From 42bfd2fce283b1cdc4c288cf37eef82836c408cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 30 Mar 2025 20:20:43 +0200 Subject: [PATCH 1/2] Add missing expectations in hidden content tests We were checking that we still were on the same page, which was true even before finishing the request to restore the content. --- spec/system/admin/hidden_budget_investments_spec.rb | 3 +++ spec/system/admin/hidden_comments_spec.rb | 3 +++ spec/system/admin/hidden_debates_spec.rb | 3 +++ spec/system/admin/hidden_proposals_spec.rb | 3 +++ spec/system/admin/hidden_users_spec.rb | 3 +++ spec/system/admin/proposal_notifications_spec.rb | 3 +++ 6 files changed, 18 insertions(+) diff --git a/spec/system/admin/hidden_budget_investments_spec.rb b/spec/system/admin/hidden_budget_investments_spec.rb index 9f3f20bfe..f3dfaaab5 100644 --- a/spec/system/admin/hidden_budget_investments_spec.rb +++ b/spec/system/admin/hidden_budget_investments_spec.rb @@ -81,8 +81,11 @@ describe "Admin hidden budget investments", :admin do visit admin_hidden_budget_investments_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm { click_button "Restore", match: :first, exact: true } + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end diff --git a/spec/system/admin/hidden_comments_spec.rb b/spec/system/admin/hidden_comments_spec.rb index 7f86f1bf1..3408088ed 100644 --- a/spec/system/admin/hidden_comments_spec.rb +++ b/spec/system/admin/hidden_comments_spec.rb @@ -130,8 +130,11 @@ describe "Admin hidden comments", :admin do visit admin_hidden_comments_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm("Are you sure? Restore") { click_button "Restore", match: :first, exact: true } + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end diff --git a/spec/system/admin/hidden_debates_spec.rb b/spec/system/admin/hidden_debates_spec.rb index 5b588e522..91ac557a1 100644 --- a/spec/system/admin/hidden_debates_spec.rb +++ b/spec/system/admin/hidden_debates_spec.rb @@ -70,8 +70,11 @@ describe "Admin hidden debates", :admin do visit admin_hidden_debates_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm("Are you sure? Restore") { click_button "Restore", match: :first, exact: true } + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end diff --git a/spec/system/admin/hidden_proposals_spec.rb b/spec/system/admin/hidden_proposals_spec.rb index 57d4807c2..1ecca8611 100644 --- a/spec/system/admin/hidden_proposals_spec.rb +++ b/spec/system/admin/hidden_proposals_spec.rb @@ -83,8 +83,11 @@ describe "Admin hidden proposals", :admin do visit admin_hidden_proposals_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm("Are you sure? Restore") { click_button "Restore", match: :first, exact: true } + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end diff --git a/spec/system/admin/hidden_users_spec.rb b/spec/system/admin/hidden_users_spec.rb index 4fb320a6f..ce831f750 100644 --- a/spec/system/admin/hidden_users_spec.rb +++ b/spec/system/admin/hidden_users_spec.rb @@ -85,10 +85,13 @@ describe "Admin hidden users", :admin do visit admin_hidden_users_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm("Are you sure? Restore \"#{users[-3].name}\"") do click_button "Restore", match: :first, exact: true end + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end diff --git a/spec/system/admin/proposal_notifications_spec.rb b/spec/system/admin/proposal_notifications_spec.rb index 02f85e28e..add35e643 100644 --- a/spec/system/admin/proposal_notifications_spec.rb +++ b/spec/system/admin/proposal_notifications_spec.rb @@ -80,8 +80,11 @@ describe "Admin proposal notifications", :admin do visit admin_hidden_proposal_notifications_path(filter: "with_confirmed_hide", page: 2) + expect(page).to have_css "tbody tr", count: 2 + accept_confirm("Are you sure? Restore") { click_button "Restore", match: :first, exact: true } + expect(page).to have_css "tbody tr", count: 1 expect(page).to have_current_path(/filter=with_confirmed_hide/) expect(page).to have_current_path(/page=2/) end From 4b3f58cf4c233612db1ae7057fc719235e56b855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 2 Apr 2025 14:09:33 +0200 Subject: [PATCH 2/2] Don't create content after a visit in notifications test We forgot to apply this change in commit f5f96ba86. Note that, in this case, executing `proposal_notification.author.email` in the middle of a test would also result in a database query. For some reason (probably the same reason why the code that explicitly created the author was added in this test but not in other moderation tests), that doesn't seem to happen in other moderation tests, so for now we aren't changing those ones. --- spec/system/moderation/proposal_notifications_spec.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/spec/system/moderation/proposal_notifications_spec.rb b/spec/system/moderation/proposal_notifications_spec.rb index ccbff02c0..05920145a 100644 --- a/spec/system/moderation/proposal_notifications_spec.rb +++ b/spec/system/moderation/proposal_notifications_spec.rb @@ -52,6 +52,7 @@ describe "Moderate proposal notifications" do describe "moderate in bulk" do describe "When a proposal has been selected for moderation" do let!(:proposal_notification) { create(:proposal_notification, created_at: Date.current - 4.days) } + let!(:email) { proposal_notification.author.email } before do visit moderation_proposal_notifications_path @@ -66,7 +67,7 @@ describe "Moderate proposal notifications" do expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}") click_link "Block users" - fill_in "email or name of user", with: proposal_notification.author.email + fill_in "email or name of user", with: email click_button "Search" within "tr", text: proposal_notification.author.name do @@ -75,15 +76,12 @@ describe "Moderate proposal notifications" do end scenario "Block the author" do - author = create(:user) - proposal_notification.update!(author: author) - accept_confirm("Are you sure? Block authors") { click_button "Block authors" } expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}") click_link "Block users" - fill_in "email or name of user", with: proposal_notification.author.email + fill_in "email or name of user", with: email click_button "Search" within "tr", text: proposal_notification.author.name do