X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/df9e166a5ffc4aa79658bec1a5d552a3b413f0d8..fc5742654641a10e765ed81d25ca44cb47976d02:/services/api/test/unit/owner_test.rb diff --git a/services/api/test/unit/owner_test.rb b/services/api/test/unit/owner_test.rb index c7f9776ac6..ca02e2db5e 100644 --- a/services/api/test/unit/owner_test.rb +++ b/services/api/test/unit/owner_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' # Test referential integrity: ensure we cannot leave any object @@ -27,7 +31,7 @@ class OwnerTest < ActiveSupport::TestCase test "create object with non-existent #{o_class} owner" do assert_raises(ActiveRecord::RecordInvalid, "create should fail with random owner_uuid") do - i = Specimen.create!(owner_uuid: o_class.generate_uuid) + Specimen.create!(owner_uuid: o_class.generate_uuid) end i = Specimen.create(owner_uuid: o_class.generate_uuid) @@ -66,8 +70,12 @@ class OwnerTest < ActiveSupport::TestCase "new #{o_class} should really be in DB") old_uuid = o.uuid new_uuid = o.uuid.sub(/..........$/, rand(2**256).to_s(36)[0..9]) - assert(o.update_attributes(uuid: new_uuid), - "should change #{o_class} uuid from #{old_uuid} to #{new_uuid}") + if o.respond_to? :update_uuid + o.update_uuid(new_uuid: new_uuid) + else + assert(o.update_attributes(uuid: new_uuid), + "should change #{o_class} uuid from #{old_uuid} to #{new_uuid}") + end assert_equal(false, o_class.where(uuid: old_uuid).any?, "#{old_uuid} should disappear when renamed to #{new_uuid}") end @@ -79,9 +87,11 @@ class OwnerTest < ActiveSupport::TestCase assert_equal(true, Specimen.where(owner_uuid: o.uuid).any?, "need something to be owned by #{o.uuid} for this test") - assert_raises(ActiveRecord::DeleteRestrictionError, - "should not delete #{ofixt} that owns objects") do - o.destroy + skip_check_permissions_against_full_refresh do + assert_raises(ActiveRecord::DeleteRestrictionError, + "should not delete #{ofixt} that owns objects") do + o.destroy + end end end @@ -89,7 +99,6 @@ class OwnerTest < ActiveSupport::TestCase o = eval ofixt assert_equal(true, Specimen.where(owner_uuid: o.uuid).any?, "need something to be owned by #{o.uuid} for this test") - old_uuid = o.uuid new_uuid = o.uuid.sub(/..........$/, rand(2**256).to_s(36)[0..9]) assert(!o.update_attributes(uuid: new_uuid), "should not change uuid of #{ofixt} that owns objects") @@ -101,9 +110,14 @@ class OwnerTest < ActiveSupport::TestCase assert User.where(uuid: o.uuid).any?, "new User should really be in DB" assert_equal(true, o.update_attributes(owner_uuid: o.uuid), "setting owner to self should work") - assert(o.destroy, "should delete User that owns self") + + skip_check_permissions_against_full_refresh do + assert(o.destroy, "should delete User that owns self") + end + assert_equal(false, User.where(uuid: o.uuid).any?, "#{o.uuid} should not be in DB after deleting") + check_permissions_against_full_refresh end test "change uuid of User that owns self" do @@ -113,8 +127,8 @@ class OwnerTest < ActiveSupport::TestCase "setting owner to self should work") old_uuid = o.uuid new_uuid = o.uuid.sub(/..........$/, rand(2**256).to_s(36)[0..9]) - assert(o.update_attributes(uuid: new_uuid), - "should change uuid of User that owns self") + o.update_uuid(new_uuid: new_uuid) + o = User.find_by_uuid(new_uuid) assert_equal(false, User.where(uuid: old_uuid).any?, "#{old_uuid} should not be in DB after deleting") assert_equal(true, User.where(uuid: new_uuid).any?,