aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-21 16:20:28 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-21 16:20:28 -0200
commita595fc1c56e5e9f4620bf5f248c87e9cb1e31b2f (patch)
treeeb8e26100ee98d991aa8adf911ef8377cbaa24e7
parent5a254c20581cccbab30b816e1efc604dce190179 (diff)
downloadrails-a595fc1c56e5e9f4620bf5f248c87e9cb1e31b2f.tar.gz
rails-a595fc1c56e5e9f4620bf5f248c87e9cb1e31b2f.tar.bz2
rails-a595fc1c56e5e9f4620bf5f248c87e9cb1e31b2f.zip
Escape the parentheses in the default function regexp
This is causing every default value in PostreSQL database to being handled as default function. Fixes #12581
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 771a150eae..c1cc905606 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -151,7 +151,7 @@ module ActiveRecord
private
def has_default_function?(default_value, default)
- !default_value && (%r{\w+(.*)} === default)
+ !default_value && (%r{\w+\(.*\)} === default)
end
def extract_limit(sql_type)
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 32f86f9c88..1ee8e60924 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -202,6 +202,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r(primary_key: "movieid"), match[1], "non-standard primary key not preserved"
end
+ def test_schema_dump_should_use_false_as_default
+ output = standard_dump
+ assert_match %r{t\.boolean\s+"has_fun",.+default: false}, output
+ end
+
if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
def test_schema_dump_should_not_add_default_value_for_mysql_text_field
output = standard_dump