Don't assign IDs to assignment records in tests

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
This commit is contained in:
Javi Martín
2021-06-14 12:45:45 +02:00
parent 7f38f61bc1
commit 433b465ec7
2 changed files with 16 additions and 8 deletions

View File

@@ -39,19 +39,23 @@ describe Poll::PartialResult do
expect(partial_result.officer_assignment_id_log).to eq("")
partial_result.amount = 33
partial_result.officer_assignment = create(:poll_officer_assignment, id: 10)
first_assignment = create(:poll_officer_assignment)
partial_result.officer_assignment = first_assignment
partial_result.save!
partial_result.amount = 32
partial_result.officer_assignment = create(:poll_officer_assignment, id: 20)
second_assignment = create(:poll_officer_assignment)
partial_result.officer_assignment = second_assignment
partial_result.save!
partial_result.amount = 34
partial_result.officer_assignment = create(:poll_officer_assignment, id: 30)
partial_result.officer_assignment = create(:poll_officer_assignment)
partial_result.save!
expect(partial_result.amount_log).to eq(":33:32")
expect(partial_result.officer_assignment_id_log).to eq(":10:20")
expect(partial_result.officer_assignment_id_log).to eq(
":#{first_assignment.id}:#{second_assignment.id}"
)
end
it "updates author_id if amount changes" do

View File

@@ -58,19 +58,23 @@ describe Poll::Recount do
expect(poll_recount.officer_assignment_id_log).to eq("")
poll_recount.white_amount = 33
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 101)
second_assignment = create(:poll_officer_assignment)
poll_recount.officer_assignment = second_assignment
poll_recount.save!
poll_recount.white_amount = 32
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 102)
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, id: 103)
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}:101:102")
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