Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

[1339] hide announcement #1350

Merged
merged 1 commit into from
Jan 5, 2016
Merged

[1339] hide announcement #1350

merged 1 commit into from
Jan 5, 2016

Conversation

alex-kogan
Copy link
Contributor

Resolves #1339 on master

@orenyk
Copy link
Contributor

orenyk commented Nov 10, 2015

Here are some notes on testing cookies in controller specs. You'd basically want to use the Devise helpers for spoofing user login in the tests - to see how we've done it in the past you can look at spec/controllers/reservations_controller_spec.rb.

@alex-kogan
Copy link
Contributor Author

@AlanLiu96 - Ready for your code review

@alex-kogan
Copy link
Contributor Author

@orenyk - While doing he's code review for this issue Alan raised a valid question, should a banned user be able to hide the announcements as well?

@AlanLiu96
Copy link
Contributor

It looks good mostly! The only issues that came up were when checkout users and banned users were not able to hide the announcement. I also found that if you hid the announcements and quickly changed the page, the announcements were still there, but I think that's a separate issue (or not one we have to worry much about anyway). Once the checkout users and banned users are addressed, it should be set to merge in!

@orenyk
Copy link
Contributor

orenyk commented Dec 6, 2015

Thanks @AlanLiu96! Regarding the refresh issue - did the "hidden" announcements stay visible permanently or only for a single refresh? Either way it's probably ok, but we should still understand what's going on.

@orenyk
Copy link
Contributor

orenyk commented Dec 14, 2015

A second note - once we squash these commits we should cherry pick that squashed commit onto release-v5.5 to patch that version as well.

@AlanLiu96
Copy link
Contributor

I'm not sure if it's fixed now, but the hidden announcements stayed there permanently when I last checked. I think that it was probably just from changing the page too quickly before it fully completed the request made to hide the announcement.

@orenyk
Copy link
Contributor

orenyk commented Dec 21, 2015

@alex-kogan please comment when @AlanLiu96's comments re: checkout persons and banned users have been addressed, thanks!

@orenyk
Copy link
Contributor

orenyk commented Dec 22, 2015

@alex-kogan I just tested locally and confirmed that Checkout Persons and Banned users can't dismiss announcements. Let's get it fixed and make sure that the tests are actually working.

@alex-kogan
Copy link
Contributor Author

@AlanLiu96 & @orenyk - Added the needed abilities please recheck.

@orenyk
Copy link
Contributor

orenyk commented Dec 23, 2015

Looks good, although I'm confused as to why your tests didn't pick it up. I'll do a code review now and see if we can figure it out.

@@ -31,6 +31,7 @@ def initialize(user) # rubocop:disable all
can :override, :reservation_errors if AppConfig.get(:override_on_create)
can :override, :checkout_errors if AppConfig.get(:override_at_checkout)
can :view_detailed, EquipmentModel
can :hide, Announcement
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is unnecessary given line 47 below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed the redundancy but for some reason without that line checkout-person can't hide the announcement

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, that's odd. I'll mess around and see if I can figure out why.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the record, this is a separate issue and we'll deal with it in #1391

@alex-kogan
Copy link
Contributor Author

@orenyk - my hypothesis about the tests:

  1. it only check the js
  2. it uses the ability to decide for what type of user to test for the hide ability

@@ -129,5 +149,8 @@
end
it_behaves_like 'access denied'
end
context 'GET hide' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this test only checks for patrons (see line 123 above), not all user roles. That's why it didn't catch the others. We should probably write tests for all roles... as this is a common problem I'm going to open a new issue to write an RSpec helper to deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I remember that when we discussed it last time that was the decision made :)
I'll wait for the issue to open

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. For this issue let's include separate tests for all roles and we'll refactor in #1390. I'm still looking into the ability.rb thing, it might actually be fundamentally broken 😛.

@orenyk
Copy link
Contributor

orenyk commented Dec 23, 2015

Ok, ability.rb is kinda broken but at the moment it isn't a big deal (see #1391 for more details). Let's leave this working and we'll refactor there, although let's add the appropriate specs to cover all user roles. Make sense?

verifier = ActiveSupport::MessageVerifier.new(
Reservations::Application.config.secret_key_base)
name = 'hidden_announcement_ids'
@request.cookies[name] = verifier.generate([@announcement[:id].to_s])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using @request instead of just request? Changing it doesn't appear to break the spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, the major issue is here. You're basically setting the relevant cookie in the request and therefore it's still set in the response, regardless of the controller behavior. If we look at this SO answer, we see how we would test for a signed cookie, effectively deleting line 29 (this line) and adding the following after line 30:

jar.signed[name] = [@announcement[:id].to_s]

This gives us an equivalent cookie to test against, and then we check to make sure the response has the right cookie value. I made sure it worked by commenting out the relevant line in ability.rb and the test failed as expected.

Let's get this text fixed and duplicate it to check all user roles. Let me know if you have any questions!

@orenyk
Copy link
Contributor

orenyk commented Dec 23, 2015

Ok, more problematically, the spec doesn't actually appear to test anything (in the sense that when I remove the "fix" in ability.rb the test still passes. This is one of the primary motivators for the Red-Green-Refactor / TDD system - if we don't have an initially failing test, we don't actually know that our code changes make it pass. Given the complexity of this test I'm going to take a stab at making it work, if that's all right with you.

@orenyk
Copy link
Contributor

orenyk commented Dec 23, 2015

Ok, figured it out - I'll comment inline.

Reservations::Application.config.secret_key_base)
name = 'hidden_announcement_ids'
@request.cookies[name] = verifier.generate([@announcement[:id].to_s])
jar = @request.cookie_jar
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, let's remove the @ here (so it would be jar = request.cookie_jar) for consistency.

@alex-kogan
Copy link
Contributor Author

@orenyk - Fixed the actual spec to test the hiding of the announcements, also added specs for each type of user. Ready for re-review.

@@ -130,4 +145,43 @@
it_behaves_like 'access denied'
end
end
context 'check hide' do
before { @announcement = FactoryGirl.create(:announcement) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary given line 20 above, @announcement already exists.

@orenyk
Copy link
Contributor

orenyk commented Dec 27, 2015

Ok, this is now working as expected, well done 😄. Just a few inline comments, mostly regarding the naming of test blocks and the organization of the spec file, and I think this will be good to squash. Feel free to squash after making the changes and we'll give this a final quick review before cherry-picking for v5.5.1 and merging both PR's. Thanks!

@alex-kogan
Copy link
Contributor Author

Fixed all the comments, I don't really know how to squash...
If you can give me some instructions that would be appreciated.

@alex-kogan alex-kogan closed this Dec 27, 2015
@alex-kogan alex-kogan reopened this Dec 27, 2015
@orenyk
Copy link
Contributor

orenyk commented Dec 27, 2015

Great, looks good. Here's our guide to squashing commits from the contributing guide - you can replace step 1 by just looking at the pull request (i.e. it says "9 Commits" at the top), but everything else should work fine. Give it a shot; as long as you don't push things to GitHub you can always delete your local branch and try again if you mess something up. Let me know if you run into any specific issues!

@alex-kogan
Copy link
Contributor Author

I squashed the commits, now what?

@orenyk
Copy link
Contributor

orenyk commented Dec 30, 2015

Now you'd force-push to this branch:

git push -f origin 1339_hide_announcement

If you're worried that you might have messed something up you can always create a new branch at the new commit and push that instead, just to verify that the diff is identical (although it should be) without overwriting any history. Does that make sense?

@alex-kogan alex-kogan force-pushed the 1339_hide_announcement branch from d4f5021 to 081e261 Compare January 1, 2016 14:21
@alex-kogan
Copy link
Contributor Author

Done!

@orenyk
Copy link
Contributor

orenyk commented Jan 1, 2016

Looks good. The last thing is you need to update the commit message to clean up all the duplication from the various commit messages (everything after - Add shared examples for specs) and fix the typo in the third line (Cahnge --> Change). You can do that using git commit --amend from within the branch to edit the commit message and force-push the branch again. Once we've merged this in to master we'll cherry-pick the final commit onto release-v5.5 as well. Nice work!

@orenyk
Copy link
Contributor

orenyk commented Jan 5, 2016

@alex-kogan I don't know if you missed this but I'd like to get this onto release-v5.5 ASAP so we can tag/release/deploy a new release candidate. Let me know when you've had a chance to update this, thanks!

@alex-kogan
Copy link
Contributor Author

Haven't missed it will do it asap. Thanks!

‫ב-5 בינו׳ 2016, בשעה 9:01, ‏‏Oren Kanner ‏[email protected] כתב/ה:‬

@alex-kogan I don't know if you missed this but I'd like to get this onto release-v5.5 ASAP so we can tag/release/deploy a new release candidate. Let me know when you've had a chance to update this, thanks!


Reply to this email directly or view it on GitHub.

@orenyk
Copy link
Contributor

orenyk commented Jan 5, 2016 via email

Resolves #1339
- Change the ability file
- Add a cookie testing spec
- Add shared examples for specs
@alex-kogan alex-kogan force-pushed the 1339_hide_announcement branch from 081e261 to 3742415 Compare January 5, 2016 08:58
@alex-kogan
Copy link
Contributor Author

Done - ready for realse

@orenyk
Copy link
Contributor

orenyk commented Jan 5, 2016

Perfect, merging. I'll cherry-pick onto release-v5.5 and update the CHANGELOG's.

orenyk added a commit that referenced this pull request Jan 5, 2016
@orenyk orenyk merged commit 02ec988 into master Jan 5, 2016
@orenyk orenyk removed the 1 - working label Jan 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants