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(:afolder).uuid,
12 head_uuid: specimens(:owned_by_active_user).uuid,
15 assert a.valid?, a.errors.to_s
16 assert_raises ActiveRecord::RecordNotUnique do
17 b = Link.create!(tail_uuid: groups(:afolder).uuid,
18 head_uuid: specimens(:owned_by_active_user).uuid,
24 test 'name links with different tail_uuid need not be unique' do
25 a = Link.create!(tail_uuid: groups(:afolder).uuid,
26 head_uuid: specimens(:owned_by_active_user).uuid,
29 assert a.valid?, a.errors.to_s
30 b = Link.create!(tail_uuid: groups(:asubfolder).uuid,
31 head_uuid: specimens(:owned_by_active_user).uuid,
34 assert b.valid?, b.errors.to_s
35 assert_not_equal(a.uuid, b.uuid,
36 "created two links and got the same uuid back.")
39 [nil, '', false].each do |name|
40 test "name links cannot be renamed to name=#{name.inspect}" do
41 a = Link.create!(tail_uuid: groups(:afolder).uuid,
42 head_uuid: specimens(:owned_by_active_user).uuid,
46 assert a.invalid?, "invalid name was accepted as valid?"
49 test "name links cannot be created with name=#{name.inspect}" do
50 a = Link.create(tail_uuid: groups(:afolder).uuid,
51 head_uuid: specimens(:owned_by_active_user).uuid,
54 if a.name and !a.name.empty?
55 assert a.valid?, "name automatically assigned, but record not valid?"
57 assert a.invalid?, "invalid name was accepted as valid?"
62 test "cannot delete an object referenced by links" do
64 link = Link.create(tail_uuid: users(:active).uuid,
68 assert_raises(ActiveRecord::DeleteRestrictionError,
69 "should not delete #{ob.uuid} with link #{link.uuid}") do
74 test "assign sequential generic name links" do
75 group = Group.create!(group_class: 'folder')
78 link = Link.create!(link_class: 'name',
79 tail_uuid: group.uuid, head_uuid: ob.uuid)
80 expect_name = 'New specimen' + (n==0 ? "" : " (#{n})")
81 assert_equal expect_name, link.name, "Expected sequential generic names"
85 test "assign sequential generic name links for a two-word model" do
86 group = Group.create!(group_class: 'folder')
87 ob = VirtualMachine.create!
89 link = Link.create!(link_class: 'name',
90 tail_uuid: group.uuid, head_uuid: ob.uuid)
91 expect_name = 'New virtual machine' + (n==0 ? "" : " (#{n})")
92 assert_equal expect_name, link.name, "Expected sequential generic names"
96 test "cannot assign sequential generic name links for a bogus uuid type" do
97 group = Group.create!(group_class: 'folder')
98 link = Link.create(link_class: 'name',
99 tail_uuid: group.uuid,
100 head_uuid: 'zzzzz-abcde-123451234512345')
101 assert link.invalid?, "gave a bogus uuid, got automatic name #{link.name}"