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 puts s.errors.messages
18 assert s.valid?, "ownership should pass validation #{s.errors.messages}"
19 assert_equal false, s.save, "should not save object with #{g.uuid} as owner"
21 # Use the group as the new owner of an existing object
22 s = specimens(:in_aproject)
23 s.owner_uuid = groups(:bad_group_has_ownership_cycle_b).uuid
24 assert s.valid?, "ownership should pass validation"
25 assert_equal false, s.save, "should not save object with #{g.uuid} as owner"
28 test "cannot create a new ownership cycle" do
29 set_user_from_auth :active_trustedclient
31 g_foo = Group.create!(name: "foo")
32 g_bar = Group.create!(name: "bar")
34 g_foo.owner_uuid = g_bar.uuid
35 assert g_foo.save, lambda { g_foo.errors.messages }
36 g_bar.owner_uuid = g_foo.uuid
37 assert g_bar.valid?, "ownership cycle should not prevent validation"
38 assert_equal false, g_bar.save, "should not create an ownership loop"
39 assert g_bar.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)
42 test "cannot create a single-object ownership cycle" do
43 set_user_from_auth :active_trustedclient
45 g_foo = Group.create!(name: "foo")
48 # Ensure I have permission to manage this group even when its owner changes
49 perm_link = Link.create!(tail_uuid: users(:active).uuid,
50 head_uuid: g_foo.uuid,
51 link_class: 'permission',
55 g_foo.owner_uuid = g_foo.uuid
56 assert_equal false, g_foo.save, "should not create an ownership loop"
57 assert g_foo.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)