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

Flaky spec: Polls Concerns behaves like notifiable in-app Multiple users commented on my notifiable #2699

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

decabeza
Copy link
Collaborator

@decabeza decabeza commented Jun 26, 2018

References

This is a backport of AyuntamientoMadrid#1294

Where

What

Fix the flaky spec that appears in spec/shared/features/notifiable_in_app.rb

How

Explain why the test is flaky, or under which conditions/scenario it fails randomly

As far as I was able to research, the problem with this flaky was around the login_as author function, where, for some reason, the current_user variable was not being set correctly. In the previous version of the test, after loging in as the notifiable's author, there were two visit root_path.

login_as author
visit root_path
visit root_path
find(".icon-notification").click

With both visits there, the test passed (always), but, when I removed one of them, the test started to fail (constantly). I realized that, after the first one, the current user was not set, so there weren't notifications available and the .icon-notification wasn't there (there was one .icon-no-notification class).
After the second one, however, the current_user was correctly set, so there were notifications (and the .icon-notification class was there).

I realized that this happens, inexplicably, for some tests (here L18, L42 and L69 )
and even removing all the code to generate the comments and notifications, like that:

3.times do
  user = create(:user, :verified)
  comment = create(:comment, commentable: notifiable, author: user)
  Notification.add(notifiable.author_id, notifiable)
end

login_as author
visit root_path
find(".icon-notification").click

it fails when searching .icon-notification

For those which only have one notification, visiting the root_path after the login works well (like here L6 )

Explain why your PR fixes it

This fix changes the way the notifications page is accessed. To test if the notifications are been shown correctly, the test doesn't need to go through the UI. I removed

visit root_path
visit root_path
find(".icon-notification").click

and changed for visit notifications_path. This way, the notifications page was accessed always, without relying on the UI.

In order to check that the notifications icon is shown, I added another test that generates a notification, visits the root_path and looks for the .icon-notification class.

Screenshots

There aren't, it's a flaky.

Test

Some tests have been modified and another one added, as explained above.

…it through UI, after the notifications are created the test goes directly to the notifications page (after login in the user). To check if the notification icon is correctly shown, a new test has been created that only does that.
@decabeza decabeza merged commit 06831f4 into master Jun 27, 2018
@decabeza decabeza deleted the polls-concerns-behaves-like-notifiable-in-app branch June 27, 2018 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant