aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations_test.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2011-11-14 22:57:15 -0800
committerJosh Susser <josh@hasmanythrough.com>2011-11-15 23:32:58 -0800
commit7cba6a37848ba96b4decec885779fb309d71c339 (patch)
treedd1c38690fd0551dd248dfe6005f7532a35e49b1 /activerecord/test/cases/associations_test.rb
parent8d1a2b3ecde5a8745b3eaab4763a71d80ca3441f (diff)
downloadrails-7cba6a37848ba96b4decec885779fb309d71c339.tar.gz
rails-7cba6a37848ba96b4decec885779fb309d71c339.tar.bz2
rails-7cba6a37848ba96b4decec885779fb309d71c339.zip
association methods are now generated in modules
Instead of generating association methods directly in the model class, they are generated in an anonymous module which is then included in the model class. There is one such module for each association. The only subtlety is that the generated_attributes_methods module (from ActiveModel) must be forced to be included before association methods are created so that attribute methods will not shadow association methods.
Diffstat (limited to 'activerecord/test/cases/associations_test.rb')
-rw-r--r--activerecord/test/cases/associations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index ffe2993e0f..a9094b7a8b 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -1,4 +1,5 @@
require "cases/helper"
+require 'models/computer'
require 'models/developer'
require 'models/project'
require 'models/company'
@@ -273,3 +274,14 @@ class OverridingAssociationsTest < ActiveRecord::TestCase
)
end
end
+
+class GeneratedMethodsTest < ActiveRecord::TestCase
+ fixtures :developers, :computers
+ def test_association_methods_override_attribute_methods_of_same_name
+ assert_equal(developers(:david), computers(:workstation).developer)
+ # this next line will fail if the attribute methods module is generated lazily
+ # after the association methods module is generated
+ assert_equal(developers(:david), computers(:workstation).developer)
+ assert_equal(developers(:david).id, computers(:workstation)[:developer])
+ end
+end \ No newline at end of file