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:
@@ -229,47 +229,42 @@ describe "Tags" do
|
|||||||
let!(:investment1) { create(:budget_investment, heading: heading, tag_list: new_tag) }
|
let!(:investment1) { create(:budget_investment, heading: heading, tag_list: new_tag) }
|
||||||
let!(:investment2) { 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!(:investment3) { create(:budget_investment, heading: heading, tag_list: newer_tag) }
|
||||||
|
let(:phase) { Budget::Phase::PHASE_KINDS.sample }
|
||||||
|
|
||||||
scenario "Display user tags" do
|
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
|
within "#tag-cloud" do
|
||||||
expect(page).to have_content(new_tag)
|
expect(page).to have_content(new_tag)
|
||||||
expect(page).to have_content(newer_tag)
|
expect(page).to have_content(newer_tag)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Filter by user tags" do
|
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|
|
[investment1, investment2, investment3].each do |investment|
|
||||||
investment.update(selected: true, feasibility: "feasible")
|
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
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -277,47 +272,42 @@ describe "Tags" do
|
|||||||
let!(:investment1) { create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) }
|
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!(: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!(:investment3) { create(:budget_investment, heading: heading, tag_list: tag_economia.name) }
|
||||||
|
let(:phase) { Budget::Phase::PHASE_KINDS.sample }
|
||||||
|
|
||||||
scenario "Display category tags" do
|
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
|
within "#categories" do
|
||||||
expect(page).to have_content(tag_medio_ambiente.name)
|
expect(page).to have_content(tag_medio_ambiente.name)
|
||||||
expect(page).to have_content(tag_economia.name)
|
expect(page).to have_content(tag_economia.name)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Filter by category tags" do
|
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|
|
[investment1, investment2, investment3].each do |investment|
|
||||||
investment.update(selected: true, feasibility: "feasible")
|
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
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user