diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-07-16 20:21:36 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-07-16 20:21:36 +0000 |
commit | 4ef5af8d4ddad82295920cc7d83fba6cbb10ad71 (patch) | |
tree | 62a78541994ec67ea0065622ed05509e62538e68 /activerecord/test | |
parent | ddb00f10781e808360a189b46a421f1d18a0360b (diff) | |
download | rails-4ef5af8d4ddad82295920cc7d83fba6cbb10ad71.tar.gz rails-4ef5af8d4ddad82295920cc7d83fba6cbb10ad71.tar.bz2 rails-4ef5af8d4ddad82295920cc7d83fba6cbb10ad71.zip |
Change belongs_to so that the foreign_key assumption is taken from the association name, not the class name. Closes #8992 [hasmanyjosh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7188 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/reflection_test.rb | 9 |
2 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index bf6d8301a2..0db8d91099 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -409,13 +409,6 @@ class HasOneAssociationsTest < Test::Unit::TestCase end end - def test_deprecated_inferred_foreign_key - assert_not_deprecated { Company.belongs_to :firm } - assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" } - assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" } - assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" } - end - end diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index cc06d31299..1ed5c2610c 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -111,6 +111,15 @@ class ReflectionTest < Test::Unit::TestCase assert_equal 'accounts', Firm.reflect_on_association(:account).table_name end + def test_belongs_to_inferred_foreign_key_from_assoc_name + Company.belongs_to :foo + assert_equal "foo_id", Company.reflect_on_association(:foo).primary_key_name + Company.belongs_to :bar, :class_name => "Xyzzy" + assert_equal "bar_id", Company.reflect_on_association(:bar).primary_key_name + Company.belongs_to :baz, :class_name => "Xyzzy", :foreign_key => "xyzzy_id" + assert_equal "xyzzy_id", Company.reflect_on_association(:baz).primary_key_name + end + def test_association_reflection_in_modules assert_reflection MyApplication::Business::Firm, :clients_of_firm, |