Skip to content
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

AO3-5447 Give 404 instead of 500 for works pages for nonexistent users #3345

Merged
merged 8 commits into from
Aug 13, 2018

Conversation

sarken
Copy link
Member

@sarken sarken commented Jun 15, 2018

Issue

https://otwarchive.atlassian.net/browse/AO3-5447

Purpose

  • Gives a 404 error (by way of ActiveRecord::RecordNotFound) if you try to access the works page for a user that doesn't exist, regardless of whether you're aiming for the user's works page or a pseud's
  • Finishes testing the various load_owner possibilities, since that's the method I was editing
  • Cleans up tests in controllers/works/default_rails_actions_spec.rb

Testing

Refer to Jira

AO3-5447 Test mergers in collections as long as I'm here
* It thought 'the works page' meant /users/the/works and not just /works
* Typo in admin tests had us checking a nonexistent user's works page

AO3-5447 Fix tests that were accidentally checking the works pages for nonexistent users

AO3-5447 Update the regex for user work paths

* Thanks zz9pzza
* Less FactoryGirl.create
* Less posted: true
* Less repetition on the includes

AO3-5447 Older tests shouldn't say should
end
end

context "with a valid owner user" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [29/25]

it "raises an error" do
params = { user_id: "nonexistent_user", pseud_id: "nonexistent_pseud" }
expect{ get :index, params: params }.to raise_error(
ActiveRecord::RecordNotFound, "Couldn't find user named 'nonexistent_user'")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

context "with an invalid pseud" do
it "raises an error" do
params = { user_id: "nonexistent_user", pseud_id: "nonexistent_pseud" }
expect{ get :index, params: params }.to raise_error(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.

it "raises an error" do
params = { user_id: "nonexistent_user" }
expect{ get :index, params: params }.to raise_error(
ActiveRecord::RecordNotFound, "Couldn't find user named 'nonexistent_user'")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

context "with an invalid owner user" do
it "raises an error" do
params = { user_id: "nonexistent_user" }
expect{ get :index, params: params }.to raise_error(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.

it "raises an error" do
params = { tag_id: "nonexistent_tag" }
expect{ get :index, params: params }.to raise_error(
ActiveRecord::RecordNotFound, "Couldn't find tag named 'nonexistent_tag'")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

context "with an invalid owner tag" do
it "raises an error" do
params = { tag_id: "nonexistent_tag" }
expect{ get :index, params: params }.to raise_error(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.

end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.

update_and_refresh_indexes('work')
get :index
expect(assigns(:works)).not_to include(work2)
end
end

context "with an owner tag" do
context "with a valid owner tag" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [53/25]

@@ -797,7 +797,9 @@ def mark_as_read
def load_owner
if params[:user_id].present?
@user = User.find_by(login: params[:user_id])
if params[:pseud_id].present?
if @user.blank?
raise ActiveRecord::RecordNotFound, "Couldn't find user named '#{params[:user_id]}'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of manually raising the exception, we could use find_by!.

get :index, params: { tag_id: @fandom.name }
expect(assigns(:works).items).to include(@work)
expect(assigns(:works).items).not_to include(@work2)
end

end

context "when tag is a synonym" do
before do
@fandom_synonym = create(:fandom, merger: @fandom)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use let to avoid leaking state between tests in instance variables. You don't need to change all the existing instance variables though.

update_and_refresh_indexes('work')
get :index
expect(assigns(:works)).not_to include(work2)
end
end

context "with an owner tag" do
context "with a valid owner tag" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/BlockLength: Block has too many lines. [49/25]

@sarken
Copy link
Member Author

sarken commented Aug 11, 2018

This needs updating

@sarken
Copy link
Member Author

sarken commented Aug 13, 2018

I took a stab at the merge conflicts. 🤞 I didn't make a mess. I hate past me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants