Skip to content

Commit

Permalink
fix a serial pk on rails 5.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
urkle committed Dec 14, 2018
1 parent dc6cb03 commit 7ec5928
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/schema_plus/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module ConnectionAdapters
require_relative "core/sql_struct"
require_relative "core/version"

if ActiveRecord.version >= Gem::Version.new('5.2.0.rc1')
if ActiveRecord.version >= Gem::Version.new('5.2')
require_relative "core/active_record/connection_adapters/postgresql/schema_dumper"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module ConnectionAdapters
module PostgreSQL
module PostgreSQL # need two PostgreSQLs because the first gets stripped by schema_monkey
module SchemaDumper

# quick hack fix quoting of column default functions to allow eval() when we
# capture the stream.
#
Expand All @@ -20,7 +19,7 @@ module SchemaDumper
#
def prepare_column_options(column, *) # :nodoc:
spec = super
spec[:default] = "%q{#{column.default_function}}" if column.default_function
spec[:default] = "%q{#{column.default_function}}" if column.default_function && !column.serial?
spec
end

Expand Down
9 changes: 9 additions & 0 deletions spec/dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def after(env)

context TestDumper::Middleware::Dumper::Tables do
Then { expect(dump).to match(/create_table "other".*create_table "#{middleware}".*create_table "things"/m) }

context 'int PK handling in rails 5.2+', postgresql: :only, rails: ['>= 5.2.0'] do
before(:each) do
migration.create_table "inttable", id: :serial do |t|
end
end

Then { expect(dump).to_not match(/create_table "inttable", id: :serial.*default:/m) }
end
end

context TestDumper::Middleware::Dumper::Table do
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
SchemaDev::Rspec.setup

RSpec.configure do |config|

config.filter_run_excluding rails: -> (v) {
rails_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
test = Gem::Requirement.new(v)
!test.satisfied_by?(rails_version)
}
config.warnings = true
config.around(:each) do |example|
ActiveRecord::Migration.suppress_messages do
Expand Down

0 comments on commit 7ec5928

Please sign in to comment.