Split independent blocks of tests

This way we avoid modifying the database in the middle of a system test
(after we've started the browser), which can lead to database
inconsistencies.

In the case of the reclassification specs we're simply removing part of
the test because that part is already tested by other specs.
This commit is contained in:
Javi Martín
2021-04-10 20:07:41 +02:00
parent 405c6e6d14
commit fc32c767dd
3 changed files with 89 additions and 84 deletions

View File

@@ -15,45 +15,50 @@ describe "Budgets" do
end
end
context "Index" do
scenario "Show normal index with links" do
group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1)
heading2 = create(:budget_heading, group: group2)
describe "Index" do
describe "Normal index" do
let!(:group1) { create(:budget_group, budget: budget) }
let!(:group2) { create(:budget_group, budget: budget) }
let!(:heading1) { create(:budget_heading, group: group1) }
let!(:heading2) { create(:budget_heading, group: group2) }
budget.update!(phase: "informing")
scenario "Show normal index with links in informing phase" do
budget.update!(phase: "informing")
visit budgets_path
visit budgets_path
within(".budget-header") do
expect(page).to have_content(budget.name)
expect(page).to have_content(budget.description)
expect(page).to have_link("Help with participatory budgets")
within(".budget-header") do
expect(page).to have_content(budget.name)
expect(page).to have_content(budget.description)
expect(page).to have_link("Help with participatory budgets")
end
within(".budget-subheader") do
expect(page).to have_content "CURRENT PHASE"
expect(page).to have_content "Information"
end
end
within(".budget-subheader") do
expect(page).to have_content "CURRENT PHASE"
expect(page).to have_content "Information"
scenario "Show normal index with links publishing prices" do
budget.update!(phase: "publishing_prices")
visit budgets_path
within(".budget-subheader") do
expect(page).to have_content("Publishing projects prices")
end
within("#budget_info") do
expect(page).to have_content(group1.name)
expect(page).to have_content(group2.name)
expect(page).to have_content(heading1.name)
expect(page).to have_content(budget.formatted_heading_price(heading1))
expect(page).to have_content(heading2.name)
expect(page).to have_content(budget.formatted_heading_price(heading2))
end
expect(page).not_to have_content("#finished_budgets")
end
budget.update!(phase: "publishing_prices")
visit budgets_path
within(".budget-subheader") do
expect(page).to have_content("Publishing projects prices")
end
within("#budget_info") do
expect(page).to have_content(group1.name)
expect(page).to have_content(group2.name)
expect(page).to have_content(heading1.name)
expect(page).to have_content(budget.formatted_heading_price(heading1))
expect(page).to have_content(heading2.name)
expect(page).to have_content(budget.formatted_heading_price(heading2))
end
expect(page).not_to have_content("#finished_budgets")
end
scenario "Show finished budgets list" do
@@ -316,35 +321,43 @@ describe "Budgets" do
end
context "Show" do
scenario "Links to unfeasible and selected if balloting or later" do
budget = create(:budget, :selecting)
group = create(:budget_group, budget: budget)
let!(:budget) { create(:budget, :selecting) }
let!(:group) { create(:budget_group, budget: budget) }
visit budget_group_path(budget, group)
describe "Links to unfeasible and selected" do
scenario "are not seen before balloting" do
visit budget_group_path(budget, group)
expect(page).not_to have_link "See unfeasible investments"
expect(page).not_to have_link "See investments not selected for balloting phase"
expect(page).not_to have_link "See unfeasible investments"
expect(page).not_to have_link "See investments not selected for balloting phase"
end
budget.update!(phase: :publishing_prices)
scenario "are not seen publishing prices" do
budget.update!(phase: :publishing_prices)
visit budget_group_path(budget, group)
visit budget_group_path(budget, group)
expect(page).not_to have_link "See unfeasible investments"
expect(page).not_to have_link "See investments not selected for balloting phase"
expect(page).not_to have_link "See unfeasible investments"
expect(page).not_to have_link "See investments not selected for balloting phase"
end
budget.update!(phase: :balloting)
scenario "are seen balloting" do
budget.update!(phase: :balloting)
visit budget_group_path(budget, group)
visit budget_group_path(budget, group)
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
end
budget.update!(phase: :finished)
scenario "are seen on finished budgets" do
budget.update!(phase: :finished)
visit budget_group_path(budget, group)
visit budget_group_path(budget, group)
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
expect(page).to have_link "See unfeasible investments"
expect(page).to have_link "See investments not selected for balloting phase"
end
end
scenario "Take into account headings with the same name from a different budget" do

View File

@@ -901,29 +901,26 @@ describe "Budget Investments" do
expect(page).to have_content("This investment project has been selected for balloting phase")
end
scenario "Show (winner budget investment) only if budget is finished" do
budget.update!(phase: "balloting")
describe "winner budget investment text" do
let(:investment) do
create(:budget_investment, :winner, budget: budget, heading: heading)
end
investment = create(:budget_investment,
:feasible,
:finished,
:selected,
:winner,
budget: budget,
heading: heading)
scenario "don't show text if budget is not finished" do
budget.update!(phase: "balloting")
user = create(:user)
login_as(user)
visit budget_investment_path(budget, id: investment.id)
visit budget_investment_path(budget, id: investment.id)
expect(page).not_to have_content("Winning investment project")
end
expect(page).not_to have_content("Winning investment project")
scenario "show text if budget is finished" do
budget.update!(phase: "finished")
budget.update!(phase: "finished")
visit budget_investment_path(budget, id: investment.id)
visit budget_investment_path(budget, id: investment.id)
expect(page).to have_content("Winning investment project")
expect(page).to have_content("Winning investment project")
end
end
scenario "Show (not selected budget investment)" do
@@ -1384,16 +1381,11 @@ describe "Budget Investments" do
user = create(:user, :level_two, ballot_lines: [investment])
heading2 = create(:budget_heading, group: group)
investment.update!(heading: heading2)
login_as(user)
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted one investment")
investment.heading = heading2
investment.save!
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted 0 investment")
end
@@ -1401,17 +1393,11 @@ describe "Budget Investments" do
investment = create(:budget_investment, :selected, heading: heading)
user = create(:user, :level_two, ballot_lines: [investment])
investment.update!(feasibility: "unfeasible", unfeasibility_explanation: "too expensive")
login_as(user)
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted one investment")
investment.feasibility = "unfeasible"
investment.unfeasibility_explanation = "too expensive"
investment.save!
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted 0 investment")
end
end

View File

@@ -1326,7 +1326,6 @@ describe "Proposals" do
{}
scenario "Erased author" do
Setting["feature.featured_proposals"] = true
user = create(:user)
proposal = create(:proposal, author: user)
user.erase
@@ -1336,10 +1335,17 @@ describe "Proposals" do
visit proposal_path(proposal)
expect(page).to have_content("User deleted")
end
scenario "Erased author with featured proposals" do
Setting["feature.featured_proposals"] = true
user = create(:proposal).author
user.erase
create_featured_proposals
visit proposals_path
expect(page).to have_content("User deleted")
end