Query the database before visiting a page in tests
We can assign query results to variables and so we avoid querying the database after starting the browser.
This commit is contained in:
@@ -3,6 +3,7 @@ shared_examples "relationable" do |relationable_model_name|
|
||||
let(:related1) { create([:proposal, :debate, :budget_investment].sample) }
|
||||
let(:related2) { create([:proposal, :debate, :budget_investment].sample) }
|
||||
let(:user) { create(:user) }
|
||||
let!(:url) { Setting["url"] }
|
||||
|
||||
scenario "related contents are listed" do
|
||||
create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
||||
@@ -32,7 +33,7 @@ shared_examples "relationable" do |relationable_model_name|
|
||||
click_on("Add related content")
|
||||
|
||||
within("#related_content") do
|
||||
fill_in "url", with: "#{Setting["url"] + related1.url}"
|
||||
fill_in "url", with: "#{url + related1.url}"
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
@@ -49,7 +50,7 @@ shared_examples "relationable" do |relationable_model_name|
|
||||
click_on("Add related content")
|
||||
|
||||
within("#related_content") do
|
||||
fill_in "url", with: "#{Setting["url"] + related2.url}"
|
||||
fill_in "url", with: "#{url + related2.url}"
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
@@ -69,7 +70,7 @@ shared_examples "relationable" do |relationable_model_name|
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
expect(page).to have_content("Link not valid. Remember to start with #{Setting[:url]}.")
|
||||
expect(page).to have_content("Link not valid. Remember to start with #{url}.")
|
||||
end
|
||||
|
||||
scenario "returns error when relating content URL to itself" do
|
||||
@@ -79,7 +80,7 @@ shared_examples "relationable" do |relationable_model_name|
|
||||
click_on("Add related content")
|
||||
|
||||
within("#related_content") do
|
||||
fill_in "url", with: Setting[:url] + relationable.url.to_s
|
||||
fill_in "url", with: url + relationable.url.to_s
|
||||
click_button "Add"
|
||||
end
|
||||
|
||||
|
||||
@@ -17,12 +17,13 @@ describe "Documents", :admin do
|
||||
3.times { create(:document, :admin) }
|
||||
1.times { create(:document) }
|
||||
|
||||
document = Document.first
|
||||
attachment = document.attachment
|
||||
|
||||
visit admin_site_customization_documents_path
|
||||
|
||||
expect(page).to have_content "There are 3 documents"
|
||||
|
||||
document = Document.first
|
||||
expect(page).to have_link document.title, href: document.attachment.url
|
||||
expect(page).to have_link document.title, href: attachment.url
|
||||
end
|
||||
|
||||
scenario "Index (empty)" do
|
||||
|
||||
@@ -411,10 +411,12 @@ describe "Stats", :admin do
|
||||
end
|
||||
|
||||
scenario "Renders all goals stats" do
|
||||
goals_count = SDG::Goal.count
|
||||
|
||||
visit sdg_admin_stats_path
|
||||
|
||||
expect(page).to have_css "h3", count: SDG::Goal.count
|
||||
expect(page).to have_css ".sdg-goal-stats", count: SDG::Goal.count
|
||||
expect(page).to have_css "h3", count: goals_count
|
||||
expect(page).to have_css ".sdg-goal-stats", count: goals_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,13 +4,12 @@ describe "Admin Budgets", :admin do
|
||||
context "Index" do
|
||||
scenario "Create poll if the budget does not have a poll associated" do
|
||||
budget = create(:budget)
|
||||
balloting_phase = budget.phases.balloting
|
||||
|
||||
visit admin_budgets_path
|
||||
|
||||
click_link "Admin ballots"
|
||||
|
||||
balloting_phase = budget.phases.find_by(kind: "balloting")
|
||||
|
||||
expect(page).to have_current_path(/admin\/polls\/\d+/)
|
||||
expect(page).to have_content(budget.name)
|
||||
expect(page).to have_content(balloting_phase.starts_at.to_date)
|
||||
|
||||
@@ -325,13 +325,14 @@ describe "Budget Investments" do
|
||||
|
||||
scenario "Random order maintained when going back from show" do
|
||||
per_page.times { create(:budget_investment, heading: heading) }
|
||||
first_investment = Budget::Investment.first
|
||||
|
||||
visit budget_investments_path(budget, heading_id: heading.id)
|
||||
|
||||
order = all(".budget-investment h3").map(&:text)
|
||||
expect(order).not_to be_empty
|
||||
|
||||
click_link Budget::Investment.first.title
|
||||
click_link first_investment.title
|
||||
click_link "Go back"
|
||||
|
||||
new_order = all(".budget-investment h3").map(&:text)
|
||||
@@ -742,16 +743,17 @@ describe "Budget Investments" do
|
||||
scenario "Price & explanation is shown when Budget is on published prices phase" do
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update!(phase: phase)
|
||||
|
||||
if budget.finished?
|
||||
investment.update!(winner: true)
|
||||
end
|
||||
|
||||
visit budget_investment_path(budget, id: investment.id)
|
||||
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
expect(page).to have_content(investment.price_explanation)
|
||||
expect(page).to have_link("See price explanation")
|
||||
|
||||
if budget.finished?
|
||||
investment.update(winner: true)
|
||||
end
|
||||
|
||||
visit budget_investments_path(budget)
|
||||
|
||||
expect(page).to have_content(investment.formatted_price)
|
||||
|
||||
@@ -125,16 +125,20 @@ describe "Officing Results", :with_frozen_time do
|
||||
end
|
||||
|
||||
scenario "Index lists all questions and answers" do
|
||||
officer_assignment = poll_officer.officer_assignments.first
|
||||
booth_assignment = officer_assignment.booth_assignment
|
||||
booth = booth_assignment.booth
|
||||
|
||||
create(:poll_partial_result,
|
||||
officer_assignment: poll_officer.officer_assignments.first,
|
||||
booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
|
||||
officer_assignment: officer_assignment,
|
||||
booth_assignment: booth_assignment,
|
||||
date: poll.ends_at,
|
||||
question: question_1,
|
||||
amount: 33)
|
||||
|
||||
create(:poll_recount,
|
||||
officer_assignment: poll_officer.officer_assignments.first,
|
||||
booth_assignment: poll_officer.officer_assignments.first.booth_assignment,
|
||||
officer_assignment: officer_assignment,
|
||||
booth_assignment: booth_assignment,
|
||||
date: poll.ends_at,
|
||||
white_amount: 21,
|
||||
null_amount: 44,
|
||||
@@ -142,10 +146,10 @@ describe "Officing Results", :with_frozen_time do
|
||||
|
||||
visit officing_poll_results_path(poll,
|
||||
date: I18n.l(poll.ends_at.to_date),
|
||||
booth_assignment_id: poll_officer.officer_assignments.first.booth_assignment_id)
|
||||
booth_assignment_id: officer_assignment.booth_assignment_id)
|
||||
|
||||
expect(page).to have_content(I18n.l(poll.ends_at.to_date, format: :long))
|
||||
expect(page).to have_content(poll_officer.officer_assignments.first.booth_assignment.booth.name)
|
||||
expect(page).to have_content(booth.name)
|
||||
|
||||
expect(page).to have_content(question_1.title)
|
||||
question_1.question_answers.each_with_index do |answer, i|
|
||||
|
||||
Reference in New Issue
Block a user