instance method read_fixture_files

Ruby on Rails 7.1.6

Since v4.0.13 Private

Available in: v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

read_fixture_files(path)

Loads the fixtures from the YAML file at path. If the file sets the model_class and current instance value is not set, it uses the file value.

Parameters

path req
Source
# File activerecord/lib/active_record/fixtures.rb, line 777
      def read_fixture_files(path)
        yaml_files = Dir["#{path}{.yml,/{**,*}/*.yml}"].select { |f|
          ::File.file?(f)
        }

        raise ArgumentError, "No fixture files found for #{@name}" if yaml_files.empty?

        yaml_files.each_with_object({}) do |file, fixtures|
          FixtureSet::File.open(file) do |fh|
            self.model_class ||= fh.model_class if fh.model_class
            self.model_class ||= default_fixture_model_class
            self.ignored_fixtures ||= fh.ignored_fixtures
            fh.each do |fixture_name, row|
              fixtures[fixture_name] = ActiveRecord::Fixture.new(row, model_class)
            end
          end
        end
      end

Defined in activerecord/lib/active_record/fixtures.rb line 777 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::FixtureSet

Type at least 2 characters to search.

↑↓ navigate · open · esc close