Skip to content

Commit

Permalink
Simplify set_checkable concern code
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Nov 14, 2018
1 parent 39d0135 commit d8a0df0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/api/app/controllers/status/checks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Status::ChecksController < ApplicationController
after_action :verify_authorized

# PUT /status_reports/published/:project_name/:repository_name/reports/:uuid
# PUT /status_reports/build/:project_name/:repository_name/:arch/reports/:uuid
# PUT /status_reports/requests/:number
def update
authorize @status_report
Expand Down
39 changes: 13 additions & 26 deletions src/api/app/controllers/status/concerns/set_checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,35 @@ module SetCheckable
private

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

raise ActiveRecord::RecordNotFound, @error_message
return set_bs_request if params[:bs_request_number]
return set_repository_architecture if params[:arch]
set_repository
end

def set_project
@project = Project.find_by(name: params[:project_name])

return @project if @project
@error_message = "Project '#{params[:project_name]}' not found."
def project
Project.find_by!(name: params[:project_name])
end

def set_repository
set_project
return unless @project

@checkable = @project.repositories.find_by(name: params[:repository_name])
@checkable = project.repositories.find_by(name: params[:repository_name])
@event_class = Event::StatusCheckForPublished
return @checkable if @checkable

@error_message = "Repository '#{params[:project_name]}/#{params[:repository_name]}' not found."
return if @checkable
raise ActiveRecord::RecordNotFound, "Repository '#{params[:project_name]}/#{params[:repository_name]}' not found."
end

def set_repository_architecture
return unless set_repository
return @checkable unless params[:arch]

set_repository
@checkable = @checkable.repository_architectures.joins(:architecture).find_by(architectures: { name: params[:arch] })
@event_class = Event::StatusCheckForBuild
return @checkable if @checkable

@error_message = "Repository '#{params[:project_name]}/#{params[:repository_name]}/#{params[:arch]}' not found."
return if @checkable
raise ActiveRecord::RecordNotFound, "Repository '#{params[:project_name]}/#{params[:repository_name]}/#{params[:arch]}' not found."
end

def set_bs_request
@checkable = BsRequest.with_submit_requests.find_by(number: params[:bs_request_number])
@event_class = Event::StatusCheckForRequest
return @checkable if @checkable

@error_message = "Submit request with number '#{params[:bs_request_number]}' not found."
return if @checkable
raise ActiveRecord::RecordNotFound, "Submit request with number '#{params[:bs_request_number]}' not found."
end
end
end
Expand Down
1 change: 1 addition & 0 deletions src/api/app/controllers/status/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Status::ReportsController < ApplicationController
skip_before_action :require_login, only: [:show]

# GET /status_reports/published/:project_name/:repository_name/reports/:uuid
# GET /status_reports/build/:project_name/:repository_name/:arch/reports/:uuid
def show
@checks = @status_report.checks
@missing_checks = @status_report.missing_checks
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/status/checks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

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/)
expect(Xmlhash.parse(response.body)['summary']).to match(/Couldn't find Project/)
end

it 'gives 404 for invalid repository' do
Expand Down

0 comments on commit d8a0df0

Please sign in to comment.