1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Reset primary key sequence in FixturesResetPkSequenceTests

The primary key sequence for each test in FixturesResetPkSequenceTest is
reset.

The state in some of the FixturesResetPkSequenceTest tests are leaking,
causing failurse in others. Using a seed of `48104`, the
`FixturesResetPkSequenceTest#test_resets_to_min_pk_with_specified_pk_and_sequence`
runs before the `DatabaseStatementsTest` tests, and
the tests fail with duplicate primary key errors:

```
Run options: --seed 48104 -n
"/^(?:FixturesResetPkSequenceTest#(?:test_resets_to_min_pk_with_specified_pk_and_sequence)|DatabaseStatementsTest#(?:test_create_should_return_the_inserted_id|test_exec_insert|test_insert_should_return_the_inserted_id))$/"

.EEE

  1) Error:
DatabaseStatementsTest#test_exec_insert:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate
key value violates unique constraint "accounts_pkey"
DETAIL:  Key (id)=(2) already exists.

  2) Error:
DatabaseStatementsTest#test_create_should_return_the_inserted_id:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate
key value violates unique constraint "accounts_pkey"
DETAIL:  Key (id)=(3) already exists.

  3) Error:
DatabaseStatementsTest#test_insert_should_return_the_inserted_id:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate
key value violates unique constraint "accounts_pkey"
DETAIL:  Key (id)=(4) already exists.
```
This commit is contained in:
Alex Kitchens 2017-05-30 09:04:36 -05:00 committed by Alex Kitchens
parent 612b54b96a
commit dcd3b940e9

View file

@ -365,6 +365,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
class FixturesResetPkSequenceTest < ActiveRecord::TestCase
fixtures :accounts
fixtures :companies
self.use_transactional_tests = false
def setup
@instances = [Account.new(credit_limit: 50), Company.new(name: "RoR Consulting"), Course.new(name: "Test")]