From f5fe8c1279e739fbeef685e39c12a176cb0b728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 27 Sep 2019 20:41:47 +0200 Subject: [PATCH] Use factory bot blocks to create complex data We had four headings, some of them had investments, and some of them didn't, and it was very hard to scan the code and check which investment belongs to which heading. Grouping the investments inside the block creating the heading makes that task much easier, even if the code is still not 100% readable. We also avoid unused variables which were there to keep the code vertically algined. --- spec/features/budgets/ballots_spec.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index c9207e1f7..9d8e088ef 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -94,16 +94,21 @@ describe "Ballots" do end scenario "Investments" do - city_heading1 = create(:budget_heading, group: city, name: "Above the city") - city_heading2 = create(:budget_heading, group: city, name: "Under the city") - district_heading1 = create(:budget_heading, group: districts, name: "District 1") - district_heading2 = create(:budget_heading, group: districts, name: "District 2") + create(:budget_heading, group: city, name: "Under the city") - create(:budget_investment, :selected, heading: city_heading1, title: "Solar panels") - create(:budget_investment, :selected, heading: city_heading1, title: "Observatory") - create(:budget_investment, :selected, heading: district_heading1, title: "New park") - create(:budget_investment, :selected, heading: district_heading1, title: "Zero-emission zone") - create(:budget_investment, :selected, heading: district_heading2, title: "Climbing wall") + create(:budget_heading, group: city, name: "Above the city") do |heading| + create(:budget_investment, :selected, heading: heading, title: "Solar panels") + create(:budget_investment, :selected, heading: heading, title: "Observatory") + end + + create(:budget_heading, group: districts, name: "District 1") do |heading| + create(:budget_investment, :selected, heading: heading, title: "New park") + create(:budget_investment, :selected, heading: heading, title: "Zero-emission zone") + end + + create(:budget_heading, group: districts, name: "District 2") do |heading| + create(:budget_investment, :selected, heading: heading, title: "Climbing wall") + end visit budget_path(budget) click_link "City"