Skip to content

Commit

Permalink
Fix flaky spec "Notifications User not logged in"
Browse files Browse the repository at this point in the history
We had a test failing several times in GitHub Actions where a user was
still logged in even after logout.

This issue can be reproduced running:

```
rspec spec/system/moderation/proposal_notifications_spec.rb:71 \
spec/system/notifications_spec.rb:126 --order defined
```

One possible cause is a concurrency issue because the process running
the test and the process running the browser both access the same
database connection. Maybe some database operations leak between tests
due to that, particularly if the previous test accessed the database
after starting the browser as well.

A way to avoid this possible cause is setting up the database before
starting the browser with a call to `visit`.
  • Loading branch information
javierm committed Apr 7, 2021
1 parent 214bb0f commit 05fad2b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions spec/system/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

describe "Notifications" do
let(:user) { create :user }

before do
login_as(user)
visit root_path
end
before { login_as(user) }

scenario "View all" do
read1 = create(:notification, :read, user: user)
read2 = create(:notification, :read, user: user)
unread = create(:notification, user: user)

visit root_path
click_notifications_icon
click_link "Read"

Expand All @@ -27,6 +24,7 @@
unread2 = create(:notification, user: user)
read = create(:notification, :read, user: user)

visit root_path
click_notifications_icon
click_link "Unread"

Expand All @@ -40,6 +38,7 @@
proposal = create(:proposal)
create(:notification, user: user, notifiable: proposal)

visit root_path
click_notifications_icon

first(".notification a").click
Expand All @@ -56,6 +55,7 @@
notification1 = create(:notification, user: user)
notification2 = create(:notification, user: user)

visit root_path
click_notifications_icon

within("#notification_#{notification1.id}") do
Expand All @@ -70,6 +70,7 @@
scenario "Mark all as read" do
2.times { create(:notification, user: user) }

visit root_path
click_notifications_icon

expect(page).to have_css(".notification", count: 2)
Expand All @@ -82,6 +83,7 @@
notification1 = create(:notification, :read, user: user)
notification2 = create(:notification, user: user)

visit root_path
click_notifications_icon
click_link "Read"

Expand Down Expand Up @@ -115,6 +117,7 @@
end

scenario "No notifications" do
visit root_path
click_notifications_icon
expect(page).to have_content "You don't have new notifications."
end
Expand All @@ -129,6 +132,7 @@
scenario "Notification's notifiable model no longer includes Notifiable module" do
create(:notification, :for_poll_question, user: user)

visit root_path
click_notifications_icon
expect(page).to have_content("This resource is not available anymore.", count: 1)
end
Expand Down

0 comments on commit 05fad2b

Please sign in to comment.