mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
77 lines
1.9 KiB
Ruby
77 lines
1.9 KiB
Ruby
# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Validations::LinkUniquenessValidator do
|
|
let(:instance) { described_class.new }
|
|
|
|
shared_examples 'adds an error' do
|
|
it 'adds an error' do
|
|
instance.validate(record)
|
|
|
|
expect(record.errors.full_messages).to include('Link already exists')
|
|
end
|
|
end
|
|
|
|
shared_examples 'does not add an error' do
|
|
it 'does not add an error' do
|
|
instance.validate(record)
|
|
|
|
expect(record.errors).to be_blank
|
|
end
|
|
end
|
|
|
|
context 'when creating a new link' do
|
|
let(:record) { build(:link) }
|
|
|
|
context 'when an unrelated link exists' do
|
|
before do
|
|
create(:link, from: create(:ticket), to: create(:ticket), link_type: 'other')
|
|
end
|
|
|
|
include_examples 'does not add an error'
|
|
end
|
|
|
|
context 'when an identical link exists' do
|
|
before { create(:link) }
|
|
|
|
include_examples 'adds an error'
|
|
end
|
|
|
|
context 'when a partially identical link exists' do
|
|
before { create(:link, link_type: 'other') }
|
|
|
|
include_examples 'does not add an error'
|
|
end
|
|
end
|
|
|
|
context 'when editing an existing link' do
|
|
let(:record) { create(:link) }
|
|
|
|
context 'when an unrelated link exists' do
|
|
before do
|
|
create(:link, from: create(:ticket), to: create(:ticket), link_type: 'other')
|
|
end
|
|
|
|
include_examples 'does not add an error'
|
|
end
|
|
|
|
context 'when an identical link exists' do
|
|
before do
|
|
create(:link, link_type: 'target')
|
|
record.link_type = Link::Type.create_if_not_exists(name: 'target', active: true)
|
|
end
|
|
|
|
include_examples 'adds an error'
|
|
end
|
|
|
|
context 'when a partially identical link exists' do
|
|
before do
|
|
create(:link, link_type: 'other')
|
|
record.link_type = Link::Type.create_if_not_exists(name: 'target', active: true)
|
|
end
|
|
|
|
include_examples 'does not add an error'
|
|
end
|
|
end
|
|
end
|