diff --git a/src/api/spec/models/bs_request_action_spec.rb b/src/api/spec/models/bs_request_action_spec.rb index e599cbc22ca..eb492d3f1b0 100644 --- a/src/api/spec/models/bs_request_action_spec.rb +++ b/src/api/spec/models/bs_request_action_spec.rb @@ -1,5 +1,37 @@ require 'rails_helper' RSpec.describe BsRequestAction do + context 'uniqueness validation of type' do + let(:bs_request) { create(:bs_request) } + let(:action_attributes) { + { + bs_request: bs_request, + type: 'submit', + target_project: 'target_prj', + target_package: 'target_pkg' + } + } + let!(:bs_request_action) { create(:bs_request_action, action_attributes) } + + it { expect(bs_request_action).to be_valid } + + it 'validates uniqueness of type among bs requests, target_project and target_package' do + duplicated_bs_request_action = build(:bs_request_action, action_attributes) + expect(duplicated_bs_request_action).not_to be_valid + expect(duplicated_bs_request_action.errors.full_messages.to_sentence).to eq('Type has already been taken') + end + + RSpec.shared_examples 'it skips validation for type' do |type| + context "type '#{type}'" do + it 'allows multiple bs request actions' do + expect(build(:bs_request_action, action_attributes.merge(type: 'add_role'))).to be_valid + end + end + end + + it_should_behave_like 'it skips validation for type', 'add_role' + it_should_behave_like 'it skips validation for type', 'maintenance_incident' + end + it { should belong_to(:bs_request).touch(true) } end