Files
grecia/spec/controllers/proposals_controller_spec.rb
Javi Martín a28967817e Split some system tests checking the database
As mentioned in commits like a586ba806, a7664ad81, 006128da5, b41fbfa52
and c480cdd91, 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.
2025-04-01 14:53:26 +02:00

60 lines
1.6 KiB
Ruby

require "rails_helper"
describe ProposalsController do
describe "GET index" do
it "raises an exception when the feature is disabled" do
Setting["process.proposals"] = false
expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled)
end
end
describe "PATCH update" do
before { InvisibleCaptcha.timestamp_enabled = false }
after { InvisibleCaptcha.timestamp_enabled = true }
it "does not delete other proposal's map location" do
proposal = create(:proposal)
other_proposal = create(:proposal, :with_map_location)
sign_in(proposal.author)
patch :update, params: {
proposal: {
map_location_attributes: { id: other_proposal.map_location.id },
responsible_name: "Skinny Fingers"
},
id: proposal.id
}
expect(proposal.reload.responsible_name).to eq "Skinny Fingers"
expect(other_proposal.reload.map_location).not_to be nil
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