From a595fc1c56e5e9f4620bf5f248c87e9cb1e31b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 21 Oct 2013 16:20:28 -0200 Subject: 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 --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 2 +- activerecord/test/cases/schema_dumper_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3