Skip to content

Commit

Permalink
[ci] Add uniqueness validation for bs request actions
Browse files Browse the repository at this point in the history
Using the inbuild rspec validation test helper didn't work, because
of the association ot BsRequestType named 'type'.

=====
  1) BsRequestAction validates uniquness of type among bs requests
     Failure/Error: type_to_class_name(type_name.to_sym) || super

     ActiveRecord::SubclassNotFound:
       The single-table inheritance mechanism failed to locate the subclass: 'an arbitrary value'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite BsRequestAction.inheritance_column to use another column for that information.
     # ./app/models/bs_request_action.rb:87:in `find_sti_class'
     # ./spec/models/bs_request_action_spec.rb:7:in `block (2 levels) in <top (required)>'
     # ./spec/support/logging.rb:4:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NameError:
     #   wrong constant name an arbitrary value
     #   ./app/models/bs_request_action.rb:87:in `find_sti_class'
  • Loading branch information
bgeuken committed Apr 3, 2017
1 parent 6f91e03 commit bc8aea7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 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

0 comments on commit bc8aea7

Please sign in to comment.