Skip to content

Commit

Permalink
Compare against literal title in feature specs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
javierm committed Sep 25, 2019
1 parent 876a4fd commit 7ca09df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
26 changes: 13 additions & 13 deletions spec/features/budgets/ballots_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,40 @@
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)

click_link "Districts"
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
Expand Down
8 changes: 4 additions & 4 deletions spec/features/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@
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)

Expand All @@ -470,7 +470,7 @@
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

Expand Down
14 changes: 7 additions & 7 deletions spec/features/debates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,9 @@
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

Expand All @@ -881,7 +881,7 @@

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

Expand Down Expand Up @@ -985,12 +985,12 @@
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

Expand Down
14 changes: 7 additions & 7 deletions spec/features/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,9 @@
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

Expand All @@ -1392,7 +1392,7 @@
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

Expand Down Expand Up @@ -1505,12 +1505,12 @@

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

Expand Down

0 comments on commit 7ca09df

Please sign in to comment.