Skip to content

Commit

Permalink
Add tests for request ignorations controller
Browse files Browse the repository at this point in the history
Co-authored-by: David Kang <dkang@suse.com>
Co-authored-by: Saray Cabrera Padrón <scabrerapadron@suse.de>
Co-authored-by: Victor Pereira <vpereira@suse.com>
Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
  • Loading branch information
5 people committed Nov 20, 2018
1 parent 81ff200 commit 2f94231
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def index

def create
authorize @staging_workflow

staging_request_exclusion = params[:staging_request_exclusion]

request = @staging_workflow.target_of_bs_requests.find_by(number: staging_request_exclusion[:number])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'rails_helper'

RSpec.describe Webui::Staging::ExcludedRequestsController, type: :controller do
let(:user) { create(:confirmed_user, login: 'tom') }
let(:project) { user.home_project }
let(:managers_group) { create(:group) }
let(:staging_workflow) { create(:staging_workflow_with_staging_projects, project: project, managers_group: managers_group) }

let(:source_package) { create(:package) }
let(:target_package) { create(:package, name: 'target_package', project: project) }
let(:bs_request) do
create(:bs_request_with_submit_action,
target_project: project.name,
target_package: target_package.name,
source_project: source_package.project.name,
source_package: source_package.name)
end

before do
login(user)
end

describe '#create' do
let(:description) { Faker::Lorem.sentence }

context 'success' do
before do
post :create, params: { staging_workflow_id: staging_workflow, staging_request_exclusion: { number: bs_request, description: description } }
end

it { expect(Staging::RequestExclusion.count).to eq(1) }
it { expect(staging_workflow.request_exclusions.first.description).to eq(description) }
it { expect(response).to redirect_to(staging_workflow_excluded_requests_path(staging_workflow)) }
it { expect(flash[:success]).not_to be_nil }
end

context "doesn't exist" do
before do
allow_any_instance_of(Staging::RequestExclusion).to receive(:save).and_return(false)
post :create, params: { staging_workflow_id: staging_workflow, staging_request_exclusion: { number: bs_request, description: description } }
end

it { expect(response).to redirect_to(staging_workflow_excluded_requests_path(staging_workflow)) }
it { expect(flash[:error]).not_to be_nil }
end
end

describe '#destroy' do
let(:request_exclusion) { create(:request_exclusion, staging_workflow: staging_workflow, bs_request: bs_request) }

context 'success' do
before do
delete :destroy, params: { staging_workflow_id: staging_workflow, id: request_exclusion }
end

it { expect(Staging::RequestExclusion.count).to eq(0) }
it { expect(response).to redirect_to(staging_workflow_excluded_requests_path(staging_workflow)) }
it { expect(flash[:success]).not_to be_nil }
end

context 'error' do
before do
allow_any_instance_of(Staging::RequestExclusion).to receive(:destroy).and_return(false)
delete :destroy, params: { staging_workflow_id: staging_workflow, id: request_exclusion }
end

it { expect(flash[:error]).not_to be_nil }
it { expect(response).to redirect_to(staging_workflow_excluded_requests_path(staging_workflow)) }
end
end
end
5 changes: 5 additions & 0 deletions src/api/spec/factories/staging_request_exclusions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :request_exclusion, class: 'Staging::RequestExclusion' do
description { Faker::Lorem.sentence }
end
end

0 comments on commit 2f94231

Please sign in to comment.