3 class GroupTest < ActiveSupport::TestCase
5 test "cannot set owner_uuid to object with existing ownership cycle" do
6 set_user_from_auth :active_trustedclient
8 # First make sure we have lots of permission on the bad group by
9 # renaming it to "{current name} is mine all mine"
10 g = groups(:bad_group_has_ownership_cycle_b)
11 g.name += " is mine all mine"
12 assert g.save, "active user should be able to modify group #{g.uuid}"
14 # Use the group as the owner of a new object
16 create(owner_uuid: groups(:bad_group_has_ownership_cycle_b).uuid)
17 assert s.valid?, "ownership should pass validation #{s.errors.messages}"
18 assert_equal false, s.save, "should not save object with #{g.uuid} as owner"
20 # Use the group as the new owner of an existing object
21 s = specimens(:in_aproject)
22 s.owner_uuid = groups(:bad_group_has_ownership_cycle_b).uuid
23 assert s.valid?, "ownership should pass validation"
24 assert_equal false, s.save, "should not save object with #{g.uuid} as owner"
27 test "cannot create a new ownership cycle" do
28 set_user_from_auth :active_trustedclient
30 g_foo = Group.create!(name: "foo")
31 g_bar = Group.create!(name: "bar")
33 g_foo.owner_uuid = g_bar.uuid
34 assert g_foo.save, lambda { g_foo.errors.messages }
35 g_bar.owner_uuid = g_foo.uuid
36 assert g_bar.valid?, "ownership cycle should not prevent validation"
37 assert_equal false, g_bar.save, "should not create an ownership loop"
38 assert g_bar.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)
41 test "cannot create a single-object ownership cycle" do
42 set_user_from_auth :active_trustedclient
44 g_foo = Group.create!(name: "foo")
47 # Ensure I have permission to manage this group even when its owner changes
48 perm_link = Link.create!(tail_uuid: users(:active).uuid,
49 head_uuid: g_foo.uuid,
50 link_class: 'permission',
54 g_foo.owner_uuid = g_foo.uuid
55 assert_equal false, g_foo.save, "should not create an ownership loop"
56 assert g_foo.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)