Having exceptions is better than having silent bugs.
There are a few methods I've kept the same way they were.
The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.
We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").
Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.
There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.
For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
167 lines
5.6 KiB
Ruby
167 lines
5.6 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Signature sheets" do
|
|
|
|
before do
|
|
admin = create(:administrator)
|
|
login_as(admin.user)
|
|
end
|
|
|
|
context "Index" do
|
|
scenario "Lists all signature_sheets" do
|
|
3.times { create(:signature_sheet) }
|
|
|
|
visit admin_signature_sheets_path
|
|
|
|
expect(page).to have_css(".signature_sheet", count: 3)
|
|
|
|
SignatureSheet.find_each do |signature_sheet|
|
|
expect(page).to have_content signature_sheet.name
|
|
end
|
|
end
|
|
|
|
scenario "Orders signature_sheets by created_at DESC" do
|
|
signature_sheet1 = create(:signature_sheet)
|
|
signature_sheet2 = create(:signature_sheet)
|
|
signature_sheet3 = create(:signature_sheet)
|
|
|
|
visit admin_signature_sheets_path
|
|
|
|
expect(signature_sheet3.name).to appear_before(signature_sheet2.name)
|
|
expect(signature_sheet2.name).to appear_before(signature_sheet1.name)
|
|
end
|
|
end
|
|
|
|
context "Create" do
|
|
scenario "Proposal" do
|
|
proposal = create(:proposal)
|
|
visit new_admin_signature_sheet_path
|
|
|
|
select "Citizen proposal", from: "signature_sheet_signable_type"
|
|
fill_in "signature_sheet_signable_id", with: proposal.id
|
|
fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z; 1234567L; 99999999Z"
|
|
click_button "Create signature sheet"
|
|
|
|
expect(page).to have_content "Signature sheet created successfully"
|
|
expect(page).to have_content "There is 1 valid signature"
|
|
expect(page).to have_content "There is 1 vote created from the verified signatures"
|
|
expect(page).to have_content "There are 2 invalid signatures"
|
|
|
|
visit proposal_path(proposal)
|
|
|
|
expect(page).to have_content "1 support"
|
|
end
|
|
|
|
scenario "Budget Investment" do
|
|
investment = create(:budget_investment)
|
|
budget = investment.budget
|
|
budget.update!(phase: "selecting")
|
|
|
|
visit new_admin_signature_sheet_path
|
|
|
|
select "Investment", from: "signature_sheet_signable_type"
|
|
fill_in "signature_sheet_signable_id", with: investment.id
|
|
fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z; 1234567L; 99999999Z"
|
|
click_button "Create signature sheet"
|
|
|
|
expect(page).to have_content "Signature sheet created successfully"
|
|
expect(page).to have_content "There is 1 valid signature"
|
|
expect(page).to have_content "There is 1 vote created from the verified signatures"
|
|
expect(page).to have_content "There are 2 invalid signatures"
|
|
|
|
visit budget_investment_path(budget, investment)
|
|
|
|
expect(page).to have_content "1 support"
|
|
end
|
|
|
|
end
|
|
|
|
context "Create throught all required_fields_to_verify of custom census api" do
|
|
|
|
before do
|
|
Setting["feature.remote_census"] = true
|
|
Setting["remote_census.request.date_of_birth"] = "some.value"
|
|
Setting["remote_census.request.postal_code"] = "some.value"
|
|
access_user_data = "get_habita_datos_response.get_habita_datos_return.datos_habitante.item"
|
|
access_residence_data = "get_habita_datos_response.get_habita_datos_return.datos_vivienda.item"
|
|
Setting["remote_census.response.date_of_birth"] = "#{access_user_data}.fecha_nacimiento_string"
|
|
Setting["remote_census.response.postal_code"] = "#{access_residence_data}.codigo_postal"
|
|
Setting["remote_census.response.valid"] = access_user_data
|
|
end
|
|
|
|
scenario "Proposal" do
|
|
proposal = create(:proposal)
|
|
visit new_admin_signature_sheet_path
|
|
|
|
select "Citizen proposal", from: "signature_sheet_signable_type"
|
|
fill_in "signature_sheet_signable_id", with: proposal.id
|
|
fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013"
|
|
click_button "Create signature sheet"
|
|
|
|
expect(page).to have_content "Signature sheet created successfully"
|
|
|
|
visit proposal_path(proposal)
|
|
|
|
expect(page).to have_content "1 support"
|
|
end
|
|
|
|
scenario "Budget Investment" do
|
|
investment = create(:budget_investment)
|
|
budget = investment.budget
|
|
budget.update!(phase: "selecting")
|
|
|
|
visit new_admin_signature_sheet_path
|
|
|
|
select "Investment", from: "signature_sheet_signable_type"
|
|
fill_in "signature_sheet_signable_id", with: investment.id
|
|
fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 31/12/1980, 28013; 99999999Z, 31/12/1980, 28013"
|
|
click_button "Create signature sheet"
|
|
|
|
expect(page).to have_content "Signature sheet created successfully"
|
|
|
|
visit budget_investment_path(budget, investment)
|
|
|
|
expect(page).to have_content "1 support"
|
|
end
|
|
|
|
end
|
|
|
|
scenario "Errors on create" do
|
|
visit new_admin_signature_sheet_path
|
|
|
|
click_button "Create signature sheet"
|
|
|
|
expect(page).to have_content error_message
|
|
end
|
|
|
|
scenario "Show" do
|
|
proposal = create(:proposal)
|
|
user = Administrator.first.user
|
|
signature_sheet = create(:signature_sheet,
|
|
signable: proposal,
|
|
required_fields_to_verify: "12345678Z; 123A; 123B",
|
|
author: user)
|
|
signature_sheet.verify_signatures
|
|
|
|
visit admin_signature_sheet_path(signature_sheet)
|
|
|
|
expect(page).to have_content "Citizen proposal #{proposal.id}"
|
|
expect(page).to have_content "12345678Z; 123A; 123B"
|
|
expect(page).to have_content signature_sheet.created_at.strftime("%B %d, %Y %H:%M")
|
|
expect(page).to have_content user.name
|
|
|
|
within("#signature_count") do
|
|
expect(page).to have_content 3
|
|
end
|
|
|
|
within("#verified_signatures") do
|
|
expect(page).to have_content 1
|
|
end
|
|
|
|
within("#unverified_signatures") do
|
|
expect(page).to have_content 2
|
|
end
|
|
end
|
|
|
|
end
|