Skip to content

Commit

Permalink
Status Reports: Fix not found handling
Browse files Browse the repository at this point in the history
Add coverage for checkables not found and fix problems
with it. The error message was overwritten and we don't
need a default error message as it's impossible to
match the :update route without either project or
request number
  • Loading branch information
coolo committed Nov 14, 2018
1 parent fa6b35b commit bea7f81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/api/app/controllers/status/concerns/set_checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ module SetCheckable
private

def set_checkable
set_repository_architecture || set_bs_request
set_repository_architecture if params[:project_name]
set_bs_request if params[:bs_request_number]
return if @checkable

@error_message ||= 'Provide at least project_name and repository_name or request number.'
render_error(
status: 404,
errorcode: 'not_found',
message: @error_message
)
raise ActiveRecord::RecordNotFound, @error_message
end

def set_project
Expand Down
32 changes: 32 additions & 0 deletions src/api/spec/controllers/status/checks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
XML
end

context 'when referencing to non-existant checkable' do
it 'gives 404 for request' do
expect(post(:update, body: xml, params: { bs_request_number: 1 }, format: :xml)).to have_http_status(:not_found)
expect(Xmlhash.parse(response.body)['summary']).to match(/Submit request.*not found/)
end

it 'gives 404 for invalid project' do
expect(post(:update, body: xml, params: { project_name: project.name + '_', report_uuid: 'nada', repository_name: repository.name }, format: :xml)).to have_http_status(:not_found)
expect(Xmlhash.parse(response.body)['summary']).to match(/Project.*not found/)
end

it 'gives 404 for invalid repository' do
expect(post(:update, body: xml, params: { project_name: project.name, report_uuid: 'nada', repository_name: repository.name + '_' }, format: :xml)).to have_http_status(:not_found)
expect(Xmlhash.parse(response.body)['summary']).to match(/Repository.*not found/)
end

it 'gives 404 for invalid architecture' do
params = { project_name: project.name, report_uuid: 'nada', repository_name: repository.name, arch: '_' }
expect(post(:update, body: xml, params: params, format: :xml)).to have_http_status(:not_found)
expect(Xmlhash.parse(response.body)['summary']).to match(/Repository.*not found/)
end
end

context 'when status report exists and check does not exist' do
shared_examples 'does create the check' do
let!(:relationship) { create(:relationship_project_user, user: user, project: project) }
Expand Down Expand Up @@ -79,6 +102,15 @@
include_context 'does create the check'
end

context 'for a repository architecture' do
let(:status_report) { create(:status_report, checkable: repository_architecture) }
let(:params) do
{ report_uuid: status_report.uuid, repository_name: repository.name, project_name: project.name, arch: repository_architecture.architecture.name }
end

include_context 'does create the check'
end

context 'for a request' do
let(:source_package) { create(:package) }
let(:source_project) { source_package.project }
Expand Down

0 comments on commit bea7f81

Please sign in to comment.