Skip to content

Respond with 404 Not Found if project not found in Api::SchoolProjectsController actions #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/api/school_projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class SchoolProjectsController < ApiController
load_and_authorize_resource :project

def show_finished
@school_project = Project.find_by(identifier: params[:id]).school_project
@school_project = Project.find_by!(identifier: params[:id]).school_project
authorize! :show_finished, @school_project
render :finished, formats: [:json], status: :ok
end

def set_finished
project = Project.find_by(identifier: params[:id])
project = Project.find_by!(identifier: params[:id])
@school_project = project.school_project
authorize! :set_finished, @school_project
result = SchoolProject::SetFinished.call(school_project: @school_project, finished: params[:finished])
Expand Down
10 changes: 10 additions & 0 deletions spec/requests/school_projects/set_finished_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@
expect(teacher_project.school_project.finished).to be_falsey
end
end

context 'when project does not exist' do
before do
put('/api/projects/does-not-exist/finished', headers:, params: { finished: false })
end

it 'returns not found response' do
expect(response).to have_http_status(:not_found)
end
end
end
10 changes: 10 additions & 0 deletions spec/requests/school_projects/show_finished_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,15 @@
expect(response).to have_http_status(:forbidden)
end
end

context 'when project does not exist' do
before do
get('/api/projects/does-not-exist/finished', headers:)
end

it 'returns not found response' do
expect(response).to have_http_status(:not_found)
end
end
end
end