mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #10884 from dmarkow/pg_fix_default_quotes
Handle single quotes in PostgreSQL default column values
This commit is contained in:
commit
12e1817835
2 changed files with 26 additions and 1 deletions
|
@ -84,7 +84,7 @@ module ActiveRecord
|
|||
$1
|
||||
# Character types
|
||||
when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/m
|
||||
$1
|
||||
$1.gsub(/''/, "'")
|
||||
# Binary data types
|
||||
when /\A'(.*)'::bytea\z/m
|
||||
$1
|
||||
|
|
|
@ -39,6 +39,31 @@ class DefaultTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class DefaultStringsTest < ActiveRecord::TestCase
|
||||
class DefaultString < ActiveRecord::Base; end
|
||||
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.create_table :default_strings do |t|
|
||||
t.string :string_col, default: "Smith"
|
||||
t.string :string_col_with_quotes, default: "O'Connor"
|
||||
end
|
||||
DefaultString.reset_column_information
|
||||
end
|
||||
|
||||
def test_default_strings
|
||||
assert_equal "Smith", DefaultString.new.string_col
|
||||
end
|
||||
|
||||
def test_default_strings_containing_single_quotes
|
||||
assert_equal "O'Connor", DefaultString.new.string_col_with_quotes
|
||||
end
|
||||
|
||||
teardown do
|
||||
@connection.drop_table :default_strings
|
||||
end
|
||||
end
|
||||
|
||||
if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
|
||||
class DefaultsTestWithoutTransactionalFixtures < ActiveRecord::TestCase
|
||||
# ActiveRecord::Base#create! (and #save and other related methods) will
|
||||
|
|
Loading…
Reference in a new issue