Skip to content

Commit

Permalink
Merge pull request #4472 from consul/visit_after_setup
Browse files Browse the repository at this point in the history
Setup database before starting the browser in tests
  • Loading branch information
javierm committed Apr 14, 2021
2 parents 9af3723 + 16fdffd commit 89e8292
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 71 deletions.
13 changes: 9 additions & 4 deletions spec/system/admin/administrators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
let!(:user) { create(:user, username: "Jose Luis Balbin") }
let!(:user_administrator) { create(:administrator, description: "admin_alias") }

before do
login_as(admin.user)
visit admin_administrators_path
end
before { login_as(admin.user) }

scenario "Index" do
visit admin_administrators_path

expect(page).to have_content user_administrator.id
expect(page).to have_content user_administrator.name
expect(page).to have_content user_administrator.email
Expand All @@ -19,6 +18,8 @@
end

scenario "Create Administrator" do
visit admin_administrators_path

fill_in "search", with: user.email
click_button "Search"

Expand All @@ -30,6 +31,8 @@
end

scenario "Delete Administrator" do
visit admin_administrators_path

within "#administrator_#{user_administrator.id}" do
accept_confirm { click_link "Delete" }
end
Expand All @@ -40,6 +43,8 @@
end

scenario "Delete Administrator when its the current user" do
visit admin_administrators_path

within "#administrator_#{admin.id}" do
accept_confirm { click_link "Delete" }
end
Expand Down
8 changes: 5 additions & 3 deletions spec/system/admin/managers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
let!(:user) { create(:user) }
let!(:manager) { create(:manager) }

before do
scenario "Index" do
visit admin_managers_path
end

scenario "Index" do
expect(page).to have_content manager.name
expect(page).to have_content manager.email
expect(page).not_to have_content user.name
end

scenario "Create Manager" do
visit admin_managers_path

fill_in "search", with: user.email
click_button "Search"

Expand All @@ -26,6 +26,8 @@
end

scenario "Delete Manager" do
visit admin_managers_path

accept_confirm { click_link "Delete" }

within("#managers") do
Expand Down
8 changes: 5 additions & 3 deletions spec/system/admin/moderators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
let!(:user) { create(:user, username: "Jose Luis Balbin") }
let!(:moderator) { create(:moderator) }

before do
scenario "Index" do
visit admin_moderators_path
end

scenario "Index" do
expect(page).to have_content moderator.name
expect(page).to have_content moderator.email
expect(page).not_to have_content user.name
end

scenario "Create Moderator" do
visit admin_moderators_path

fill_in "search", with: user.email
click_button "Search"

Expand All @@ -26,6 +26,8 @@
end

scenario "Delete Moderator" do
visit admin_moderators_path

accept_confirm { click_link "Delete" }

within("#moderators") do
Expand Down
11 changes: 7 additions & 4 deletions spec/system/admin/sdg/managers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
let!(:user) { create(:user) }
let!(:sdg_manager) { create(:sdg_manager) }

before do
login_as(create(:administrator).user)
visit admin_sdg_managers_path
end
before { login_as(create(:administrator).user) }

scenario "Index" do
visit admin_sdg_managers_path

expect(page).to have_content sdg_manager.name
expect(page).to have_content sdg_manager.email
expect(page).not_to have_content user.name
end

scenario "Create SDG Manager" do
visit admin_sdg_managers_path

fill_in "search", with: user.email
click_button "Search"

Expand All @@ -29,6 +30,8 @@
end

scenario "Delete SDG Manager" do
visit admin_sdg_managers_path

accept_confirm { click_link "Delete" }

within("#sdg_managers") do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/site_customization/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
slugs = %w[accessibility conditions faq privacy welcome_not_verified
welcome_level_two_verified welcome_level_three_verified]

visit admin_site_customization_pages_path

expect(SiteCustomization::Page.count).to be 7
slugs.each do |slug|
expect(SiteCustomization::Page.find_by(slug: slug).status).to eq "published"
end

visit admin_site_customization_pages_path

expect(all("[id^='site_customization_page_']").count).to be 7
slugs.each do |slug|
expect(page).to have_content slug
Expand Down
11 changes: 7 additions & 4 deletions spec/system/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
let(:admin) { create(:administrator) }
let!(:user) { create(:user, username: "Jose Luis Balbin") }

before do
login_as(admin.user)
visit admin_users_path
end
before { login_as(admin.user) }

scenario "Index" do
visit admin_users_path

expect(page).to have_link user.name
expect(page).to have_content user.email
expect(page).to have_content admin.name
expect(page).to have_content admin.email
end

scenario "The username links to their public profile" do
visit admin_users_path

within_window(window_opened_by { click_link user.name }) do
expect(page).to have_current_path(user_path(user))
end
Expand Down Expand Up @@ -45,6 +46,8 @@
end

scenario "Search" do
visit admin_users_path

fill_in :search, with: "Luis"
click_button "Search"

Expand Down
8 changes: 6 additions & 2 deletions spec/system/admin/valuators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
let!(:user) { create(:user, username: "Jose Luis Balbin") }
let!(:valuator) { create(:valuator, description: "Very reliable") }

before { visit admin_valuators_path }

scenario "Show" do
visit admin_valuator_path(valuator)

Expand All @@ -16,12 +14,16 @@
end

scenario "Index" do
visit admin_valuators_path

expect(page).to have_content(valuator.name)
expect(page).to have_content(valuator.email)
expect(page).not_to have_content(user.name)
end

scenario "Create" do
visit admin_valuators_path

fill_in "search", with: user.email
click_button "Search"

Expand Down Expand Up @@ -51,6 +53,8 @@
end

scenario "Destroy" do
visit admin_valuators_path

accept_confirm { click_link "Delete" }

within("#valuators") do
Expand Down
5 changes: 1 addition & 4 deletions spec/system/budgets/ballots_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
end

context "Voting" do
before do
login_as(user)
visit budget_path(budget)
end
before { login_as(user) }

let!(:city) { create(:budget_group, budget: budget, name: "City") }
let!(:districts) { create(:budget_group, budget: budget, name: "Districts") }
Expand Down
11 changes: 4 additions & 7 deletions spec/system/dashboard/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,7 @@
end

describe "detect_new_actions_after_last_login" do
before do
visit proposal_dashboard_path(proposal)
proposal.author.update!(last_sign_in_at: Date.yesterday)
end
before { proposal.author.update!(current_sign_in_at: 1.day.ago) }

scenario "Display tag 'new' on resouce when it is new for author since last login" do
resource = create(:dashboard_action, :resource, :active, day_offset: 0,
Expand All @@ -503,7 +500,7 @@
scenario "Not display tag 'new' on resouce when there is not new resources since last login" do
resource = create(:dashboard_action, :resource, :active, day_offset: 0,
published_proposal: false)
proposal.author.update!(last_sign_in_at: Date.current)
proposal.author.update!(current_sign_in_at: Date.current)

visit progress_proposal_dashboard_path(proposal)

Expand All @@ -526,7 +523,7 @@
scenario "Not display tag 'new' on proposed_action when there is not new since last login" do
proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0,
published_proposal: false)
proposal.author.update!(last_sign_in_at: Date.current)
proposal.author.update!(current_sign_in_at: Date.current)

visit progress_proposal_dashboard_path(proposal)

Expand All @@ -547,7 +544,7 @@

scenario "Not display tag 'new' on sidebar when there is not a new resouce since last login" do
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
proposal.author.update!(last_sign_in_at: Date.current)
proposal.author.update!(current_sign_in_at: Date.current)

visit progress_proposal_dashboard_path(proposal)

Expand Down
9 changes: 5 additions & 4 deletions spec/system/dashboard/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
describe "Polls" do
let!(:proposal) { create(:proposal, :draft) }

before do
login_as(proposal.author)
visit proposal_dashboard_path(proposal)
end
before { login_as(proposal.author) }

scenario "Has a link to polls feature" do
visit proposal_dashboard_path(proposal)

expect(page).to have_link("Polls")
end

scenario "Create a poll" do
visit proposal_dashboard_path(proposal)
click_link "Polls"
click_link "Create poll"

Expand Down Expand Up @@ -80,6 +80,7 @@
end

scenario "Create a poll redirects back to form when invalid data" do
visit proposal_dashboard_path(proposal)
click_link "Polls"
click_link "Create poll"

Expand Down
11 changes: 9 additions & 2 deletions spec/system/officing/residence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@
context "With remote census configuration", :remote_census do
before do
create(:poll_officer_assignment, officer: officer)
login_through_form_as_officer(officer.user)
visit officing_root_path
end

describe "Display form fields according to the remote census configuration" do
scenario "by default (without custom census) not display date_of_birth and postal_code" do
Setting["feature.remote_census"] = false

login_through_form_as_officer(officer.user)
visit officing_root_path

within("#side_menu") do
click_link "Validate document"
end
Expand All @@ -134,6 +135,9 @@
end

scenario "with all custom census not display year_of_birth" do
login_through_form_as_officer(officer.user)
visit officing_root_path

within("#side_menu") do
click_link "Validate document"
end
Expand All @@ -149,6 +153,9 @@
scenario "can verify voter with date_of_birth and postal_code fields" do
mock_valid_remote_census_response

login_through_form_as_officer(officer.user)
visit officing_root_path

within("#side_menu") do
click_link "Validate document"
end
Expand Down
3 changes: 0 additions & 3 deletions spec/system/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@
proposal = create(:proposal)
visit proposal_path(proposal)
expect(page).to have_content "Access the community"

Setting["feature.community"] = false
end

scenario "Can not access the community" do
Expand Down Expand Up @@ -746,7 +744,6 @@
expect(page).not_to have_current_path(edit_proposal_path(proposal))
expect(page).to have_current_path(root_path)
expect(page).to have_content "You do not have permission"
Setting["max_votes_for_proposal_edit"] = 1000
end

scenario "Update should be posible for the author of an editable proposal" do
Expand Down
Loading

0 comments on commit 89e8292

Please sign in to comment.