diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-14 19:40:24 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-14 19:49:22 +0100 |
commit | 60b23ea1da1c119eaab6d07e5a03cf3b5d5577d4 (patch) | |
tree | 3e352279ac70704e426726e848b1687cd0007fdc /activerecord/test | |
parent | 6660beef367a888ac633cc03d1d7157737e6b2cb (diff) | |
download | rails-60b23ea1da1c119eaab6d07e5a03cf3b5d5577d4.tar.gz rails-60b23ea1da1c119eaab6d07e5a03cf3b5d5577d4.tar.bz2 rails-60b23ea1da1c119eaab6d07e5a03cf3b5d5577d4.zip |
CollectionAssociation#merge_target_lists should write to the underlying attributes when copying, rather than using the assignment method
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/models/bulb.rb | 4 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index b149f5912f..0e33fa9c8e 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1445,4 +1445,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_not_equal target.object_id, ary.object_id end + + def test_merging_with_custom_attribute_writer + bulb = Bulb.new(:color => "red") + assert_equal "RED!", bulb.color + + car = Car.create! + car.bulbs << bulb + + assert_equal "RED!", car.bulbs.to_a.first.color + end end diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb index 643dcefed3..7d90963720 100644 --- a/activerecord/test/models/bulb.rb +++ b/activerecord/test/models/bulb.rb @@ -11,4 +11,8 @@ class Bulb < ActiveRecord::Base @scope_after_initialize = self.class.scoped end + def color=(color) + self[:color] = color.upcase + "!" + end + end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index c8a98f121d..d56cdd57b2 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -90,6 +90,7 @@ ActiveRecord::Schema.define do t.integer :car_id t.string :name t.boolean :frickinawesome + t.string :color end create_table "CamelCase", :force => true do |t| |