AO3-4862 Extending work controller test coverage - #3888
Conversation
Also implemented show multiple for pseuds
- Added edit multiple works for pseud - Removed several dead code paths
| context "with restricted works" do | ||
| before do | ||
| @work2 = create(:work, fandom_string: @fandom.name, restricted: true) | ||
| work2 = create(:work, fandom_string: @fandom.name, restricted: true) |
There was a problem hiding this comment.
It's not useless, we're checking it doesn't come up in the search results.
| @fandom2 = create(:canonical_fandom) | ||
| @work2 = create(:work, fandom_string: @fandom2.name) | ||
| fandom2 = create(:canonical_fandom) | ||
| work2 = create(:work, fandom_string: fandom2.name) |
There was a problem hiding this comment.
Not useless, we're checking it's not in the results.
sarken
left a comment
There was a problem hiding this comment.
Thanks for updating this! I've left some comments, and I think this might need to be updated with master before Travis will successfully run. No rush, though!
| @fandom2 = create(:canonical_fandom) | ||
| @work2 = create(:work, fandom_string: @fandom2.name) | ||
| fandom2 = create(:canonical_fandom) | ||
| work2 = create(:work, fandom_string: fandom2.name) |
There was a problem hiding this comment.
The results run in a different scope, so these variables are inaccessible in the results. (Hence Hound's complaint.) I think let! would be good here.
| put :update_multiple, params: params | ||
| end | ||
|
|
||
| xit "redirects to the user multiple work path with an error" do |
There was a problem hiding this comment.
Why is this test disabled?
There was a problem hiding this comment.
Also doesn't seem to have a reason so I've enabled it
There was a problem hiding this comment.
Did you mean to reenable this? It's still xit.
It should probably also say "the edit user multiple works path" -- there are other user multiple works paths, e.g. show_multiple_user_works_path.
There was a problem hiding this comment.
Yes, oops, should now be properly enabled, and I've fixed the name
|
I've fixed all the previous comments, can't currently figure out if the failing test is related to the changes. |
| include "Invalid creator: Could not find a pseud *impossible*." | ||
| end | ||
|
|
||
| it "renders new if edit is pressed" do |
There was a problem hiding this comment.
it "renders new if edit_button params" do, since that describes the code rather than the behavior and corresponds more closely with the phrasing below?
|
|
||
| it "renders new if edit is pressed" do | ||
| work_attributes = attributes_for(:work).except(:posted) | ||
| # returns a failure unpermitted param :posted, so removed it following same method as above |
There was a problem hiding this comment.
I think you can leave this off -- if we didn't need an explanation in the other places we've used it, we don't need it here.
If you think it's necessary, the best move would probably be to either put a comment above the first use of .except(:posted) or all uses.
| end | ||
|
|
||
| it "redirects to tags works page for noncanonical merged tags page" do | ||
| noncanonical_fandom = create(:fandom, canonical: false) |
There was a problem hiding this comment.
For both this example and the next, create(:fandom) makes noncanonical tags by default, so you should be able to do without canonical: false.
Also, can you set up the canonical/syn relationship right out of the gate by doing create(:fandom, merger_id: fandom.id) and eliminating the next two lines?
| let(:update_work) { | ||
| work = create(:work, authors: [update_user.default_pseud]) | ||
| let!(:update_work) do | ||
| work = create(:work, authors: [update_user.default_pseud], posted: true) |
There was a problem hiding this comment.
posted: true shouldn't be necessary here. The work factory should make posted works by default:
Lines 4 to 12 in c200136
| @@ -0,0 +1,20 @@ | |||
| # frozen_string_literal: true | |||
There was a problem hiding this comment.
Let's call this file tags_spec.rb, so it could cover all the work actions with tags in the name, much like we have drafts_spec.rb for drafts and post_draft.
| put :update_multiple, params: params | ||
| end | ||
|
|
||
| xit "redirects to the user multiple work path with an error" do |
There was a problem hiding this comment.
Did you mean to reenable this? It's still xit.
It should probably also say "the edit user multiple works path" -- there are other user multiple works paths, e.g. show_multiple_user_works_path.
| When "AO3-3455" is fixed | ||
| # And I should see "classic" |
There was a problem hiding this comment.
This isn't right -- the tag shows up on the edit page, just not in the meta due to caching. (Also, fwiw, the next thing we're merging is #4014, which contains the fix for AO3-3455.)
The failure might be because you need to check the contents of the Additional Tags field, which is done with a different step than checking text outside a form field. You could also try enabling JavaScript for this test instead, which might drag the tag out of the form field.
| end | ||
| end | ||
|
|
||
| context "when work parameters are invalid" do |
There was a problem hiding this comment.
I'm kind of thinking we should set this up in a way that'll make it easier to add coverage of other invalid work params in the future, e.g.
context "when work params are invalid" do
context "when summary is invalid" do
context "when some other param is invalid" do
context "when yet another param is invalid" do
... but now that I'm looking at the edit multiple work page, summary isn't one of the parameters you're meant to edit, so I'm a little confused what we're actually try to test here.
Is this meant to test passing an unpermitted work parameter (e.g., a summary), or a permitted parameter with an invalid value (e.g., a visibility setting that doesn't exist)?
There was a problem hiding this comment.
I'm not sure what the original developer was trying to test, but checking both of those sounds like a good idea to me. I'll have a go.
There was a problem hiding this comment.
It looks like an unpermitted work parameter actually works fine, which is a minor loophole if people want to be editing their form submissions manually, but not a big security risk since it still goes through the normal work controller checks. And a permitted parameter with an invalid value gives an error in the controller rather than a friendly error page, but that's okay because the form doesn't let you do that unless you edit the form submission manually anyway. So I'm going to scrap this test as it requires coding skills to do either rather than being something a user normally could do.
| expect(response).to redirect_to(tag_path(noncanonical_tag)) | ||
| end | ||
|
|
||
| it "redirects to tags works page for noncanonical merged tags page" do |
There was a problem hiding this comment.
Should this example and the one on line 357 be tested under the without caching section, since we already have the same tests in the with caching section?
otwarchive/spec/controllers/works/default_rails_actions_spec.rb
Lines 456 to 474 in 584c4da
It would also makes sense to use the same descriptions for the new tests that we used for the existing tests. That will make it clearer the examples just cover the same thing in different contexts. (If you could change the existing describe "with caching" and describe "without caching" to context instead, that would be great.)
| allow(controller).to receive(:fetch_admin_settings).and_call_original | ||
| end | ||
|
|
||
| it "shows results when filters are disabled" do |
There was a problem hiding this comment.
Let's describe this as it "returns the work" do. That will
- match the description of the related example on line 332
- get rid of the incorrect part about filters being disabled (we're testing when filter counts are suspended, which is made clear by the fact this is inside
context "when suspend_filter_counts is on" do)
There was a problem hiding this comment.
I've tweaked slightly further to "shows the work in the index", and also clarified the description a couple of lines down.
|
When I come back to this, I have one cucumber test still to fix, the rest of the comments have been addressed. |
|
Hi, Cesy! Someone pointed out this has been in draft for two years, so I wanted to check if you'd be picking this back up soon. If not, no worries, we can close it until you're ready. |
|
I'd still be up for it if you think it would be useful? I imagine better automated tests are still a good thing. |
|
Yeah, more test coverage is always good! |
|
Adopted at #5959 based on the policy for stalled pull requests |
Issue
https://otwarchive.atlassian.net/browse/AO3-4862
Purpose
Updated version of #3165
Please make sure Tal Hayon gets correct credit.