500 Error when accessing works/collected for a user that does not exist

Description

If you try to go to the Works in Collections page for a user that does not exist, e.g. https://test.archiveofourown.org/users/IMNOTREAL/works/collected, you get a 500 error.

You should get a 404 instead.

Activity

Show:
tlee911
August 7, 2020, 3:24 PM

Ruby and rails newbie here, so I started looking into this to as way to learn about the routing. I think we just need a guard here for invalid users:
https://github.com/otwcode/otwarchive/blob/master/app/controllers/works_controller.rb#L143

What would be the desired behaviour in this situation? Straight up 404, or the same as https://archiveofourown.org/users/randomfakeuser with redirect to search?

Also I would like to add a test, but not sure what's the right file for that (there's no works_controller_spec I could find).

Sarken
August 8, 2020, 10:24 AM

We want a 404 instead of a redirect, yeah.

I think what we’ve done elsewhere to solve problems like this is use find_by! instead of find_by, e.g. and .

Because the works controller is so big, we’ve divided the specs up a bit. It looks like the specs for the collected action are here: https://github.com/otwcode/otwarchive/blob/master/spec/controllers/works/default_rails_actions_spec.rb#L504 (A little counterintuitive since collected is not a default Rails action like index or show, but we probably didn’t want to put it in a separate file.)

tlee911
August 8, 2020, 1:30 PM
Sarken
October 9, 2020, 7:41 PM

https://test.archiveofourown.org/users/IMNOTAREALUSER/works/collected now gives a 404 instead of a 500. Looks good!

redsummernight
October 11, 2020, 6:32 AM
DeployedToBeta

Assignee

tlee911

Reporter

Sarken

Roadmap

Users
Works

Priority

Low

Affects versions

Fix versions

Components

BackEnd

Difficulty

Medium

Milestone

Internal 0.9