Permalink
Browse files

create_fixtures should accept symbol keys for custom table -> class m…

…appings. Fixes an unintended regression.
  • Loading branch information...
1 parent 4b81007 commit 78372b6cbb655227f4e6ddcb32187704659de84f @jeremy jeremy committed Jan 4, 2012
Showing with 14 additions and 4 deletions.
  1. +4 −2 activerecord/lib/active_record/fixtures.rb
  2. +10 −2 activerecord/test/cases/fixtures_test.rb
@@ -445,7 +445,8 @@ def self.instantiate_all_loaded_fixtures(object, load_instances = true)
self.all_loaded_fixtures = {}
def self.create_fixtures(fixtures_directory, table_names, class_names = {})
- table_names = [table_names].flatten.map { |n| n.to_s }
+ table_names = Array(table_names).map(&:to_s)
+ class_names = class_names.stringify_keys
# FIXME: Apparently JK uses this.
connection = block_given? ? yield : ActiveRecord::Base.connection
@@ -464,7 +465,7 @@ def self.create_fixtures(fixtures_directory, table_names, class_names = {})
fixtures_map[fixture_name] = new( # ActiveRecord::Fixtures.new
connection,
fixture_name,
- class_names[fixture_name] || default_fixture_model_name(fixture_name),
+ class_names[fixture_name.to_s] || default_fixture_model_name(fixture_name),
::File.join(fixtures_directory, path))
end
@@ -728,6 +729,7 @@ module TestFixtures
self.pre_loaded_fixtures = false
self.fixture_class_names = Hash.new do |h, fixture_name|
+ fixture_name = fixture_name.to_s
h[fixture_name] = ActiveRecord::Fixtures.default_fixture_model_name(fixture_name)
end
end
@@ -65,8 +65,9 @@ def test_broken_yaml_exception
end
def test_create_fixtures
- ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT, "parrots")
- assert Parrot.find_by_name('Curious George'), 'George is in the database'
+ fixtures = ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT, "parrots")
+ assert Parrot.find_by_name('Curious George'), 'George is not in the database'
+ assert fixtures.detect { |f| f.name == 'parrots' }, "no fixtures named 'parrots' in #{fixtures.map(&:name).inspect}"
end
def test_multiple_clean_fixtures
@@ -76,6 +77,13 @@ def test_multiple_clean_fixtures
fixtures_array.each { |fixtures| assert_kind_of(ActiveRecord::Fixtures, fixtures) }
end
+ def test_create_symbol_fixtures
+ fixtures = ActiveRecord::Fixtures.create_fixtures(FIXTURES_ROOT, :collections, :collections => Course) { Course.connection }
+
+ assert Course.find_by_name('Collection'), 'course is not in the database'
+ assert fixtures.detect { |f| f.name == 'collections' }, "no fixtures named 'collections' in #{fixtures.map(&:name).inspect}"
+ end
+
def test_attributes
topics = create_fixtures("topics").first
assert_equal("The First Topic", topics["first"]["title"])

0 comments on commit 78372b6

Please sign in to comment.