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.
This commit is contained in:
Javi Martín
2021-04-15 16:53:11 +02:00
parent 42bc8eb4da
commit 8a2e159805

View File

@@ -229,12 +229,11 @@ 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)
login_as(admin) if budget.drafting?
visit budget_investments_path(budget, heading_id: heading.id)
within "#tag-cloud" do
@@ -242,10 +241,8 @@ describe "Tags" do
expect(page).to have_content(newer_tag)
end
end
end
scenario "Filter by user tags" do
Budget::Phase::PHASE_KINDS.each do |phase|
budget.update!(phase: phase)
[investment1, investment2, investment3].each do |investment|
@@ -258,7 +255,6 @@ describe "Tags" do
end
end
login_as(admin) if budget.drafting?
visit budget_investments_path(budget, heading: heading.id)
within "#tag-cloud" do
@@ -271,18 +267,16 @@ describe "Tags" do
expect(page).not_to have_content investment3.title
end
end
end
context "Categories" 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)
login_as(admin) if budget.drafting?
visit budget_investments_path(budget, heading_id: heading.id)
within "#categories" do
@@ -290,10 +284,8 @@ describe "Tags" do
expect(page).to have_content(tag_economia.name)
end
end
end
scenario "Filter by category tags" do
Budget::Phase::PHASE_KINDS.each do |phase|
budget.update!(phase: phase)
[investment1, investment2, investment3].each do |investment|
@@ -306,7 +298,6 @@ describe "Tags" do
end
end
login_as(admin) if budget.drafting?
visit budget_investments_path(budget, heading: heading.id)
within "#categories" do
@@ -319,7 +310,6 @@ describe "Tags" do
expect(page).not_to have_content investment3.title
end
end
end
context "Valuation" do
scenario "Users do not see valuator tags" do