Sign in manager after setting up test data

We've got quite a messy hack to sign in managers: they need to visit a
specific URL (management root path).

That means tests signing in managers start the browser to sign them in,
which might cause issues if we setup the database after that.
This commit is contained in:
Javi Martín
2021-04-02 15:20:09 +02:00
parent efbb3bb690
commit 03d0ffd89e
9 changed files with 61 additions and 48 deletions

View File

@@ -282,12 +282,12 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_show_path}" do
before do
set_arguments(arguments, mappable, mappable_path_arguments)
do_login_for(user) if management
end
scenario "Should display map and marker on #{mappable_factory_name} show page" do
arguments[:id] = mappable.id
do_login_for(user) if management
visit send(mappable_show_path, arguments)
within ".map_location" do
@@ -300,6 +300,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
set_arguments(arguments, mappable_without_map, mappable_path_arguments)
arguments[:id] = mappable_without_map.id
do_login_for(user) if management
visit send(mappable_show_path, arguments)
expect(page).not_to have_css(".map_location")
@@ -309,6 +310,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
Setting["feature.map"] = false
arguments[:id] = mappable.id
do_login_for(user) if management
visit send(mappable_show_path, arguments)
expect(page).not_to have_css(".map_location")
@@ -318,8 +320,8 @@ end
def do_login_for(user)
if management
login_as_manager
login_managed_user(user)
login_as_manager
else
login_as(user)
end

View File

@@ -1,16 +1,11 @@
require "rails_helper"
describe "Account" do
before do
login_as_manager
end
scenario "Should not allow unverified users to edit their account" do
user = create(:user)
login_managed_user(user)
visit management_root_path
login_as_manager
click_link "Reset password via email"
expect(page).to have_content "No verified user logged in yet"
@@ -20,6 +15,7 @@ describe "Account" do
user = create(:user, :level_two)
login_managed_user(user)
login_as_manager
visit management_account_path
click_link "Delete user"
@@ -33,8 +29,8 @@ describe "Account" do
scenario "Send reset password email to currently managed user session" do
user = create(:user, :level_three)
login_managed_user(user)
visit management_root_path
login_as_manager
click_link "Reset password via email"
click_link "Send reset password email"
@@ -49,8 +45,8 @@ describe "Account" do
scenario "Manager changes the password by hand (writen by them)" do
user = create(:user, :level_three)
login_managed_user(user)
visit management_root_path
login_as_manager
click_link "Reset password manually"
find(:css, "input[id$='user_password']").set("new_password")
@@ -69,8 +65,8 @@ describe "Account" do
scenario "Manager generates random password" do
user = create(:user, :level_three)
login_managed_user(user)
visit management_root_path
login_as_manager
click_link "Reset password manually"
click_link "Generate random password"
@@ -90,8 +86,8 @@ describe "Account" do
scenario "The password is printed" do
user = create(:user, :level_three)
login_managed_user(user)
visit management_root_path
login_as_manager
click_link "Reset password manually"
find(:css, "input[id$='user_password']").set("another_new_password")

View File

@@ -7,10 +7,7 @@ describe "Budget Investments" do
let(:heading) { create(:budget_heading, group: group, name: "Health") }
let(:user) { create(:user, :level_two) }
before do
login_managed_user(user)
login_as_manager(manager)
end
before { login_managed_user(user) }
it_behaves_like "mappable",
"budget_investment",
@@ -25,6 +22,7 @@ describe "Budget Investments" do
let(:investment) { create(:budget_investment, budget: budget) }
scenario "finds investment using budget slug" do
login_as_manager(manager)
visit management_budget_investment_path("budget_slug", investment)
expect(page).to have_content investment.title
@@ -35,6 +33,7 @@ describe "Budget Investments" do
before { heading.budget.update(phase: "accepting") }
scenario "Creating budget investments on behalf of someone, selecting a budget" do
login_as_manager(manager)
click_link "Create budget investment"
within "#budget_#{budget.id}" do
click_link "Create budget investment"
@@ -71,6 +70,7 @@ describe "Budget Investments" do
scenario "Should not allow unverified users to create budget investments" do
login_managed_user(create(:user))
login_as_manager(manager)
click_link "Create budget investment"
expect(page).to have_content "User is not verified"
@@ -83,6 +83,7 @@ describe "Budget Investments" do
create(:budget_investment, budget: budget, title: "No more parks")
create(:budget_investment, budget: budget, title: "Plant trees")
login_as_manager(manager)
click_link "Create budget investment"
within "#budget_#{budget.id}" do
click_link "Create budget investment"
@@ -104,6 +105,7 @@ describe "Budget Investments" do
budget_investment1 = create(:budget_investment, budget: budget, title: "Show me what you got")
budget_investment2 = create(:budget_investment, budget: budget, title: "Get Schwifty")
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content(budget.name)
within "#budget_#{budget.id}" do
@@ -129,6 +131,7 @@ describe "Budget Investments" do
budget_investment2 = create(:budget_investment, budget: budget, title: "Let's go",
heading: create(:budget_heading, name: "Area 52"))
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content(budget.name)
within "#budget_#{budget.id}" do
@@ -153,6 +156,7 @@ describe "Budget Investments" do
budget_investment1 = create(:budget_investment, budget: budget, title: "Show me what you got")
budget_investment2 = create(:budget_investment, budget: budget, title: "Get Schwifty")
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content(budget.name)
within "#budget_#{budget.id}" do
@@ -186,6 +190,7 @@ describe "Budget Investments" do
reviewing_ballots_budget = create(:budget, :reviewing_ballots)
finished = create(:budget, :finished)
login_as_manager(manager)
click_link "Create budget investment"
expect(page).to have_content(accepting_budget.name)
@@ -207,11 +212,7 @@ describe "Budget Investments" do
reviewing_ballots_budget = create(:budget, :reviewing_ballots)
finished = create(:budget, :finished)
visit root_path
click_link "Sign out"
admin = create(:administrator)
login_as(admin.user)
login_as(create(:administrator).user)
visit management_sign_in_path
@@ -231,6 +232,7 @@ describe "Budget Investments" do
scenario "Supporting budget investments on behalf of someone in index view" do
budget_investment = create(:budget_investment, heading: heading)
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content(budget.name)
within "#budget_#{budget.id}" do
@@ -250,6 +252,7 @@ describe "Budget Investments" do
xscenario "Supporting budget investments on behalf of someone in show view" do
budget_investment = create(:budget_investment, budget: budget)
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content(budget.name)
within "#budget_#{budget.id}" do
@@ -269,6 +272,7 @@ describe "Budget Investments" do
login_managed_user(create(:user))
create(:budget_investment, budget: budget)
login_as_manager(manager)
click_link "Support budget investments"
expect(page).to have_content "User is not verified"
@@ -279,6 +283,7 @@ describe "Budget Investments" do
scenario "Printing budget investments" do
16.times { create(:budget_investment, heading: heading) }
login_as_manager(manager)
click_link "Print budget investments"
expect(page).to have_content(budget.name)
@@ -295,6 +300,7 @@ describe "Budget Investments" do
voted_investment = create(:budget_investment, :selected, heading: heading, balloters: [create(:user)])
login_as_manager(manager)
click_link "Print budget investments"
within "#budget_#{budget.id}" do
@@ -328,6 +334,7 @@ describe "Budget Investments" do
heading: another_heading,
title: "Add new districts to the city")
login_as_manager(manager)
click_link "Print budget investments"
expect(page).to have_content(budget.name)

View File

@@ -1,13 +1,10 @@
require "rails_helper"
describe "DocumentVerifications" do
before do
login_as_manager
end
scenario "Verifying a level 3 user shows an 'already verified' page" do
user = create(:user, :level_three)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: user.document_number
click_button "Check document"
@@ -18,6 +15,7 @@ describe "DocumentVerifications" do
scenario "Verifying a level 2 user displays the verification form" do
user = create(:user, :level_two)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: user.document_number
click_button "Check document"
@@ -37,6 +35,7 @@ describe "DocumentVerifications" do
expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).
and_return(false)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "inexisting"
click_button "Check document"
@@ -45,6 +44,7 @@ describe "DocumentVerifications" do
end
scenario "Verifying a user which does exists in the census but not in the db redirects allows sending an email" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"
@@ -58,6 +58,7 @@ describe "DocumentVerifications" do
expect_any_instance_of(Verification::Management::Document).to receive(:in_census?).
and_return(false)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
@@ -71,6 +72,7 @@ describe "DocumentVerifications" do
redirects allows sending an email" do
mock_valid_remote_census_response
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
select_date "31-December-1980", from: "document_verification_date_of_birth"
@@ -83,6 +85,7 @@ describe "DocumentVerifications" do
end
scenario "Document number is format-standarized" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345 - h"
click_button "Check document"
@@ -93,6 +96,7 @@ describe "DocumentVerifications" do
scenario "User age is checked" do
expect_any_instance_of(Verification::Management::Document).to receive(:under_age?).and_return(true)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"

View File

@@ -1,11 +1,8 @@
require "rails_helper"
describe "Localization" do
before do
login_as_manager
end
scenario "Wrong locale" do
login_as_manager
visit management_root_path(locale: :es)
visit management_root_path(locale: :klingon)
@@ -13,7 +10,7 @@ describe "Localization" do
end
scenario "Available locales appear in the locale switcher" do
visit management_root_path
login_as_manager
within(".locale-form .js-location-changer") do
expect(page).to have_content "Español"
@@ -22,13 +19,13 @@ describe "Localization" do
end
scenario "The current locale is selected" do
visit management_root_path
login_as_manager
expect(page).to have_select("locale-switcher", selected: "English")
expect(page).to have_text("Management")
end
scenario "Changing the locale" do
visit management_root_path
login_as_manager
expect(page).to have_content("Language")
select("Español", from: "locale-switcher")
@@ -40,7 +37,7 @@ describe "Localization" do
scenario "Locale switcher not present if only one locale" do
allow(I18n).to receive(:available_locales).and_return([:en])
visit management_root_path
login_as_manager
expect(page).not_to have_content("Language")
expect(page).not_to have_css("div.locale")
end

View File

@@ -1,12 +1,9 @@
require "rails_helper"
describe "Managed User" do
before do
login_as_manager
end
context "Currently managed user" do
scenario "No managed user" do
login_as_manager
visit management_document_verifications_path
expect(page).not_to have_css ".account-info"
end
@@ -14,6 +11,7 @@ describe "Managed User" do
scenario "User is already level three verified" do
user = create(:user, :level_three)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: user.document_number
click_button "Check document"
@@ -31,6 +29,7 @@ describe "Managed User" do
scenario "User becomes verified as level three" do
user = create(:user, :level_two)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: user.document_number
click_button "Check document"
@@ -50,10 +49,9 @@ describe "Managed User" do
end
scenario "User becomes verified as level two (pending email confirmation for level three)" do
login_as_manager
user = create(:user)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"
@@ -141,6 +139,7 @@ describe "Managed User" do
scenario "Close the currently managed user session" do
user = create(:user, :level_three)
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: user.document_number
click_button "Check document"

View File

@@ -5,11 +5,11 @@ describe "Proposals" do
before do
login_managed_user(user)
login_as_manager
end
context "Create" do
scenario "Creating proposals on behalf of someone" do
login_as_manager
click_link "Create proposal"
within(".account-info") do
@@ -42,6 +42,7 @@ describe "Proposals" do
scenario "Should not allow unverified users to create proposals" do
login_managed_user(create(:user))
login_as_manager
click_link "Create proposal"
expect(page).to have_content "User is not verified"
@@ -53,6 +54,7 @@ describe "Proposals" do
proposal = create(:proposal)
right_path = management_proposal_path(proposal)
login_as_manager
visit right_path
expect(page).to have_current_path(right_path)
@@ -63,6 +65,8 @@ describe "Proposals" do
right_path = management_proposal_path(proposal)
old_path = "#{management_proposals_path}/#{proposal.id}-something-else"
login_as_manager
visit old_path
expect(page).not_to have_current_path(old_path)
@@ -72,6 +76,7 @@ describe "Proposals" do
scenario "Successful proposal" do
proposal = create(:proposal, :successful, title: "Success!")
login_as_manager
visit management_proposal_path(proposal)
expect(page).to have_content("Success!")
@@ -82,6 +87,7 @@ describe "Proposals" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
login_as_manager
click_link "Support proposals"
fill_in "search", with: "what you got"
@@ -102,6 +108,7 @@ describe "Proposals" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
login_as_manager
click_link "Support proposals"
expect(page).to have_current_path(management_proposals_path)
@@ -126,6 +133,7 @@ describe "Proposals" do
let!(:proposal) { create(:proposal) }
scenario "Voting proposals on behalf of someone in index view" do
login_as_manager
click_link "Support proposals"
within(".proposals-list") do
@@ -138,6 +146,7 @@ describe "Proposals" do
end
scenario "Voting proposals on behalf of someone in show view" do
login_as_manager
click_link "Support proposals"
within(".proposals-list") { click_link proposal.title }
@@ -153,6 +162,7 @@ describe "Proposals" do
scenario "Should not allow unverified users to vote proposals" do
login_managed_user(create(:user))
login_as_manager
click_link "Support proposals"
expect(page).to have_content "User is not verified"
@@ -163,6 +173,7 @@ describe "Proposals" do
scenario "Printing proposals" do
6.times { create(:proposal) }
login_as_manager
click_link "Print proposals"
expect(page).to have_css(".proposal", count: 5)
@@ -177,6 +188,7 @@ describe "Proposals" do
medium_proposal = create(:proposal, title: "Medium proposal")
medium_proposal.update_column(:confidence_score, 5)
login_as_manager
click_link "Print proposals"
expect(page).to have_selector(".js-order-selector[data-order='confidence_score']")

View File

@@ -1,11 +1,8 @@
require "rails_helper"
describe "Users" do
before do
login_as_manager
end
scenario "Create a level 3 user with email from scratch" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"
@@ -46,6 +43,7 @@ describe "Users" do
end
scenario "Create a level 3 user without email from scratch" do
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"
@@ -74,6 +72,7 @@ describe "Users" do
scenario "Delete a level 2 user account from document verification page" do
level_2_user = create(:user, :level_two, document_number: "12345678Z")
login_as_manager
visit management_document_verifications_path
fill_in "document_verification_document_number", with: "12345678Z"
click_button "Check document"

View File

@@ -1,11 +1,8 @@
require "rails_helper"
describe "User invites" do
before do
login_as_manager
end
scenario "Send invitations" do
login_as_manager
visit new_management_user_invite_path
fill_in "emails", with: "john@example.com, ana@example.com, isable@example.com"