diff options
author | Dylan Markow <dylan@dylanmarkow.com> | 2013-06-07 17:36:37 -0500 |
---|---|---|
committer | Dylan Markow <dylan@dylanmarkow.com> | 2013-06-19 11:03:40 -0500 |
commit | 78f6268977d80f3e6dcb916dd185ef046caf8586 (patch) | |
tree | 5c5e7f4c676bfbfd71b64d2a593401259507a8c2 /activerecord/test | |
parent | 2b763131eacaae5bff9ffb5015fbf367d594dc64 (diff) | |
download | rails-78f6268977d80f3e6dcb916dd185ef046caf8586.tar.gz rails-78f6268977d80f3e6dcb916dd185ef046caf8586.tar.bz2 rails-78f6268977d80f3e6dcb916dd185ef046caf8586.zip |
Handle single quotes in PostgreSQL default column values
PostgreSQL escapes single quotes by using an additional single quote.
When Rails queries the column information, PostgreSQL returns the
default values with the escaped single quotes.
#extract_value_from_default now converts these to one single quote each.
Fixes #10881.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/defaults_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/defaults_test.rb b/activerecord/test/cases/defaults_test.rb index e0cf4adf13..7e3d91e08c 100644 --- a/activerecord/test/cases/defaults_test.rb +++ b/activerecord/test/cases/defaults_test.rb @@ -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 |