aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-03-30 03:25:30 -0700
committerJon Leighton <j@jonathanleighton.com>2012-03-30 03:25:30 -0700
commit3a8c54396ea3965eb7601501d7bb9618ff305728 (patch)
tree18044d98cd07e0619efa4d416bc6b9dd74a347e0 /activerecord/test
parent7dd7d76b86b2168b39fb7f0c359d84ea6df0ce41 (diff)
parent135d704a55b87b1c5371f4a552151f44964a8fed (diff)
downloadrails-3a8c54396ea3965eb7601501d7bb9618ff305728.tar.gz
rails-3a8c54396ea3965eb7601501d7bb9618ff305728.tar.bz2
rails-3a8c54396ea3965eb7601501d7bb9618ff305728.zip
Merge pull request #2945 from Casecommons/nested_attributes_module
Nested attribute setters can be overridden.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb13
-rw-r--r--activerecord/test/schema/schema.rb1
2 files changed, 14 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
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 5e7985c530..d5e4f165cb 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -439,6 +439,7 @@ ActiveRecord::Schema.define do
create_table :parrots, :force => true do |t|
t.column :name, :string
+ t.column :color, :string
t.column :parrot_sti_class, :string
t.column :killer_id, :integer
t.column :created_at, :datetime