diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-10-31 18:01:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-10-31 18:08:34 -0700 |
commit | 3dae34e217320324dd0db9953b9ba77c2419ab34 (patch) | |
tree | d356676c6c8741f22ccdc05238e896f66ee62b79 | |
parent | 4f6fb19662331afd90539103cd0d2691e72c54b9 (diff) | |
download | rails-3dae34e217320324dd0db9953b9ba77c2419ab34.tar.gz rails-3dae34e217320324dd0db9953b9ba77c2419ab34.tar.bz2 rails-3dae34e217320324dd0db9953b9ba77c2419ab34.zip |
fix set_pk_sequence and add a test for it.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/schema_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 47e030e981..849d41c83c 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -303,7 +303,7 @@ module ActiveRecord if pk if sequence - quoted_sequence = quote_column_name(sequence) + quoted_sequence = quote_table_name(sequence) select_value <<-end_sql, 'SCHEMA' SELECT setval('#{quoted_sequence}', #{value}) diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb index 6f40b0d2de..350cb3e065 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb @@ -388,6 +388,14 @@ class SchemaTest < ActiveRecord::TestCase assert_equal "1", @connection.select_value("SELECT nextval('#{sequence_name}')") end + def test_set_pk_sequence + table_name = "#{SCHEMA_NAME}.#{PK_TABLE_NAME}" + _, sequence_name = @connection.pk_and_sequence_for table_name + @connection.set_pk_sequence! table_name, 123 + assert_equal "124", @connection.select_value("SELECT nextval('#{sequence_name}')") + @connection.reset_pk_sequence! table_name + end + private def columns(table_name) @connection.send(:column_definitions, table_name).map do |name, type, default| |