diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-07-17 15:06:38 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-07-17 16:20:58 +0900 |
commit | 1701709e7f87520a07eed87dec1570be13584f72 (patch) | |
tree | 63a7c303b2f838f2630d87595a6c312883aed772 /activerecord/test/cases | |
parent | d87fbf75abd368fef33f1f01024623f32881b2d2 (diff) | |
download | rails-1701709e7f87520a07eed87dec1570be13584f72.tar.gz rails-1701709e7f87520a07eed87dec1570be13584f72.tar.bz2 rails-1701709e7f87520a07eed87dec1570be13584f72.zip |
Move `reset_pk_sequence!` test to `AdapterTestWithoutTransaction`
If execute PostgreSQL test with specifying 53853 for seed, the following
error will occur.
```
1) Error:
TransactionTest#test_restore_custom_primary_key_after_rollback:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "movies_pkey"
DETAIL: Key (movieid)=(2) already exists.
: INSERT INTO "movies" ("name") VALUES ($1) RETURNING "movieid"
```
travis is here https://travis-ci.org/rails/rails/jobs/254095918
As with #29287, it seems like a problem that the value of primary key
obtained from connection gets different.
Therefore, fixed to execute that test within transaction.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapter_test.rb | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb index 827bcba121..eccd250d19 100644 --- a/activerecord/test/cases/adapter_test.rb +++ b/activerecord/test/cases/adapter_test.rb @@ -156,26 +156,6 @@ module ActiveRecord end end - # test resetting sequences in odd tables in PostgreSQL - if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) - require "models/movie" - require "models/subscriber" - - def test_reset_empty_table_with_custom_pk - Movie.delete_all - Movie.connection.reset_pk_sequence! "movies" - assert_equal 1, Movie.create(name: "fight club").id - end - - def test_reset_table_with_non_integer_pk - Subscriber.delete_all - Subscriber.connection.reset_pk_sequence! "subscribers" - sub = Subscriber.new(name: "robert drake") - sub.id = "bob drake" - assert_nothing_raised { sub.save! } - end - end - def test_uniqueness_violations_are_translated_to_specific_exception @connection.execute "INSERT INTO subscribers(nick) VALUES('me')" error = assert_raises(ActiveRecord::RecordNotUnique) do @@ -368,5 +348,25 @@ module ActiveRecord assert !@connection.transaction_open? end end + + # test resetting sequences in odd tables in PostgreSQL + if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) + require "models/movie" + require "models/subscriber" + + def test_reset_empty_table_with_custom_pk + Movie.delete_all + Movie.connection.reset_pk_sequence! "movies" + assert_equal 1, Movie.create(name: "fight club").id + end + + def test_reset_table_with_non_integer_pk + Subscriber.delete_all + Subscriber.connection.reset_pk_sequence! "subscribers" + sub = Subscriber.new(name: "robert drake") + sub.id = "bob drake" + assert_nothing_raised { sub.save! } + end + end end end |