17152: Fixes old collection versions' modified_at handling and test.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 1 Dec 2020 22:17:01 +0000 (19:17 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 1 Dec 2020 22:17:01 +0000 (19:17 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/app/models/collection.rb
services/api/test/unit/collection_test.rb

index 8b549a71ab4fba348ab9279f456595912fb693db..3637f34e105b1bd66013a7cc0882860dc434034e 100644 (file)
@@ -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
index 48cae5afee92622fcda41c2b48e89761f54ac80d..666d41f0eebe2e0fd407b6014150f6ce0b28e168 100644 (file)
@@ -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.