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.
This commit is contained in:
Javi Martín
2019-09-25 04:43:40 +02:00
parent 0fe0d8e57c
commit 0f80dabfe4
6 changed files with 56 additions and 55 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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