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.
105 lines
3.1 KiB
Ruby
105 lines
3.1 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Poll::Recount do
|
|
|
|
describe "logging changes" do
|
|
let(:author) { create(:user) }
|
|
let(:officer_assignment) { create(:poll_officer_assignment) }
|
|
let(:poll_recount) { create(:poll_recount, author: author, officer_assignment: officer_assignment) }
|
|
|
|
it "updates white_amount_log if white_amount changes" do
|
|
poll_recount.white_amount = 33
|
|
|
|
expect(poll_recount.white_amount_log).to eq("")
|
|
|
|
poll_recount.white_amount = 33
|
|
poll_recount.save!
|
|
poll_recount.white_amount = 32
|
|
poll_recount.save!
|
|
poll_recount.white_amount = 34
|
|
poll_recount.save!
|
|
|
|
expect(poll_recount.white_amount_log).to eq(":0:33:32")
|
|
end
|
|
|
|
it "updates null_amount_log if null_amount changes" do
|
|
poll_recount.null_amount = 33
|
|
|
|
expect(poll_recount.null_amount_log).to eq("")
|
|
|
|
poll_recount.null_amount = 33
|
|
poll_recount.save!
|
|
poll_recount.null_amount = 32
|
|
poll_recount.save!
|
|
poll_recount.null_amount = 34
|
|
poll_recount.save!
|
|
|
|
expect(poll_recount.null_amount_log).to eq(":0:33:32")
|
|
end
|
|
|
|
it "updates total_amount_log if total_amount changes" do
|
|
poll_recount.total_amount = 33
|
|
|
|
expect(poll_recount.total_amount_log).to eq("")
|
|
|
|
poll_recount.total_amount = 33
|
|
poll_recount.save!
|
|
poll_recount.total_amount = 32
|
|
poll_recount.save!
|
|
poll_recount.total_amount = 34
|
|
poll_recount.save!
|
|
|
|
expect(poll_recount.total_amount_log).to eq(":0:33:32")
|
|
end
|
|
|
|
it "updates officer_assignment_id_log if amount changes" do
|
|
poll_recount.white_amount = 33
|
|
|
|
expect(poll_recount.white_amount_log).to eq("")
|
|
expect(poll_recount.officer_assignment_id_log).to eq("")
|
|
|
|
poll_recount.white_amount = 33
|
|
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 101)
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 32
|
|
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 102)
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 34
|
|
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 103)
|
|
poll_recount.save!
|
|
|
|
expect(poll_recount.white_amount_log).to eq(":0:33:32")
|
|
expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102")
|
|
end
|
|
|
|
it "updates author_id if amount changes" do
|
|
poll_recount.white_amount = 33
|
|
|
|
expect(poll_recount.white_amount_log).to eq("")
|
|
expect(poll_recount.author_id_log).to eq("")
|
|
|
|
first_author = create(:poll_officer).user
|
|
second_author = create(:poll_officer).user
|
|
third_author = create(:poll_officer).user
|
|
|
|
poll_recount.white_amount = 33
|
|
poll_recount.author_id = first_author.id
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 32
|
|
poll_recount.author_id = second_author.id
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 34
|
|
poll_recount.author_id = third_author.id
|
|
poll_recount.save!
|
|
|
|
expect(poll_recount.white_amount_log).to eq(":0:33:32")
|
|
expect(poll_recount.author_id_log).to eq(":#{author.id}:#{first_author.id}:#{second_author.id}")
|
|
end
|
|
end
|
|
|
|
end
|