From 7489f16633470d7804479f48da693ba7657f1a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 8 Feb 2021 20:23:08 +0100 Subject: [PATCH] Try to avoid exception after flaggable tests We had one exception running test suite [1]: ``` 1) Commenting legislation questions Merged comment threads View comments of annotations in an included range Failure/Error: count: annotation.comments.roots.count) %> ActionView::Template::Error: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 2 : SELECT COUNT(*) FROM "comments" WHERE "comments"."hidden_at" IS NULL AND "comments"."commentable_id" = $1 AND "comments"."commentable_type" = $2 AND "comments"."ancestry" IS NULL ``` Debugging shows this test was run right after the flaggable specs. There's a chance these exceptions take place because the test is accessing the database after the browser (chromedriver) process has already accessed the database. This is just an attempt at fixing the issue; I don't know whether these changes will fix it since I've only seen this exception on Github Actions (never on my machine). Worst case scenario, we're encouraging good practices of system tests: test things from the user's point of view. [1] https://github.com/consul/consul/runs/1856245992 --- spec/shared/system/flaggable.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/spec/shared/system/flaggable.rb b/spec/shared/system/flaggable.rb index 81a1f863c..502d1d130 100644 --- a/spec/shared/system/flaggable.rb +++ b/spec/shared/system/flaggable.rb @@ -34,7 +34,12 @@ shared_examples "flaggable" do |factory_name, admin: false| expect(page).not_to have_link "Flag as inappropriate", visible: :all end - expect(Flag.flagged?(user, flaggable)).to be + visit path + + within "##{dom_id(flaggable)} .flag-content" do + expect(page).to have_link "Unflag", visible: :hidden + expect(page).not_to have_link "Flag as inappropriate", visible: :all + end end scenario "Unflagging", :js do @@ -54,7 +59,12 @@ shared_examples "flaggable" do |factory_name, admin: false| expect(page).not_to have_link "Unflag", visible: :all end - expect(Flag.flagged?(user, flaggable)).not_to be + visit path + + within "##{dom_id(flaggable)} .flag-content" do + expect(page).to have_link "Flag as inappropriate", visible: :hidden + expect(page).not_to have_link "Unflag", visible: :all + end end scenario "Flagging and unflagging", :js do @@ -66,7 +76,6 @@ shared_examples "flaggable" do |factory_name, admin: false| click_link "Flag as inappropriate" expect(page).to have_css ".flag-active" - expect(Flag.flagged?(user, flaggable)).to be find(".icon-flag").click click_link "Unflag" @@ -74,7 +83,12 @@ shared_examples "flaggable" do |factory_name, admin: false| expect(page).not_to have_css ".flag-active" end - expect(Flag.flagged?(user, flaggable)).not_to be + visit path + + within "##{dom_id(flaggable)} .flag-content" do + expect(page).to have_link "Flag as inappropriate", visible: :hidden + expect(page).not_to have_link "Unflag", visible: :all + end end scenario "Flagging a comment with a child does not update its children", :js do