Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rename "ActiveRecord::Fixtures" to "ActiveRecord::FixtureSet" #6282

Merged
merged 4 commits into from Oct 7, 2012
@@ -11,7 +11,7 @@ class ActiveRecordTestConnector
end
# Try to grab AR
-unless defined?(ActiveRecord) && defined?(Fixtures)
+unless defined?(ActiveRecord) && defined?(FixtureSet)
begin
PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
View
@@ -1,5 +1,17 @@
## Rails 4.0.0 (unreleased) ##
+* Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
+ Instances of this class normally hold a collection of fixtures (records)
+ loaded either from a single YAML file, or from a file and a folder
+ with the same name. This change make the class name singular and makes
+ the class easier to distinguish from the modules like
+ `ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
+ or `DelegatingFixtures`, `::Fixtures`, etc.,
+ and from the class `ActiveRecord::Fixture`, which corresponds to a single
+ fixture.
+
+ *Alexey Muranov*
+
* The postgres adapter now supports tables with capital letters.
Fix #5920
@@ -635,7 +647,7 @@
*Michael Pearson*
* Added default order to `first` to assure consistent results among
- diferent database engines. Introduced `take` as a replacement to
+ different database engines. Introduced `take` as a replacement to
the old behavior of `first`.
*Marcelo Silveira*
@@ -2,7 +2,7 @@
require 'yaml'
module ActiveRecord
- class Fixtures
+ class FixtureSet
class File # :nodoc:
include Enumerable
@@ -2,9 +2,11 @@
require 'yaml'
require 'zlib'
require 'active_support/dependencies'
-require 'active_record/fixtures/file'
+require 'active_record/fixture_set/file'
require 'active_record/errors'
+require 'active_support/deprecation' # temporary
+
module ActiveRecord
class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
end
@@ -350,8 +352,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
# to the rescue:
#
# george_reginald:
- # monkey_id: <%= ActiveRecord::Fixtures.identify(:reginald) %>
- # pirate_id: <%= ActiveRecord::Fixtures.identify(:george) %>
+ # monkey_id: <%= ActiveRecord::FixtureSet.identify(:reginald) %>
+ # pirate_id: <%= ActiveRecord::FixtureSet.identify(:george) %>
#
# == Support for YAML defaults
#
@@ -370,10 +372,11 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
# *DEFAULTS
#
# Any fixture labeled "DEFAULTS" is safely ignored.
- class Fixtures
+ class FixtureSet
#--
- # NOTE: an instance of Fixtures can be called fixture_set, it is normally stored in a single YAML file and possibly in a folder with the same name.
+ # An instance of FixtureSet is normally stored in a single YAML file and possibly in a folder with the same name.
#++
+
MAX_ID = 2 ** 30 - 1
@@all_cached_fixtures = Hash.new { |h,k| h[k] = {} }
@@ -451,7 +454,7 @@ def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}
fixtures_map = {}
fixture_sets = files_to_read.map do |fs_name|
- fixtures_map[fs_name] = new( # ActiveRecord::Fixtures.new
+ fixtures_map[fs_name] = new( # ActiveRecord::FixtureSet.new
connection,
fs_name,
class_names[fs_name] || default_fixture_model_name(fs_name),
@@ -565,7 +568,7 @@ def table_rows
# generate a primary key if necessary
if has_primary_key_column? && !row.include?(primary_key_name)
- row[primary_key_name] = ActiveRecord::Fixtures.identify(label)
+ row[primary_key_name] = ActiveRecord::FixtureSet.identify(label)
end
# If STI is used, find the correct subclass for association reflection
@@ -588,15 +591,15 @@ def table_rows
row[association.foreign_type] = $1
end
- row[fk_name] = ActiveRecord::Fixtures.identify(value)
+ row[fk_name] = ActiveRecord::FixtureSet.identify(value)
end
when :has_and_belongs_to_many
if (targets = row.delete(association.name.to_s))
targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/)
table_name = association.join_table
rows[table_name].concat targets.map { |target|
{ association.foreign_key => row[primary_key_name],
- association.association_foreign_key => ActiveRecord::Fixtures.identify(target) }
+ association.association_foreign_key => ActiveRecord::FixtureSet.identify(target) }
}
end
end
@@ -637,7 +640,7 @@ def read_fixture_files
} + [yaml_file_path]
yaml_files.each do |file|
- Fixtures::File.open(file) do |fh|
+ FixtureSet::File.open(file) do |fh|
fh.each do |fixture_name, row|
fixtures[fixture_name] = ActiveRecord::Fixture.new(row, model_class)
end
@@ -651,6 +654,11 @@ def yaml_file_path
end
+ #--
+ # Deprecate 'Fixtures' in favor of 'FixtureSet'.
+ #++
+ Fixtures = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActiveRecord::Fixtures', '::ActiveRecord::FixtureSet')
+
class Fixture #:nodoc:
include Enumerable
@@ -712,7 +720,7 @@ module TestFixtures
self.pre_loaded_fixtures = false
self.fixture_class_names = Hash.new do |h, fixture_set_name|
- h[fixture_set_name] = ActiveRecord::Fixtures.default_fixture_model_name(fixture_set_name)
+ h[fixture_set_name] = ActiveRecord::FixtureSet.default_fixture_model_name(fixture_set_name)
end
end
@@ -847,7 +855,7 @@ def setup_fixtures
end
# Load fixtures for every test.
else
- ActiveRecord::Fixtures.reset_cache
+ ActiveRecord::FixtureSet.reset_cache
@@already_loaded_fixtures[self.class] = nil
@loaded_fixtures = load_fixtures
end
@@ -860,7 +868,7 @@ def teardown_fixtures
return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
unless run_in_transaction?
- ActiveRecord::Fixtures.reset_cache
+ ActiveRecord::FixtureSet.reset_cache
end
# Rollback changes if a transaction is active.
@@ -879,7 +887,7 @@ def enlist_fixture_connections
private
def load_fixtures
- fixtures = ActiveRecord::Fixtures.create_fixtures(fixture_path, fixture_table_names, fixture_class_names)
+ fixtures = ActiveRecord::FixtureSet.create_fixtures(fixture_path, fixture_table_names, fixture_class_names)
Hash[fixtures.map { |f| [f.name, f] }]
end
@@ -888,16 +896,16 @@ def load_fixtures
def instantiate_fixtures
if pre_loaded_fixtures
- raise RuntimeError, 'Load fixtures before instantiating them.' if ActiveRecord::Fixtures.all_loaded_fixtures.empty?
+ raise RuntimeError, 'Load fixtures before instantiating them.' if ActiveRecord::FixtureSet.all_loaded_fixtures.empty?
unless @@required_fixture_classes
- self.class.require_fixture_classes ActiveRecord::Fixtures.all_loaded_fixtures.keys
+ self.class.require_fixture_classes ActiveRecord::FixtureSet.all_loaded_fixtures.keys
@@required_fixture_classes = true
end
- ActiveRecord::Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
+ ActiveRecord::FixtureSet.instantiate_all_loaded_fixtures(self, load_instances?)
else
raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
@loaded_fixtures.each_value do |fixture_set|
- ActiveRecord::Fixtures.instantiate_fixtures(self, fixture_set, load_instances?)
+ ActiveRecord::FixtureSet.instantiate_fixtures(self, fixture_set, load_instances?)
end
end
end
@@ -196,7 +196,7 @@ db_namespace = namespace :db do
fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }).each do |fixture_file|
- ActiveRecord::Fixtures.create_fixtures(fixtures_dir, fixture_file)
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_file)
end
end
@@ -207,13 +207,13 @@ db_namespace = namespace :db do
label, id = ENV['LABEL'], ENV['ID']
raise 'LABEL or ID required' if label.blank? && id.blank?
- puts %Q(The fixture ID for "#{label}" is #{ActiveRecord::Fixtures.identify(label)}.) if label
+ puts %Q(The fixture ID for "#{label}" is #{ActiveRecord::FixtureSet.identify(label)}.) if label
base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
Dir["#{base_dir}/**/*.yml"].each do |file|
if data = YAML::load(ERB.new(IO.read(file)).result)
data.keys.each do |key|
- key_id = ActiveRecord::Fixtures.identify(key)
+ key_id = ActiveRecord::FixtureSet.identify(key)
if key == label || key_id == id.to_i
puts "#{file}: #{key} (#{key_id})"
@@ -136,9 +136,9 @@ def test_associations_work_with_reserved_words
#the following functions were added to DRY test cases
private
- # custom fixture loader, uses Fixtures#create_fixtures and appends base_path to the current file's path
+ # custom fixture loader, uses FixtureSet#create_fixtures and appends base_path to the current file's path
def create_test_fixtures(*fixture_names)
- ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT + "/reserved_words", fixture_names)
+ ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/reserved_words", fixture_names)
end
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
@@ -136,9 +136,9 @@ def test_associations_work_with_reserved_words
#the following functions were added to DRY test cases
private
- # custom fixture loader, uses Fixtures#create_fixtures and appends base_path to the current file's path
+ # custom fixture loader, uses FixtureSet#create_fixtures and appends base_path to the current file's path
def create_test_fixtures(*fixture_names)
- ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT + "/reserved_words", fixture_names)
+ ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/reserved_words", fixture_names)
end
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
@@ -2,7 +2,7 @@
require 'tempfile'
module ActiveRecord
- class Fixtures
+ class FixtureSet
class FileTest < ActiveRecord::TestCase
def test_open
fh = File.open(::File.join(FIXTURES_ROOT, "accounts.yml"))
Oops, something went wrong.