Skip to content

AO3-4862 Extending work controller test coverage - #3888

Closed
cesy wants to merge 20 commits into
otwcode:masterfrom
cesy:AO3-4862
Closed

AO3-4862 Extending work controller test coverage#3888
cesy wants to merge 20 commits into
otwcode:masterfrom
cesy:AO3-4862

Conversation

@cesy

@cesy cesy commented Aug 19, 2020

Copy link
Copy Markdown
Contributor

Issue

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

Purpose

Updated version of #3165

Please make sure Tal Hayon gets correct credit.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not useless, we're checking it's not in the results.

@sarken sarken left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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!

Comment thread features/works/work_edit_multiple.feature Outdated
Comment thread features/works/work_edit_multiple.feature Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/miscellaneous_spec.rb Outdated
Comment thread spec/controllers/works/miscellaneous_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
@sarken sarken added Reviewed: Action Needed Scope: Tests Only Only changes automated tests or test configuration and removed Awaiting Review labels Nov 10, 2020
Comment thread features/works/work_edit_multiple.feature Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
Comment thread spec/controllers/works/default_rails_actions_spec.rb Outdated
@fandom2 = create(:canonical_fandom)
@work2 = create(:work, fandom_string: @fandom2.name)
fandom2 = create(:canonical_fandom)
work2 = create(:work, fandom_string: fandom2.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this test disabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also doesn't seem to have a reason so I've enabled it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, oops, should now be properly enabled, and I've fixed the name

Comment thread spec/spec_helper.rb Outdated
@cesy
cesy requested a review from sarken June 16, 2021 13:38
@cesy

cesy commented Jun 16, 2021

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

end

it "redirects to tags works page for noncanonical merged tags page" do
noncanonical_fandom = create(:fandom, canonical: false)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

posted: true shouldn't be necessary here. The work factory should make posted works by default:

factory :work do
title { "My title is long enough" }
fandom_string { "Testing" }
rating_string { ArchiveConfig.RATING_DEFAULT_TAG_NAME }
archive_warning_string { ArchiveConfig.WARNING_NONE_TAG_NAME }
language_id { Language.default.id }
chapter_info = { content: "This is some chapter content for my work." }
chapter_attributes { chapter_info }
posted { true }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -0,0 +1,20 @@
# frozen_string_literal: true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

put :update_multiple, params: params
end

xit "redirects to the user multiple work path with an error" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread features/works/work_edit_tags.feature Outdated
Comment on lines +101 to +102
When "AO3-3455" is fixed
# And I should see "classic"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

context "when tag is a synonym" do
let(:fandom_synonym) { create(:fandom, merger: fandom) }
it "redirects to the merger's work index" do
params = { tag_id: fandom_synonym.name }
get :index, params: params
it_redirects_to tag_works_path(fandom)
end
context "when collection is specified" do
let(:collection) { create(:collection) }
it "redirects to the merger's collection works index" do
params = { tag_id: fandom_synonym.name, collection_id: collection.name }
get :index, params: params
it_redirects_to collection_tag_works_path(collection, fandom)
end
end
end

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.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed

allow(controller).to receive(:fetch_admin_settings).and_call_original
end

it "shows results when filters are disabled" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've tweaked slightly further to "shows the work in the index", and also clarified the description a couple of lines down.

@cesy

cesy commented Jun 18, 2021

Copy link
Copy Markdown
Contributor Author

When I come back to this, I have one cucumber test still to fix, the rest of the comments have been addressed.

@cesy
cesy marked this pull request as draft June 18, 2021 16:02
@sarken

sarken commented Jul 14, 2023

Copy link
Copy Markdown
Collaborator

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.

@cesy

cesy commented Jul 14, 2023

Copy link
Copy Markdown
Contributor Author

I'd still be up for it if you think it would be useful? I imagine better automated tests are still a good thing.

@sarken

sarken commented Jul 14, 2023

Copy link
Copy Markdown
Collaborator

Yeah, more test coverage is always good!

@Bilka2

Bilka2 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Adopted at #5959 based on the policy for stalled pull requests

@Bilka2 Bilka2 closed this Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed: Action Needed Scope: Tests Only Only changes automated tests or test configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants