diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-22 18:44:14 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-02-22 18:44:14 +0000 |
commit | c7d6d68f91f2cd2e04c2113cba44bef86dbad99f (patch) | |
tree | f9c4a03d7254d648718e671c4619f8637235b428 /activerecord/test | |
parent | de54db3c1e2056322450e46c265b27792e99b2c7 (diff) | |
download | rails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.tar.gz rails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.tar.bz2 rails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.zip |
Reflections don't attempt to resolve module nesting of association classes. Simplify type computation.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/fixtures/company_in_module.rb | 20 | ||||
-rw-r--r-- | activerecord/test/modules_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/reflection_test.rb | 45 |
3 files changed, 66 insertions, 6 deletions
diff --git a/activerecord/test/fixtures/company_in_module.rb b/activerecord/test/fixtures/company_in_module.rb index 52b5d37b8c..df476520b8 100644 --- a/activerecord/test/fixtures/company_in_module.rb +++ b/activerecord/test/fixtures/company_in_module.rb @@ -33,11 +33,25 @@ module MyApplication end end - + module Billing + class Firm < ActiveRecord::Base + self.table_name = 'companies' + end + + module Nested + class Firm < ActiveRecord::Base + self.table_name = 'companies' + end + end + class Account < ActiveRecord::Base - belongs_to :firm, :class_name => "MyApplication::Business::Firm" - + belongs_to :firm, :class_name => 'MyApplication::Business::Firm' + belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm' + belongs_to :unqualified_billing_firm, :class_name => 'Firm' + belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm' + belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm' + protected def validate errors.add_on_empty "credit_limit" diff --git a/activerecord/test/modules_test.rb b/activerecord/test/modules_test.rb index d34afbb8f8..5c3cc1906e 100644 --- a/activerecord/test/modules_test.rb +++ b/activerecord/test/modules_test.rb @@ -18,6 +18,11 @@ class ModulesTest < Test::Unit::TestCase end def test_associations_spanning_cross_modules - assert MyApplication::Billing::Account.find(1).has_firm?, "37signals account should be able to backtrack" + account = MyApplication::Billing::Account.find(:first) + assert_kind_of MyApplication::Business::Firm, account.firm + assert_kind_of MyApplication::Billing::Firm, account.qualified_billing_firm + assert_kind_of MyApplication::Billing::Firm, account.unqualified_billing_firm + assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_qualified_billing_firm + assert_kind_of MyApplication::Billing::Nested::Firm, account.nested_unqualified_billing_firm end end diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index 30cc99677e..6e5d7126f5 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -90,8 +90,41 @@ class ReflectionTest < Test::Unit::TestCase end def test_association_reflection_in_modules - assert_equal MyApplication::Business::Client, MyApplication::Business::Firm.reflect_on_association(:clients_of_firm).klass - assert_equal MyApplication::Business::Firm, MyApplication::Billing::Account.reflect_on_association(:firm).klass + assert_reflection MyApplication::Business::Firm, + :clients_of_firm, + :klass => MyApplication::Business::Client, + :class_name => 'Client', + :table_name => 'companies' + + assert_reflection MyApplication::Billing::Account, + :firm, + :klass => MyApplication::Business::Firm, + :class_name => 'MyApplication::Business::Firm', + :table_name => 'companies' + + assert_reflection MyApplication::Billing::Account, + :qualified_billing_firm, + :klass => MyApplication::Billing::Firm, + :class_name => 'MyApplication::Billing::Firm', + :table_name => 'companies' + + assert_reflection MyApplication::Billing::Account, + :unqualified_billing_firm, + :klass => MyApplication::Billing::Firm, + :class_name => 'Firm', + :table_name => 'companies' + + assert_reflection MyApplication::Billing::Account, + :nested_qualified_billing_firm, + :klass => MyApplication::Billing::Nested::Firm, + :class_name => 'MyApplication::Billing::Nested::Firm', + :table_name => 'companies' + + assert_reflection MyApplication::Billing::Account, + :nested_unqualified_billing_firm, + :klass => MyApplication::Billing::Nested::Firm, + :class_name => 'Nested::Firm', + :table_name => 'companies' end def test_reflection_of_all_associations @@ -100,4 +133,12 @@ class ReflectionTest < Test::Unit::TestCase assert_equal 1, Firm.reflect_on_all_associations(:has_one).size assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size end + + private + def assert_reflection(klass, association, options) + assert reflection = klass.reflect_on_association(association) + options.each do |method, value| + assert_equal(value, reflection.send(method)) + end + end end |