diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-25 19:59:31 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-02-25 19:59:31 -0300 |
commit | 5c5d9417ca4f6dedd47565bb41b6cdcacde11099 (patch) | |
tree | de2488c754271765bddcabf643273a2f8d8289d6 /activerecord | |
parent | 026ce5ddf11c4cda0aae7f33a9266e54117db318 (diff) | |
parent | 9f48e75ad713a657b1e37cf22fa361ff98a4580a (diff) | |
download | rails-5c5d9417ca4f6dedd47565bb41b6cdcacde11099.tar.gz rails-5c5d9417ca4f6dedd47565bb41b6cdcacde11099.tar.bz2 rails-5c5d9417ca4f6dedd47565bb41b6cdcacde11099.zip |
Merge pull request #17297 from rebyn/fix/17161-remove-objs-from-has_many-updates-fields
Add specs for adding-to/clear has_many collections’s behavior on `updated_at`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 25 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
2 files changed, 26 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 eebeaad7cf..897c52a49d 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -30,6 +30,7 @@ require 'models/college' require 'models/student' require 'models/pirate' require 'models/ship' +require 'models/ship_part' require 'models/tyre' require 'models/subscriber' require 'models/subscription' @@ -162,6 +163,30 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal college.students, Student.where(active: true, college_id: college.id) end + def test_add_record_to_collection_should_change_its_updated_at + ship = Ship.create(name: 'dauntless') + part = ShipPart.create(name: 'cockpit') + updated_at = part.updated_at + + ship.parts << part + + assert_equal part.ship, ship + assert_not_equal part.updated_at, updated_at + end + + def test_clear_collection_should_not_change_updated_at + # GH#17161: .clear calls delete_all (and returns the association), + # which is intended to not touch associated objects's updated_at field + ship = Ship.create(name: 'dauntless') + part = ShipPart.create(name: 'cockpit', ship_id: ship.id) + + ship.parts.clear + part.reload + + assert_equal nil, part.ship + assert !part.updated_at_changed? + end + def test_create_from_association_should_respect_default_scope car = Car.create(:name => 'honda') assert_equal 'honda', car.name diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 08a16d5c9e..5e5f7a798e 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -680,6 +680,7 @@ ActiveRecord::Schema.define do create_table :ship_parts, force: true do |t| t.string :name t.integer :ship_id + t.datetime :updated_at end create_table :speedometers, force: true, id: false do |t| |