The test "updates officer_assignment_id_log if amount changes" failed
when the ID we assigned when creating the records was the same as the ID
of the first officer assignment created during that test. It's recently
happened while running our test suite [1] with the following error:
```
1) Poll::Recount logging changes updates officer_assignment_id_log if
amount changes
Failure/Error: poll_recount.officer_assignment =
create(:poll_officer_assignment, id: 101)
ActiveRecord::RecordNotUnique:
PG::UniqueViolation: ERROR: duplicate key value violates unique
constraint "poll_officer_assignments_pkey"
DETAIL: Key (id)=(101) already exists.
```
We're also removing the IDs in the "updates officer_assignment_id_log if
amount changes" test to avoid any possible issues, even if in this test
I think no other officer assignments are created and so there can't be
another record with the same ID.
[1] https://github.com/consul/consul/runs/2818889296
107 lines
3.2 KiB
Ruby
107 lines
3.2 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
|
|
second_assignment = create(:poll_officer_assignment)
|
|
poll_recount.officer_assignment = second_assignment
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 32
|
|
third_assignment = create(:poll_officer_assignment)
|
|
poll_recount.officer_assignment = third_assignment
|
|
poll_recount.save!
|
|
|
|
poll_recount.white_amount = 34
|
|
poll_recount.officer_assignment = create(:poll_officer_assignment)
|
|
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}:#{second_assignment.id}:#{third_assignment.id}"
|
|
)
|
|
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
|