From 8a2e1598056c410bc616fa4767a68cfc80cdda38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Apr 2021 16:53:11 +0200 Subject: [PATCH] Simplify tests for investments tag cloud It's true that previously we didn't display the tag cloud on all phases and so we added a test checking we did on all phases. However, doing so makes tests really slow and prone to database inconsistencies because the alter the database after the process running the browser has started. So now we're using a random phase in these tests to solve this issue. We're also removing the `login_as(admin) if budget.drafting?` line because we removed the drafting phase in commit 28caabecd. --- spec/system/tags/budget_investments_spec.rb | 114 +++++++++----------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/spec/system/tags/budget_investments_spec.rb b/spec/system/tags/budget_investments_spec.rb index 1eb6f3744..9f5f38284 100644 --- a/spec/system/tags/budget_investments_spec.rb +++ b/spec/system/tags/budget_investments_spec.rb @@ -229,47 +229,42 @@ describe "Tags" do let!(:investment1) { create(:budget_investment, heading: heading, tag_list: new_tag) } let!(:investment2) { create(:budget_investment, heading: heading, tag_list: new_tag) } let!(:investment3) { create(:budget_investment, heading: heading, tag_list: newer_tag) } + let(:phase) { Budget::Phase::PHASE_KINDS.sample } scenario "Display user tags" do - Budget::Phase::PHASE_KINDS.each do |phase| - budget.update!(phase: phase) + budget.update!(phase: phase) - login_as(admin) if budget.drafting? - visit budget_investments_path(budget, heading_id: heading.id) + visit budget_investments_path(budget, heading_id: heading.id) - within "#tag-cloud" do - expect(page).to have_content(new_tag) - expect(page).to have_content(newer_tag) - end + within "#tag-cloud" do + expect(page).to have_content(new_tag) + expect(page).to have_content(newer_tag) end end scenario "Filter by user tags" do - Budget::Phase::PHASE_KINDS.each do |phase| - budget.update!(phase: phase) + budget.update!(phase: phase) - [investment1, investment2, investment3].each do |investment| - investment.update(selected: true, feasibility: "feasible") - end - - if budget.finished? - [investment1, investment2, investment3].each do |investment| - investment.update(selected: true, feasibility: "feasible", winner: true) - end - end - - login_as(admin) if budget.drafting? - visit budget_investments_path(budget, heading: heading.id) - - within "#tag-cloud" do - click_link new_tag - end - - expect(page).to have_css ".budget-investment", count: 2 - expect(page).to have_content investment1.title - expect(page).to have_content investment2.title - expect(page).not_to have_content investment3.title + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true, feasibility: "feasible") end + + if budget.finished? + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true, feasibility: "feasible", winner: true) + end + end + + visit budget_investments_path(budget, heading: heading.id) + + within "#tag-cloud" do + click_link new_tag + end + + expect(page).to have_css ".budget-investment", count: 2 + expect(page).to have_content investment1.title + expect(page).to have_content investment2.title + expect(page).not_to have_content investment3.title end end @@ -277,47 +272,42 @@ describe "Tags" do let!(:investment1) { create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) } let!(:investment2) { create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) } let!(:investment3) { create(:budget_investment, heading: heading, tag_list: tag_economia.name) } + let(:phase) { Budget::Phase::PHASE_KINDS.sample } scenario "Display category tags" do - Budget::Phase::PHASE_KINDS.each do |phase| - budget.update!(phase: phase) + budget.update!(phase: phase) - login_as(admin) if budget.drafting? - visit budget_investments_path(budget, heading_id: heading.id) + visit budget_investments_path(budget, heading_id: heading.id) - within "#categories" do - expect(page).to have_content(tag_medio_ambiente.name) - expect(page).to have_content(tag_economia.name) - end + within "#categories" do + expect(page).to have_content(tag_medio_ambiente.name) + expect(page).to have_content(tag_economia.name) end end scenario "Filter by category tags" do - Budget::Phase::PHASE_KINDS.each do |phase| - budget.update!(phase: phase) + budget.update!(phase: phase) - [investment1, investment2, investment3].each do |investment| - investment.update(selected: true, feasibility: "feasible") - end - - if budget.finished? - [investment1, investment2, investment3].each do |investment| - investment.update(selected: true, feasibility: "feasible", winner: true) - end - end - - login_as(admin) if budget.drafting? - visit budget_investments_path(budget, heading: heading.id) - - within "#categories" do - click_link tag_medio_ambiente.name - end - - expect(page).to have_css ".budget-investment", count: 2 - expect(page).to have_content investment1.title - expect(page).to have_content investment2.title - expect(page).not_to have_content investment3.title + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true, feasibility: "feasible") end + + if budget.finished? + [investment1, investment2, investment3].each do |investment| + investment.update(selected: true, feasibility: "feasible", winner: true) + end + end + + visit budget_investments_path(budget, heading: heading.id) + + within "#categories" do + click_link tag_medio_ambiente.name + end + + expect(page).to have_css ".budget-investment", count: 2 + expect(page).to have_content investment1.title + expect(page).to have_content investment2.title + expect(page).not_to have_content investment3.title end end