diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 10:02:19 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-30 10:02:19 -0800 |
commit | 116b9edf95ccaa59feb6afe67b126ad3da526b92 (patch) | |
tree | 8c9bcdadd3e2a6315e165bf2a1582afa5898236c /activerecord/test | |
parent | 4b99732552f997c846b186f9e2d3439ff75baff0 (diff) | |
parent | b52d9d0ff585f3131e26317542df2971a667d319 (diff) | |
download | rails-116b9edf95ccaa59feb6afe67b126ad3da526b92.tar.gz rails-116b9edf95ccaa59feb6afe67b126ad3da526b92.tar.bz2 rails-116b9edf95ccaa59feb6afe67b126ad3da526b92.zip |
Merge pull request #4224 from alexeymuranov/my-fix-for-fixture-tables
Fix #2572 and define fixture table name in the associated model
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 33 | ||||
-rw-r--r-- | activerecord/test/fixtures/admin/randomly_named_a9.yml | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/admin/randomly_named_b0.yml | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/randomly_named_a9.yml | 7 | ||||
-rw-r--r-- | activerecord/test/models/admin/randomly_named_c1.rb | 3 | ||||
-rw-r--r-- | activerecord/test/models/randomly_named_c1.rb | 3 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 5 |
7 files changed, 65 insertions, 0 deletions
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index ba09df4b7d..859bb7992b 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -1,6 +1,7 @@ require 'cases/helper' require 'models/admin' require 'models/admin/account' +require 'models/admin/randomly_named_c1' require 'models/admin/user' require 'models/binary' require 'models/book' @@ -14,6 +15,7 @@ require 'models/matey' require 'models/parrot' require 'models/pirate' require 'models/post' +require 'models/randomly_named_c1' require 'models/reply' require 'models/ship' require 'models/task' @@ -745,3 +747,34 @@ class FixtureLoadingTest < ActiveRecord::TestCase ActiveRecord::TestCase.try_to_load_dependency(:works_out_fine) end end + +class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase + ActiveRecord::Fixtures.reset_cache + + set_fixture_class :randomly_named_a9 => + ClassNameThatDoesNotFollowCONVENTIONS, + :'admin/randomly_named_a9' => + Admin::ClassNameThatDoesNotFollowCONVENTIONS, + 'admin/randomly_named_b0' => + Admin::ClassNameThatDoesNotFollowCONVENTIONS + + fixtures :randomly_named_a9, 'admin/randomly_named_a9', + :'admin/randomly_named_b0' + + def test_named_accessor_for_randomly_named_fixture_and_class + assert_kind_of ClassNameThatDoesNotFollowCONVENTIONS, + randomly_named_a9(:first_instance) + end + + def test_named_accessor_for_randomly_named_namespaced_fixture_and_class + assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS, + admin_randomly_named_a9(:first_instance) + assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS, + admin_randomly_named_b0(:second_instance) + end + + def test_table_name_is_defined_in_the_model + assert_equal :randomly_named_table, ActiveRecord::Fixtures::all_loaded_fixtures["admin/randomly_named_a9"].table_name + assert_equal :randomly_named_table, Admin::ClassNameThatDoesNotFollowCONVENTIONS.table_name + end +end diff --git a/activerecord/test/fixtures/admin/randomly_named_a9.yml b/activerecord/test/fixtures/admin/randomly_named_a9.yml new file mode 100644 index 0000000000..bc51c83112 --- /dev/null +++ b/activerecord/test/fixtures/admin/randomly_named_a9.yml @@ -0,0 +1,7 @@ +first_instance:
+ some_attribute: AAA
+ another_attribute: 000
+
+second_instance:
+ some_attribute: BBB
+ another_attribute: 999
diff --git a/activerecord/test/fixtures/admin/randomly_named_b0.yml b/activerecord/test/fixtures/admin/randomly_named_b0.yml new file mode 100644 index 0000000000..bc51c83112 --- /dev/null +++ b/activerecord/test/fixtures/admin/randomly_named_b0.yml @@ -0,0 +1,7 @@ +first_instance:
+ some_attribute: AAA
+ another_attribute: 000
+
+second_instance:
+ some_attribute: BBB
+ another_attribute: 999
diff --git a/activerecord/test/fixtures/randomly_named_a9.yml b/activerecord/test/fixtures/randomly_named_a9.yml new file mode 100644 index 0000000000..bc51c83112 --- /dev/null +++ b/activerecord/test/fixtures/randomly_named_a9.yml @@ -0,0 +1,7 @@ +first_instance:
+ some_attribute: AAA
+ another_attribute: 000
+
+second_instance:
+ some_attribute: BBB
+ another_attribute: 999
diff --git a/activerecord/test/models/admin/randomly_named_c1.rb b/activerecord/test/models/admin/randomly_named_c1.rb new file mode 100644 index 0000000000..2f81d5b831 --- /dev/null +++ b/activerecord/test/models/admin/randomly_named_c1.rb @@ -0,0 +1,3 @@ +class Admin::ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
+ self.table_name = :randomly_named_table
+end
diff --git a/activerecord/test/models/randomly_named_c1.rb b/activerecord/test/models/randomly_named_c1.rb new file mode 100644 index 0000000000..18a86c4989 --- /dev/null +++ b/activerecord/test/models/randomly_named_c1.rb @@ -0,0 +1,3 @@ +class ClassNameThatDoesNotFollowCONVENTIONS < ActiveRecord::Base
+ self.table_name = :randomly_named_table
+end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index b06175cd3f..b8f34bb739 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -505,6 +505,11 @@ ActiveRecord::Schema.define do t.string :type end + create_table :randomly_named_table, :force => true do |t| + t.string :some_attribute + t.integer :another_attribute + end + create_table :ratings, :force => true do |t| t.integer :comment_id t.integer :value |