Skip to content
Open
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
6 changes: 1 addition & 5 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ def collected
end

def drafts
unless params[:user_id] && (@user = User.find_by(login: params[:user_id]))
flash[:error] = ts('Whose drafts did you want to look at?')
redirect_to users_path
return
end
@user = User.find_by!(login: params[:user_id])

unless current_user == @user || logged_in_as_admin?
flash[:error] = ts('You can only see your own drafts, sorry!')
Expand Down
15 changes: 8 additions & 7 deletions spec/controllers/works/drafts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
end

describe "drafts" do
context "when no user_id is specified" do
it "redirects to the user controller and display an appropriate error message" do
get :drafts
it_redirects_to_with_error(users_path, "Whose drafts did you want to look at?")
end
end

context "when logged out" do
before { fake_logout }

Expand Down Expand Up @@ -76,6 +69,14 @@
"You can only see your own drafts, sorry!")
end
end

context "when the requested user does not exist" do
it "raises a RecordNotFound error" do
expect do
get :drafts, params: { user_id: "invalid-user" }
end.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

describe "post_draft" do
Expand Down
Loading