5383: add one more test that updates an object twice and verifies the updated_at...
authorRadhika Chippada <radhika@curoverse.com>
Tue, 17 Mar 2015 14:51:16 +0000 (10:51 -0400)
committerRadhika Chippada <radhika@curoverse.com>
Tue, 17 Mar 2015 14:51:16 +0000 (10:51 -0400)
services/api/test/unit/arvados_model_test.rb

index 540ad0efe528fba6ff24aff4eb7de8f3d70f4ac6..b569d335639e51c46d3b6b851328eaa4cb858df8 100644 (file)
@@ -177,4 +177,24 @@ class ArvadosModelTest < ActiveSupport::TestCase
     assert_equal true, results.map(&:uuid).include?(group.uuid),
       "Expected new group uuid in results when searched with its created_at timestamp"
   end
+
+  test 'create and update twice and expect different update times' do
+    set_user_from_auth :active
+    group = Group.create! name: 'test create and retrieve group'
+    assert group.valid?, "group is not valid"
+
+    # update 1
+    group.update_attributes!(name: "test create and update name 1")
+    results = Group.where(name: "test create and update name 1")
+    assert_equal group.uuid, results.first.uuid, "Expected group uuid in results"
+    updated_at_1 = results.first.updated_at.to_f
+
+    # update 2
+    group.update_attributes!(name: "test create and update name 2")
+    results = Group.where(name: "test create and update name 2")
+    assert_equal group.uuid, results.first.uuid, "Expected group uuid in results"
+    updated_at_2 = results.first.updated_at.to_f
+
+    assert_equal true, (updated_at_2 > updated_at_1), "Expected updated time 2 to be newer than 1"
+  end
 end