diff --git a/app/controllers/related_works_controller.rb b/app/controllers/related_works_controller.rb index 7b6e1fe759..b740940734 100644 --- a/app/controllers/related_works_controller.rb +++ b/app/controllers/related_works_controller.rb @@ -70,16 +70,7 @@ def destroy private def load_user - if params[:user_id].blank? - flash[:error] = ts("Whose related works were you looking for?") - redirect_to search_people_path - else - @user = User.find_by(login: params[:user_id]) - if @user.blank? - flash[:error] = ts("Sorry, we couldn't find that user") - redirect_to search_people_path - end - end + @user = User.find_by!(login: params[:user_id]) end def get_instance_variables diff --git a/spec/controllers/related_works_controller_spec.rb b/spec/controllers/related_works_controller_spec.rb index 626d694737..cb60dd7cee 100644 --- a/spec/controllers/related_works_controller_spec.rb +++ b/spec/controllers/related_works_controller_spec.rb @@ -10,22 +10,16 @@ describe "GET #index" do context "for a blank user" do - before(:each) do - get :index, params: { user_id: "" } - end - - it "sets a flash message and redirects the requester" do - it_redirects_to_with_error(search_people_path, "Whose related works were you looking for?") + it "raises a RecordNotFound error" do + expect { get :index, params: { user_id: "" } } + .to raise_error(ActiveRecord::RecordNotFound) end end context "for a nonexistent user" do - before(:each) do - get :index, params: { user_id: "user" } - end - - it "sets a flash message and redirects the requester" do - it_redirects_to_with_error(search_people_path, "Sorry, we couldn't find that user") + it "raises a RecordNotFound error" do + expect { get :index, params: { user_id: "user" } } + .to raise_error(ActiveRecord::RecordNotFound) end end