Split some system tests checking the database
As mentioned in commits likea586ba806,a7664ad81,006128da5,b41fbfa52andc480cdd91, accessing the database after starting the browser with the `visit` method sometimes results in database corruption and failing tests on our CI due to the process running the test accessing the database after the process running the browser has started. IMHO this is also a bad practice for system tests, since these tests should be checking what users experience. In these cases, however, I haven't been able to test the user experience. For example, it looks like failed census calls for unregistered users aren't displayed anywhere and can only be accessed by manually checking the database. Similarly, there's no interface showing that all the options from a poll have been deleted (which makes sense, since we only display options in the context of their poll) or a place showing the responsible name for a proposal. So we're splitting the tests in two, with the controller test running the database checks.
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Admin::AdminNotificationsController, :admin do
|
||||||
|
describe "POST deliver" do
|
||||||
|
it "sends notifications to every recipient" do
|
||||||
|
2.times { create(:user) }
|
||||||
|
notification = create(:admin_notification, segment_recipient: :all_users)
|
||||||
|
|
||||||
|
post :deliver, params: { id: notification }
|
||||||
|
|
||||||
|
User.find_each do |user|
|
||||||
|
expect(user.notifications.count).to eq 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,4 +8,17 @@ describe Admin::Poll::PollsController, :admin do
|
|||||||
expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled)
|
expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "DELETE destroy" do
|
||||||
|
it "deletes every question and every option from that poll" do
|
||||||
|
poll = create(:poll, name: "Do you support CONSUL?")
|
||||||
|
create(:poll_question, :yes_no, poll: poll)
|
||||||
|
|
||||||
|
delete :destroy, params: { id: poll }
|
||||||
|
|
||||||
|
expect(Poll.count).to eq 0
|
||||||
|
expect(Poll::Question.count).to eq 0
|
||||||
|
expect(Poll::Question::Option.count).to eq 0
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
22
spec/controllers/officing/residence_controller_spec.rb
Normal file
22
spec/controllers/officing/residence_controller_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Officing::ResidenceController do
|
||||||
|
describe "POST create" do
|
||||||
|
it "creates a failed census called when the census data is invalid" do
|
||||||
|
officer = create(:poll_officer)
|
||||||
|
create(:poll_officer_assignment, officer: officer)
|
||||||
|
|
||||||
|
sign_in(officer.user)
|
||||||
|
|
||||||
|
expect do
|
||||||
|
post :create, params: {
|
||||||
|
residence: { document_type: "1", document_number: "23456789A", year_of_birth: "1980" }
|
||||||
|
}
|
||||||
|
end.to change { FailedCensusCall.count }.by(1)
|
||||||
|
|
||||||
|
failed_census_call = FailedCensusCall.last
|
||||||
|
expect(failed_census_call.poll_officer).to eq officer
|
||||||
|
expect(officer.failed_census_calls).to eq [failed_census_call]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -20,6 +20,7 @@ describe Officing::VotersController do
|
|||||||
end.each(&:join)
|
end.each(&:join)
|
||||||
|
|
||||||
expect(Poll::Voter.count).to eq 1
|
expect(Poll::Voter.count).to eq 1
|
||||||
|
expect(Poll::Voter.last.officer_id).to eq(officer.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,4 +31,29 @@ describe ProposalsController do
|
|||||||
expect(other_proposal.reload.map_location).not_to be nil
|
expect(other_proposal.reload.map_location).not_to be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "POST create" do
|
||||||
|
before { InvisibleCaptcha.timestamp_enabled = false }
|
||||||
|
after { InvisibleCaptcha.timestamp_enabled = true }
|
||||||
|
|
||||||
|
it "assigns the responsible name to the proposal" do
|
||||||
|
sign_in(create(:user, document_number: "13572468A"))
|
||||||
|
|
||||||
|
post :create, params: {
|
||||||
|
proposal: {
|
||||||
|
translations_attributes: {
|
||||||
|
"0" => {
|
||||||
|
locale: "en",
|
||||||
|
title: "I'm responsible",
|
||||||
|
summary: "I have a document number",
|
||||||
|
description: "But you won't see my document number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
terms_of_service: "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Proposal.last.responsible_name).to eq "13572468A"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -193,10 +193,7 @@ describe "Admin Notifications", :admin do
|
|||||||
accept_confirm { click_button "Send notification" }
|
accept_confirm { click_button "Send notification" }
|
||||||
|
|
||||||
expect(page).to have_content "Notification sent successfully"
|
expect(page).to have_content "Notification sent successfully"
|
||||||
|
expect(page).to have_content "3 users got notified"
|
||||||
User.find_each do |user|
|
|
||||||
expect(user.notifications.count).to eq(1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "A sent Admin notification can not be sent" do
|
scenario "A sent Admin notification can not be sent" do
|
||||||
|
|||||||
@@ -129,11 +129,8 @@ describe "Admin polls", :admin do
|
|||||||
accept_confirm { click_button "Delete" }
|
accept_confirm { click_button "Delete" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_content("Poll deleted successfully")
|
expect(page).to have_content "Poll deleted successfully"
|
||||||
expect(page).not_to have_content("Do you support CONSUL?")
|
expect(page).not_to have_content "Do you support CONSUL?"
|
||||||
|
|
||||||
expect(Poll::Question.count).to eq(0)
|
|
||||||
expect(Poll::Question::Option.count).to eq(0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Can destroy polls with options including videos" do
|
scenario "Can destroy polls with options including videos" do
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ describe "Residence", :with_frozen_time do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Error on Census (document number)" do
|
scenario "Error on Census (document number)" do
|
||||||
initial_failed_census_calls_count = officer.failed_census_calls_count
|
|
||||||
within("#side_menu") do
|
within("#side_menu") do
|
||||||
click_link "Validate document"
|
click_link "Validate document"
|
||||||
end
|
end
|
||||||
@@ -65,13 +64,6 @@ describe "Residence", :with_frozen_time do
|
|||||||
click_button "Validate document"
|
click_button "Validate document"
|
||||||
|
|
||||||
expect(page).to have_content "The Census was unable to verify this document"
|
expect(page).to have_content "The Census was unable to verify this document"
|
||||||
|
|
||||||
officer.reload
|
|
||||||
fcc = FailedCensusCall.last
|
|
||||||
expect(fcc).to be
|
|
||||||
expect(fcc.poll_officer).to eq(officer)
|
|
||||||
expect(officer.failed_census_calls.last).to eq(fcc)
|
|
||||||
expect(officer.failed_census_calls_count).to eq(initial_failed_census_calls_count + 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Error on Census (year of birth)" do
|
scenario "Error on Census (year of birth)" do
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ describe "Voters" do
|
|||||||
page.evaluate_script("window.location.reload()")
|
page.evaluate_script("window.location.reload()")
|
||||||
expect(page).to have_content "Has already participated in this poll"
|
expect(page).to have_content "Has already participated in this poll"
|
||||||
expect(page).not_to have_button "Confirm vote"
|
expect(page).not_to have_button "Confirm vote"
|
||||||
|
|
||||||
expect(Poll::Voter.last.officer_id).to eq(officer.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Cannot vote" do
|
scenario "Cannot vote" do
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ describe "Proposals" do
|
|||||||
expect(page).to have_field "Full name of the person submitting the proposal", with: "Isabel Garcia"
|
expect(page).to have_field "Full name of the person submitting the proposal", with: "Isabel Garcia"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Responsible name field is not shown for verified users" do
|
scenario "Responsible name field is not shown anywhere" do
|
||||||
author = create(:user, :level_two)
|
author = create(:user, :level_two)
|
||||||
login_as(author)
|
login_as(author)
|
||||||
|
|
||||||
@@ -453,7 +453,8 @@ describe "Proposals" do
|
|||||||
click_link "No, I want to publish the proposal"
|
click_link "No, I want to publish the proposal"
|
||||||
click_link "Not now, go to my proposal"
|
click_link "Not now, go to my proposal"
|
||||||
|
|
||||||
expect(Proposal.last.responsible_name).to eq(author.document_number)
|
expect(page).to have_css "h1", exact_text: "Help refugees"
|
||||||
|
expect(page).not_to have_content author.document_number
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Errors on create" do
|
scenario "Errors on create" do
|
||||||
|
|||||||
Reference in New Issue
Block a user