aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorJonathan Mukai & Peter Jaros <pair+jmukai+pjaros@pivotallabs.com>2011-09-08 15:39:44 -0400
committerPeter Jaros <peter.a.jaros@gmail.com>2012-03-28 19:08:31 -0400
commit135d704a55b87b1c5371f4a552151f44964a8fed (patch)
treef4072b79a71cec71b5c9835fd1722b3057578b2b /activerecord/test/cases/nested_attributes_test.rb
parentddaeb4b6cf6c1a1779c6e46ff49e8c5f5e0b7418 (diff)
downloadrails-135d704a55b87b1c5371f4a552151f44964a8fed.tar.gz
rails-135d704a55b87b1c5371f4a552151f44964a8fed.tar.bz2
rails-135d704a55b87b1c5371f4a552151f44964a8fed.zip
Nested attribute setters can be overridden.
Overriding implementation can call super.
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 09276a034e..0559bbbe9a 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -172,6 +172,19 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase
man.interests_attributes = [{:id => interest.id, :topic => 'gardening'}]
assert_equal man.interests.first.topic, man.interests[0].topic
end
+
+ def test_allows_class_to_override_setter_and_call_super
+ mean_pirate_class = Class.new(Pirate) do
+ accepts_nested_attributes_for :parrot
+ def parrot_attributes=(attrs)
+ super(attrs.merge(:color => "blue"))
+ end
+ end
+ mean_pirate = mean_pirate_class.new
+ mean_pirate.parrot_attributes = { :name => "James" }
+ assert_equal "James", mean_pirate.parrot.name
+ assert_equal "blue", mean_pirate.parrot.color
+ end
end
class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase