From b3fad38bb4fd356e5ce924e792be7f4113d1c746 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 1 Dec 2020 19:17:01 -0300 Subject: [PATCH 1/1] 17152: Fixes old collection versions' modified_at handling and test. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- services/api/app/models/collection.rb | 7 +++++-- services/api/test/unit/collection_test.rb | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index 8b549a71ab..3637f34e10 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -269,6 +269,7 @@ class Collection < ArvadosModel snapshot = self.dup snapshot.uuid = nil # Reset UUID so it's created as a new record snapshot.created_at = self.created_at + snapshot.modified_at = self.modified_at_was end # Restore requested changes on the current version @@ -294,8 +295,10 @@ class Collection < ArvadosModel if snapshot snapshot.attributes = self.syncable_updates leave_modified_by_user_alone do - act_as_system_user do - snapshot.save + leave_modified_at_alone do + act_as_system_user do + snapshot.save + end end end end diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index 48cae5afee..666d41f0ee 100644 --- a/services/api/test/unit/collection_test.rb +++ b/services/api/test/unit/collection_test.rb @@ -334,6 +334,7 @@ class CollectionTest < ActiveSupport::TestCase # Set up initial collection c = create_collection 'foo', Encoding::US_ASCII assert c.valid? + original_version_modified_at = c.modified_at.to_f # Make changes so that a new version is created c.update_attributes!({'name' => 'bar'}) c.reload @@ -344,9 +345,7 @@ class CollectionTest < ActiveSupport::TestCase version_creation_datetime = c_old.modified_at.to_f assert_equal c.created_at.to_f, c_old.created_at.to_f - # Current version is updated just a few milliseconds before the version is - # saved on the database. - assert_operator c.modified_at.to_f, :<, version_creation_datetime + assert_equal original_version_modified_at, version_creation_datetime # Make update on current version so old version get the attribute synced; # its modified_at should not change. -- 2.30.2