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-4913 Increase coverage of ChallengeSignupsController #2798

Merged
merged 17 commits into from Oct 28, 2018

Conversation

zz9pzza
Copy link
Contributor

@zz9pzza zz9pzza commented Mar 14, 2017

Issue

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

Purpose

Increase coverage of ChallengeSignupsController

Testing

No manual testing required.

challenge_claims_controller currently has 70.11% test coverage on Coveralls:
https://coveralls.io/builds/10550066/source?filename=app%2Fcontrollers%2Fchallenge_signups_controller.rb
We'd like to increase that, with an ultimate goal of 90% or greater.
How to test:
Use Coveralls to confirm that the coverage percentage has increased:

  1. Go to https://coveralls.io/github/otwcode/otwarchive?branch=master
  2. In the "Search" field near the "Source Files on Master" heading, enter the name of the controller: challenge_claims_controller
  3. Note the number in the "Coverage" column of the table

end

Choose a reason for hiding this comment

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

Extra empty line detected at block body end.

sarken
sarken previously requested changes Mar 14, 2017
Copy link
Member

@sarken sarken left a comment

Choose a reason for hiding this comment

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

Just a reminder: with specs, you don't want to describe the big picture ("checks that signups are open") but rather what happens if sign-ups are open and what happens if sign-ups are closed. I haven't reviewed the code, but I've suggested better descriptions.

let(:open_signup_owner) { Pseud.find(open_signup.pseud_id).user }

describe "new" do
it "ensures signups are open" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors if sign-up is not open

end

describe "show" do
xit "checks that there is a challenge" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors if there is no challenge associated with the collection

"What sign-up did you want to work on?")
end

it "checks ownership" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors if the user does not own the sign-up

end

describe "index" do
it "checks for the right owner" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors if the current user is not allowed to see the specified user's sign-ups


describe "destroy" do
context "signups are open" do
it "checks that signups are open" do
Copy link
Member

Choose a reason for hiding this comment

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

it deletes the sign-up and redirects with notice

end
end
context "signups are closed" do
it "checks that signups are open" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors

expect(response).to render_template('edit')
end

it "checks ownership of the signup" do
Copy link
Member

Choose a reason for hiding this comment

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

it redirects and errors if the current user can't edit the sign-up

end

context "signups are closed" do
it "does not allow edits when signups are closed" do
Copy link
Member

Choose a reason for hiding this comment

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

You already have "signups are closed" in the context, so this only needs it redirects and errors without updating the sign-up

@sarken sarken dismissed their stale review March 14, 2017 20:50

The descriptions are mostly good now, just needs code review

let(:open_signup_owner) { Pseud.find(open_signup.pseud_id).user }

describe "new" do
it "directs and errors if sign-up is not open" do
Copy link
Member

Choose a reason for hiding this comment

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

Nothing that needs taking care of until this gets proper review, but typo: should be "redirects"

@@ -299,7 +299,7 @@ def gift_exchange_to_csv
csv_array
end


Choose a reason for hiding this comment

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

Extra blank line detected.

@sarken
Copy link
Member

sarken commented Mar 15, 2017

Did you mean to add a code change to this? If so, please update the description and the JIRA issue so we don't accidentally merge this.

@zz9pzza
Copy link
Contributor Author

zz9pzza commented Mar 15, 2017

I did change on the wrong branch, then reverted it but I missed the push that I did.

@sarken
Copy link
Member

sarken commented Mar 15, 2017

Okie dokie -- thanks for clearing it up!

require 'faker'

FactoryGirl.define do
factory :gift_exchange do
Copy link
Member

Choose a reason for hiding this comment

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

You should use the factory for gift_exchange added in #2756.

@sarken
Copy link
Member

sarken commented Apr 25, 2017

This also has merge conflicts, jsyk.

@sarken
Copy link
Member

sarken commented Jul 19, 2017

Do you think you can fix the merge conflicts and switch to the factories redsummernight mentioned soon? It would be great to get this merged before doing more Rails things.

@otw-deploy otw-deploy closed this Oct 31, 2017
@zz9pzza zz9pzza reopened this Oct 31, 2017
@sarken sarken added the Scope: Tests Only Only changes automated tests or test configuration label Jul 2, 2018
@@ -0,0 +1,12 @@
class ScheduledTagJob

Choose a reason for hiding this comment

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

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

)

unless parent_id(object.id, object).match("deleted")
json_object.merge!(

Choose a reason for hiding this comment

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

Performance/RedundantMerge: Use json_object[:bookmarkable_join] = {

)

unless parent_id(object.id, object).match("deleted")

Choose a reason for hiding this comment

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

Performance/RedundantMatch: Use =~ in places where the MatchData returned by #match will not be used.

:id, :created_at, :bookmarkable_type, :bookmarkable_id, :user_id,
:notes, :private, :updated_at, :hidden_by_admin, :pseud_id, :rec
],
methods: [:bookmarker, :collection_ids, :with_notes, :bookmarkable_date]

Choose a reason for hiding this comment

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

Style/SymbolArray: Use %i or %I for an array of symbols.

root: false,
except: [:notes_sanitizer_version, :delta],
methods: [:bookmarker, :collection_ids, :with_notes]
only: [

Choose a reason for hiding this comment

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

Style/SymbolArray: Use %i or %I for an array of symbols.

scope :by_byline, lambda {|byline|
{
conditions: ['users.login = ? AND pseuds.name = ?',
scope :by_byline, -> (byline) {

Choose a reason for hiding this comment

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

Layout/SpaceInLambdaLiteral: Do not use spaces between -> and opening brace in lambda literals
Style/Lambda: Use the lambda method for multiline lambdas.

.where(
pseuds: { id: pseud_ids }, bookmarks: { private: false, hidden_by_admin: false, rec: true }
)
.group('pseuds.id')

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
Layout/MultilineMethodCallIndentation: Use 2 (not 0) spaces for indenting an expression spanning multiple lines.

scope :public_rec_count_for, -> (pseud_ids) {
select('pseuds.id, count(pseuds.id) AS rec_count')
.joins(:bookmarks)
.where(

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
Layout/MultilineMethodCallIndentation: Use 2 (not 0) spaces for indenting an expression spanning multiple lines.

}
scope :public_rec_count_for, -> (pseud_ids) {
select('pseuds.id, count(pseuds.id) AS rec_count')
.joins(:bookmarks)

Choose a reason for hiding this comment

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

Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
Layout/MultilineMethodCallIndentation: Use 2 (not 0) spaces for indenting an expression spanning multiple lines.

conditions: {bookmarks: {private: false, hidden_by_admin: false, rec: true}, pseuds: {id: pseud_ids}},
group: 'pseuds.id'
}
scope :public_rec_count_for, -> (pseud_ids) {

Choose a reason for hiding this comment

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

Layout/SpaceInLambdaLiteral: Do not use spaces between -> and opening brace in lambda literals
Style/Lambda: Use the lambda method for multiline lambdas.

* Move to exisiting file (and delete the newer one)
* Make exisiting tests pass
Context was when sign-ups are open but test was for closed sign-up.
Now there's tests for both! Also, less repetition of parameters.
end
end

describe "update" 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. [43/25]

end

describe "show" do
xit "redirects and errors if there is no challenge associated with the collection" do
Copy link
Member

Choose a reason for hiding this comment

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

This test is ignored, does it pass or do we need a follow-up issue for it?

Copy link
Member

Choose a reason for hiding this comment

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

It fails with an ActuveRecord not found error and the actual behavior on production seems to be a 404, which I think is what we prefer, so we might want an issue to remove the code for the flash message this test is looking for. However, I'd like someone to double check the test and I are checking the right behavior because I'm a little confused why it's 404ing instead of giving the flash message.

Copy link
Contributor

Choose a reason for hiding this comment

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

The name of the test doesn't match the contents of the test -- the invalid ID below is for the challenge signup, not the challenge itself. (Hence the error message, "What sign-up did you want to work on?")

The sign-up is loaded with find instead of find_by, which makes it throw an exception instead of returning nil when there's no record:

def load_signup_from_id
@challenge_signup = ChallengeSignup.find(params[:id])
no_signup and return unless @challenge_signup
end

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, it was the description that was throwing me off! I've updated that and made an issue.

fake_login
get :new, params: { collection_id: plain_collection }
it_redirects_to_with_error(collection_path(plain_collection),
"What challenge did you want to sign up for?")

Choose a reason for hiding this comment

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

Layout/AlignParameters: Align the parameters of a method call if they span more than one line.

fake_login_known_user(open_signup_owner)
get :new, params: { collection_id: open_collection.name, pseud: user.pseuds.first }
it_redirects_to_with_notice(edit_collection_signup_path(open_collection, open_signup),
"You are already signed up for this challenge. You can edit your sign-up below.")

Choose a reason for hiding this comment

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

Layout/AlignParameters: Align the parameters of a method call if they span more than one line.

fake_login
get :new, params: { collection_id: closed_collection.name }
it_redirects_to_with_error(collection_path(closed_collection),
"Sign-up is currently closed: please contact a moderator for help.")

Choose a reason for hiding this comment

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

Layout/AlignParameters: Align the parameters of a method call if they span more than one line.

Copy link
Member

@redsummernight redsummernight left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed: Ready to Merge Scope: Tests Only Only changes automated tests or test configuration
Projects
None yet
6 participants