-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write tests for ExcludedRequestController
Cover all edge cases. Co-authored-by: David Kang <dkang@suse.com> Co-authored-by: Moisés Déniz Alemán <mdeniz@suse.com>
- Loading branch information
1 parent
e4aa4e9
commit f1cfcc9
Showing
1 changed file
with
136 additions
and
0 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
src/api/spec/controllers/staging/excluded_requests_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Staging::ExcludedRequestsController, type: :controller, vcr: true do | ||
let(:user) { create(:confirmed_user, login: 'user') } | ||
let(:other_user) { create(:confirmed_user, login: 'other_user') } | ||
let(:project) { user.home_project } | ||
let(:staging_workflow) { create(:staging_workflow_with_staging_projects, project: project) } | ||
let(:group) { staging_workflow.managers_group } | ||
let(:manager) { create(:confirmed_user, login: 'manager', groups: [group]) } | ||
let(:source_project) { create(:project, name: 'source_project') } | ||
let(:target_package) { create(:package, name: 'target_package', project: project) } | ||
let(:source_package) { create(:package, name: 'source_package', project: source_project) } | ||
let(:review) { create(:review, by_group: group.title) } | ||
let(:bs_request) do | ||
create(:bs_request_with_submit_action, | ||
creator: other_user, | ||
target_project: project.name, | ||
target_package: target_package.name, | ||
source_project: source_project.name, | ||
source_package: source_package.name, | ||
reviews: [review]) | ||
end | ||
|
||
before { login(manager) } | ||
|
||
describe 'POST #create' do | ||
context 'succeeds' do | ||
subject { post :create, params: { number: bs_request.number, project_name: project, description: "I don't want to see you any more" }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
end | ||
|
||
it { expect { subject }.to(change { staging_workflow.request_exclusions.count }.by(1)) } | ||
end | ||
|
||
context 'fails: project does not exist' do | ||
subject { post :create, params: { number: bs_request.number, project_name: 'i_do_not_exist', description: "I don't want to see you any more" }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(404) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
|
||
context 'fails: project without staging_workflow' do | ||
let(:project_without_staging) { create(:project, name: 'no_staging') } | ||
subject { post :create, params: { number: bs_request.number, project_name: project_without_staging, description: "I don't want to see you any more" }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(400) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
|
||
context 'fails: invalid request exclusion' do | ||
let(:project_without_staging) { create(:project, name: 'without_staging_wokflow') } | ||
subject { post :create, params: { number: bs_request.number, project_name: project_without_staging }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(400) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
let(:request_exclusion) { create(:request_exclusion, bs_request: bs_request, staging_workflow: staging_workflow) } | ||
|
||
context 'succeeds' do | ||
subject { delete :destroy, params: { number: bs_request.number }, format: :xml } | ||
|
||
before { request_exclusion } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(:success) } | ||
end | ||
|
||
it { expect { subject }.to(change { staging_workflow.request_exclusions.count }.by(-1)) } | ||
end | ||
|
||
context 'fails: request does not exist' do | ||
subject { delete :destroy, params: { number: 43543 }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(404) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
|
||
context 'fails: request not excluded' do | ||
subject { delete :destroy, params: { number: bs_request.number }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(400) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
|
||
context 'fails: unable to destroy' do | ||
before do | ||
request_exclusion | ||
allow_any_instance_of(Staging::RequestExclusion).to receive(:destroy).and_return(false) | ||
end | ||
|
||
subject { delete :destroy, params: { number: bs_request.number }, format: :xml } | ||
|
||
context 'response' do | ||
before { subject } | ||
|
||
it { expect(response).to have_http_status(400) } | ||
end | ||
|
||
it { expect { subject }.not_to(change { staging_workflow.request_exclusions.count }) } | ||
end | ||
end | ||
end |