From 0f80dabfe40ba612bb576bb3f5bf6b1477e7b48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 25 Sep 2019 04:43:40 +0200 Subject: [PATCH] Compare against literal title in feature specs We were creating records with a title we manually set, so to be consistent with the rest of the code, in the test we check the title is present using a string literal. This way we can also remove useless assignments while keeping the code vertically aligned. --- spec/features/admin/tags_spec.rb | 27 ++++++++++--------- spec/features/budgets/ballots_spec.rb | 26 +++++++++--------- spec/features/budgets/investments_spec.rb | 20 +++++++------- spec/features/debates_spec.rb | 14 +++++----- spec/features/proposals_spec.rb | 14 +++++----- spec/features/tags/budget_investments_spec.rb | 10 +++---- 6 files changed, 56 insertions(+), 55 deletions(-) diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb index 1363d6842..713c583ce 100644 --- a/spec/features/admin/tags_spec.rb +++ b/spec/features/admin/tags_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "Admin tags" do before do - @tag1 = create(:tag, :category) + create(:tag, :category, name: "Existence") login_as(create(:administrator).user) end @@ -12,7 +12,7 @@ describe "Admin tags" do debate.tag_list.add(create(:tag, :category, name: "supertag")) visit admin_tags_path - expect(page).to have_content @tag1.name + expect(page).to have_content "Existence" expect(page).to have_content "supertag" end @@ -33,38 +33,39 @@ describe "Admin tags" do scenario "Delete" do tag2 = create(:tag, :category, name: "bad tag") - create(:debate, tag_list: tag2.name) + create(:debate, tag_list: "bad tag") + visit admin_tags_path - expect(page).to have_content @tag1.name - expect(page).to have_content tag2.name + expect(page).to have_content "Existence" + expect(page).to have_content "bad tag" within("#tag_#{tag2.id}") do click_link "Delete topic" end visit admin_tags_path - expect(page).to have_content @tag1.name - expect(page).not_to have_content tag2.name + expect(page).to have_content "Existence" + expect(page).not_to have_content "bad tag" end scenario "Delete tag with hidden taggables" do tag2 = create(:tag, :category, name: "bad tag") - debate = create(:debate, tag_list: tag2.name) + debate = create(:debate, tag_list: "bad tag") debate.hide visit admin_tags_path - expect(page).to have_content @tag1.name - expect(page).to have_content tag2.name + expect(page).to have_content "Existence" + expect(page).to have_content "bad tag" within("#tag_#{tag2.id}") do click_link "Delete topic" end visit admin_tags_path - expect(page).to have_content @tag1.name - expect(page).not_to have_content tag2.name + expect(page).to have_content "Existence" + expect(page).not_to have_content "bad tag" end context "Manage only tags of kind category" do @@ -73,7 +74,7 @@ describe "Admin tags" do visit admin_tags_path - expect(page).to have_content @tag1.name + expect(page).to have_content "Existence" expect(page).not_to have_content "Not a category" end diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 41c9cc430..c9207e1f7 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -94,24 +94,24 @@ describe "Ballots" do end scenario "Investments" do - city_heading1 = create(:budget_heading, group: city, name: "Investments Type1") - city_heading2 = create(:budget_heading, group: city, name: "Investments Type2") + 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") - city_investment1 = create(:budget_investment, :selected, heading: city_heading1) - city_investment2 = create(:budget_investment, :selected, heading: city_heading1) - district1_investment1 = create(:budget_investment, :selected, heading: district_heading1) - district1_investment2 = create(:budget_investment, :selected, heading: district_heading1) - district2_investment1 = create(:budget_investment, :selected, heading: district_heading2) + 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") visit budget_path(budget) click_link "City" - click_link "Investments Type1" + click_link "Above the city" expect(page).to have_css(".budget-investment", count: 2) - expect(page).to have_content city_investment1.title - expect(page).to have_content city_investment2.title + expect(page).to have_content "Solar panels" + expect(page).to have_content "Observatory" visit budget_path(budget) @@ -119,15 +119,15 @@ describe "Ballots" do click_link "District 1" expect(page).to have_css(".budget-investment", count: 2) - expect(page).to have_content district1_investment1.title - expect(page).to have_content district1_investment2.title + expect(page).to have_content "New park" + expect(page).to have_content "Zero-emission zone" visit budget_path(budget) click_link "Districts" click_link "District 2" expect(page).to have_css(".budget-investment", count: 1) - expect(page).to have_content district2_investment1.title + expect(page).to have_content "Climbing wall" end scenario "Redirect to first heading if there is only one" do diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index de6607e02..ec0c2da29 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -454,9 +454,9 @@ describe "Budget Investments" do ana = create :user, official_level: 1 john = create :user, official_level: 1 - bdgt_invest1 = create(:budget_investment, heading: heading, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) - bdgt_invest2 = create(:budget_investment, heading: heading, title: "Hello Schwifty", author: john, created_at: 2.days.ago) - bdgt_invest3 = create(:budget_investment, heading: heading, title: "Save the forest") + create(:budget_investment, heading: heading, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) + create(:budget_investment, heading: heading, title: "Hello Schwifty", author: john, created_at: 2.days.ago) + create(:budget_investment, heading: heading, title: "Save the forest") visit budget_investments_path(budget) @@ -470,7 +470,7 @@ describe "Budget Investments" do expect(page).to have_content("There is 1 investment") within("#budget-investments") do - expect(page).to have_content(bdgt_invest1.title) + expect(page).to have_content "Get Schwifty" end end @@ -1336,13 +1336,13 @@ describe "Budget Investments" do carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) - carabanchel_investment = create(:budget_investment, :selected, heading: carabanchel) - salamanca_investment = create(:budget_investment, :selected, heading: salamanca) + create(:budget_investment, :selected, title: "In Carabanchel", heading: carabanchel) + create(:budget_investment, :selected, title: "In Salamanca", heading: salamanca) login_as(author) visit budget_investments_path(budget, heading_id: carabanchel.id) - within("#budget_investment_#{carabanchel_investment.id}") do + within(".budget-investment", text: "In Carabanchel") do expect(page).to have_css(".in-favor a[data-confirm]") end end @@ -1351,13 +1351,13 @@ describe "Budget Investments" do carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) - carabanchel_investment = create(:budget_investment, heading: carabanchel, voters: [author]) - salamanca_investment = create(:budget_investment, heading: salamanca) + create(:budget_investment, title: "In Carabanchel", heading: carabanchel, voters: [author]) + create(:budget_investment, title: "In Salamanca", heading: salamanca) login_as(author) visit budget_investments_path(budget, heading_id: carabanchel.id) - within("#budget_investment_#{carabanchel_investment.id}") do + within(".budget-investment", text: "In Carabanchel") do expect(page).not_to have_css(".in-favor a[data-confirm]") end end diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index a8723b7d9..6478e3cbf 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -860,9 +860,9 @@ describe "Debates" do ana = create :user, official_level: 1 john = create :user, official_level: 1 - debate1 = create(:debate, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) - debate2 = create(:debate, title: "Hello Schwifty", author: john, created_at: 2.days.ago) - debate3 = create(:debate, title: "Save the forest") + create(:debate, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) + create(:debate, title: "Hello Schwifty", author: john, created_at: 2.days.ago) + create(:debate, title: "Save the forest") visit debates_path @@ -875,7 +875,7 @@ describe "Debates" do within("#debates") do expect(page).to have_css(".debate", count: 1) - expect(page).to have_content(debate1.title) + expect(page).to have_content "Get Schwifty" end end @@ -978,12 +978,12 @@ describe "Debates" do end scenario "After a search do not show featured debates" do - featured_debates = create_featured_debates - debate = create(:debate, title: "Abcdefghi") + create_featured_debates + create(:debate, title: "Abcdefghi") visit debates_path within(".expanded #search_form") do - fill_in "search", with: debate.title + fill_in "search", with: "Abcdefghi" click_button "Search" end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 148afd66b..8ac6a5bc2 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1370,9 +1370,9 @@ describe "Proposals" do ana = create :user, official_level: 1 john = create :user, official_level: 1 - proposal1 = create(:proposal, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) - proposal2 = create(:proposal, title: "Hello Schwifty", author: john, created_at: 2.days.ago) - proposal3 = create(:proposal, title: "Save the forest") + create(:proposal, title: "Get Schwifty", author: ana, created_at: 1.minute.ago) + create(:proposal, title: "Hello Schwifty", author: john, created_at: 2.days.ago) + create(:proposal, title: "Save the forest") visit proposals_path @@ -1386,7 +1386,7 @@ describe "Proposals" do expect(page).to have_content("There is 1 citizen proposal") within("#proposals") do - expect(page).to have_content(proposal1.title) + expect(page).to have_content "Get Schwifty" end end @@ -1498,12 +1498,12 @@ describe "Proposals" do scenario "After a search do not show featured proposals" do Setting["feature.featured_proposals"] = true - featured_proposals = create_featured_proposals - proposal = create(:proposal, title: "Abcdefghi") + create_featured_proposals + create(:proposal, title: "Abcdefghi") visit proposals_path within(".expanded #search_form") do - fill_in "search", with: proposal.title + fill_in "search", with: "Abcdefghi" click_button "Search" end diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index 0a9fcb8ae..e48926fe4 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -206,16 +206,16 @@ describe "Tags" do end scenario "From show" do - investment1 = create(:budget_investment, heading: heading, tag_list: tag_economia.name) - investment2 = create(:budget_investment, heading: heading, tag_list: "Health") + investment = create(:budget_investment, heading: heading, tag_list: "Economy", title: "New bank") + create(:budget_investment, heading: heading, tag_list: "Health", title: "New hospital") - visit budget_investment_path(budget, investment1) + visit budget_investment_path(budget, investment) - click_link tag_economia.name + click_link "Economy" within("#budget-investments") do expect(page).to have_css(".budget-investment", count: 1) - expect(page).to have_content(investment1.title) + expect(page).to have_content "New bank" end end