Commit 1d67b449 authored by Philip Cunningham's avatar Philip Cunningham Committed by Alex Kalderimis

Extract shared example for Dast::Profile spec

parent 770b0fb8
...@@ -27,30 +27,31 @@ RSpec.describe Dast::Profile, type: :model do ...@@ -27,30 +27,31 @@ RSpec.describe Dast::Profile, type: :model do
it { is_expected.to validate_presence_of(:dast_scanner_profile_id) } it { is_expected.to validate_presence_of(:dast_scanner_profile_id) }
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
context 'when the project_id and dast_site_profile.project_id do not match' do shared_examples 'the project_id does not match' do
let(:dast_site_profile) { create(:dast_site_profile) } let(:association_name) { association.class.underscore }
subject { build(:dast_profile, project: project, dast_site_profile: dast_site_profile) } subject { build(:dast_profile, project: project, association_name => association) }
it 'is not valid' do before do
aggregate_failures do association.project_id = non_existing_record_id
expect(subject.valid?).to be_falsey end
expect(subject.errors.full_messages).to include('Project must match dast_site_profile.project_id')
end it 'is not valid', :aggregate_failures do
expect(subject).not_to be_valid
expect(subject.errors.full_messages).to include("Project must match #{association_name}.project_id")
end end
end end
context 'when the project_id and dast_scanner_profile.project_id do not match' do context 'when the project_id and dast_site_profile.project_id do not match' do
let(:dast_scanner_profile) { create(:dast_scanner_profile) } let(:association) { build(:dast_site_profile) }
subject { build(:dast_profile, project: project, dast_scanner_profile: dast_scanner_profile) } it_behaves_like 'the project_id does not match'
end
it 'is not valid' do context 'when the project_id and dast_scanner_profile.project_id do not match' do
aggregate_failures do let(:association) { build(:dast_scanner_profile) }
expect(subject.valid?).to be_falsey
expect(subject.errors.full_messages).to include('Project must match dast_scanner_profile.project_id') it_behaves_like 'the project_id does not match'
end
end
end end
context 'when the description is nil' do context 'when the description is nil' do
...@@ -58,7 +59,7 @@ RSpec.describe Dast::Profile, type: :model do ...@@ -58,7 +59,7 @@ RSpec.describe Dast::Profile, type: :model do
it 'is not valid' do it 'is not valid' do
aggregate_failures do aggregate_failures do
expect(subject.valid?).to be_falsey expect(subject).not_to be_valid
expect(subject.errors.full_messages).to include('Description can\'t be nil') expect(subject.errors.full_messages).to include('Description can\'t be nil')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment