Flaky spec: Polls Concerns behaves like notifiable in-app Multiple users commented on my notifiable #2699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, thecurrent_user
variable was not being set correctly. In the previous version of the test, after loging in as the notifiable's author, there were twovisit root_path
.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:
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
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.