X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2d4263c16812a906589cbc13be26535a85691bd8..5845d196105cc4676847695833b7ef3658c8a180:/services/api/test/unit/link_test.rb diff --git a/services/api/test/unit/link_test.rb b/services/api/test/unit/link_test.rb index 944bfced3d..72d6017ce7 100644 --- a/services/api/test/unit/link_test.rb +++ b/services/api/test/unit/link_test.rb @@ -1,7 +1,48 @@ require 'test_helper' class LinkTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + fixtures :all + + setup do + Thread.current[:user] = users(:active) + end + + test 'name links with the same tail_uuid must be unique' do + a = Link.create!(tail_uuid: groups(:afolder).uuid, + head_uuid: specimens(:owned_by_active_user).uuid, + link_class: 'name', + name: 'foo') + assert a.valid?, a.errors.to_s + assert_raises ActiveRecord::RecordNotUnique do + b = Link.create!(tail_uuid: groups(:afolder).uuid, + head_uuid: specimens(:owned_by_active_user).uuid, + link_class: 'name', + name: 'foo') + end + end + + test 'name links with different tail_uuid need not be unique' do + a = Link.create!(tail_uuid: groups(:afolder).uuid, + head_uuid: specimens(:owned_by_active_user).uuid, + link_class: 'name', + name: 'foo') + assert a.valid?, a.errors.to_s + b = Link.create!(tail_uuid: groups(:asubfolder).uuid, + head_uuid: specimens(:owned_by_active_user).uuid, + link_class: 'name', + name: 'foo') + assert b.valid?, b.errors.to_s + assert_not_equal(a.uuid, b.uuid, + "created two links and got the same uuid back.") + end + + [nil, '', false].each do |name| + test "name links cannot have name=#{name.inspect}" do + a = Link.create(tail_uuid: groups(:afolder).uuid, + head_uuid: specimens(:owned_by_active_user).uuid, + link_class: 'name', + name: name) + assert a.invalid?, "invalid name was accepted as valid?" + end + end end