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