Skip to content
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
11 changes: 1 addition & 10 deletions app/controllers/related_works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions spec/controllers/related_works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading