3 class LinkTest < ActiveSupport::TestCase
7 set_user_from_auth :admin_trustedclient
10 test 'name links with the same tail_uuid must be unique' do
11 a = Link.create!(tail_uuid: groups(:aproject).uuid,
12 head_uuid: specimens(:owned_by_active_user).uuid,
15 assert a.valid?, a.errors.to_s
16 assert_equal groups(:aproject).uuid, a.owner_uuid
17 assert_raises ActiveRecord::RecordNotUnique do
18 b = Link.create!(tail_uuid: groups(:aproject).uuid,
19 head_uuid: specimens(:owned_by_active_user).uuid,
25 test 'name links with different tail_uuid need not be unique' do
26 a = Link.create!(tail_uuid: groups(:aproject).uuid,
27 head_uuid: specimens(:owned_by_active_user).uuid,
30 assert a.valid?, a.errors.to_s
31 assert_equal groups(:aproject).uuid, a.owner_uuid
32 b = Link.create!(tail_uuid: groups(:asubproject).uuid,
33 head_uuid: specimens(:owned_by_active_user).uuid,
36 assert b.valid?, b.errors.to_s
37 assert_equal groups(:asubproject).uuid, b.owner_uuid
38 assert_not_equal(a.uuid, b.uuid,
39 "created two links and got the same uuid back.")
42 [nil, '', false].each do |name|
43 test "name links cannot have name=#{name.inspect}" do
44 a = Link.create(tail_uuid: groups(:aproject).uuid,
45 head_uuid: specimens(:owned_by_active_user).uuid,
48 assert a.invalid?, "invalid name was accepted as valid?"
52 test "cannot delete an object referenced by links" do
54 link = Link.create(tail_uuid: users(:active).uuid,
58 assert_equal users(:admin).uuid, link.owner_uuid
59 assert_raises(ActiveRecord::DeleteRestrictionError,
60 "should not delete #{ob.uuid} with link #{link.uuid}") do
65 def new_active_link_valid?(link_attrs)
66 set_user_from_auth :active
69 create({link_class: "permission",
71 head_uuid: groups(:aproject).uuid,
74 rescue ArvadosModel::PermissionDeniedError
79 test "link granting permission to nonexistent user is invalid" do
80 refute new_active_link_valid?(tail_uuid:
81 users(:active).uuid.sub(/-\w+$/, "-#{'z' * 15}"))
84 test "link granting non-project permission to unreadable user is invalid" do
85 refute new_active_link_valid?(tail_uuid: users(:admin).uuid,
86 head_uuid: collections(:bar_file).uuid)
89 test "user can't add a Collection to a Project without permission" do
90 refute new_active_link_valid?(link_class: "name",
91 name: "Permission denied test name",
92 tail_uuid: collections(:bar_file).uuid)
95 test "user can't add a User to a Project" do
96 # Users *can* give other users permissions to projects.
97 # This test helps ensure that that exception is specific to permissions.
98 refute new_active_link_valid?(link_class: "name",
99 name: "Permission denied test name",
100 tail_uuid: users(:admin).uuid)
103 test "link granting project permissions to unreadable user is valid" do
104 assert new_active_link_valid?(tail_uuid: users(:admin).uuid)