diff --git a/app/controllers/challenge_signups_controller.rb b/app/controllers/challenge_signups_controller.rb index e456e3ecda..a330c61436 100644 --- a/app/controllers/challenge_signups_controller.rb +++ b/app/controllers/challenge_signups_controller.rb @@ -17,6 +17,8 @@ class ChallengeSignupsController < ApplicationController before_action :check_signup_in_collection, only: [:show, :edit, :update, :destroy, :confirm_delete] def load_challenge + raise ActiveRecord::RecordNotFound, "Couldn't find collection named '#{params[:collection_id]}'" unless @collection + @challenge = @collection.challenge no_challenge and return unless @challenge end diff --git a/spec/controllers/challenge_signups_controller_spec.rb b/spec/controllers/challenge_signups_controller_spec.rb index 4f269dde81..4c4e9571bf 100644 --- a/spec/controllers/challenge_signups_controller_spec.rb +++ b/spec/controllers/challenge_signups_controller_spec.rb @@ -46,6 +46,25 @@ "What challenge did you want to sign up for?") end end + + context "when collection does not exist" do + it "raises a RecordNotFound error" do + fake_login + expect do + get :new, params: { collection_id: "nonexistent_collection" } + end.to raise_error ActiveRecord::RecordNotFound + end + end + end + + describe "summary" do + context "when collection does not exist" do + it "raises a RecordNotFound error" do + expect do + get :summary, params: { collection_id: "nonexistent_collection" } + end.to raise_error ActiveRecord::RecordNotFound + end + end end describe "show" do