diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-11 14:33:03 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-11 14:33:03 -0800 |
commit | fb09d025429d1c1f05a705a231edb9938ccff9b0 (patch) | |
tree | 6723f8bb084fd8e6315e55fa40294eb93a0d0f1f /activerecord/lib/active_record | |
parent | 83dd6e1e620e0350c5999bd35d75251374aceaea (diff) | |
download | rails-fb09d025429d1c1f05a705a231edb9938ccff9b0.tar.gz rails-fb09d025429d1c1f05a705a231edb9938ccff9b0.tar.bz2 rails-fb09d025429d1c1f05a705a231edb9938ccff9b0.zip |
refactor fixtures to do less work in the constructor
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index c8adb809b0..59dbe8651e 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -450,6 +450,12 @@ class Fixtures @@all_cached_fixtures = {} + def self.find_table_name(table_name) # :nodoc: + ActiveRecord::Base.pluralize_table_names ? + table_name.to_s.singularize.camelize : + table_name.to_s.camelize + end + def self.reset_cache(connection = nil) connection ||= ActiveRecord::Base.connection @@all_cached_fixtures[connection.object_id] = {} @@ -547,14 +553,16 @@ class Fixtures attr_reader :table_name, :name, :fixtures def initialize(connection, table_name, class_name, fixture_path, file_filter = DEFAULT_FILTER_RE) - @fixtures = ActiveSupport::OrderedHash.new - @connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter - @name = table_name # preserve fixture base name - @class_name = class_name || - (ActiveRecord::Base.pluralize_table_names ? @table_name.singularize.camelize : @table_name.camelize) - @table_name = "#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}" - @table_name = class_name.table_name if class_name.respond_to?(:table_name) - @connection = class_name.connection if class_name.respond_to?(:connection) + @fixtures = ActiveSupport::OrderedHash.new + @connection = connection + @table_name = table_name + @fixture_path = fixture_path + @file_filter = file_filter + @name = table_name # preserve fixture base name + @class_name = class_name + @table_name = "#{ActiveRecord::Base.table_name_prefix}#{@table_name}#{ActiveRecord::Base.table_name_suffix}" + @table_name = class_name.table_name if class_name.respond_to?(:table_name) + @connection = class_name.connection if class_name.respond_to?(:connection) read_fixture_files end @@ -587,7 +595,10 @@ class Fixtures # track any join tables we need to insert later habtm_fixtures = Hash.new do |h, habtm| - h[habtm] = HabtmFixtures.new(@connection, habtm.options[:join_table], nil, nil) + h[habtm] = HabtmFixtures.new( + @connection, + habtm.options[:join_table], + Fixtures.find_table_name(habtm.options[:join_table]), nil) end fixtures.each do |label, fixture| @@ -843,7 +854,9 @@ module ActiveRecord self.use_instantiated_fixtures = false self.pre_loaded_fixtures = false - self.fixture_class_names = {} + self.fixture_class_names = Hash.new do |h, table_name| + h[table_name] = Fixtures.find_table_name(table_name) + end end module ClassMethods |