Skip to content
This repository
Browse code

PostgreSQL: correctly parse negative integer column defaults. Referen…

…ces #3776.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3554 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 5991e5c789da5adc260ceb9ba77da31d65991fbc 1 parent d49a5fc
Jeremy Kemper jeremy authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* PostgreSQL: correctly parse negative integer column defaults. #3776 [bellis@deepthought.org]
  4 +
3 5 * Fix problems with count when used with :include [Jeremy Hopple and Kevin Clark]
4 6
5 7 * ActiveRecord::RecordInvalid now states which validations failed in its default error message [Tobias Luetke]
2  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -468,7 +468,7 @@ def default_value(value)
468 468 return $1 if value =~ /^'(.*)'::(bpchar|text|character varying)$/
469 469
470 470 # Numeric values
471   - return value if value =~ /^[0-9]+(\.[0-9]*)?/
  471 + return value if value =~ /^-?[0-9]+(\.[0-9]*)?/
472 472
473 473 # Date / Time magic values
474 474 return Time.now.to_s if value =~ /^now\(\)|^\('now'::text\)::(date|timestamp)/i
14 activerecord/test/defaults_test.rb
... ... @@ -0,0 +1,14 @@
  1 +require 'abstract_unit'
  2 +require 'fixtures/default'
  3 +
  4 +class DefaultsTest < Test::Unit::TestCase
  5 + if %w(PostgreSQL).include? ActiveRecord::Base.connection.adapter_name
  6 + def test_default_integers
  7 + default = Default.new
  8 + assert_instance_of(Fixnum, default.positive_integer)
  9 + assert_equal(default.positive_integer, 1)
  10 + assert_instance_of(Fixnum, default.negative_integer)
  11 + assert_equal(default.negative_integer, -1)
  12 + end
  13 + end
  14 +end
4 activerecord/test/fixtures/db_definitions/postgresql.sql
@@ -111,7 +111,9 @@ CREATE TABLE defaults (
111 111 fixed_time timestamp default '2004-01-01 00:00:00.000000-00',
112 112 char1 char(1) default 'Y',
113 113 char2 character varying(50) default 'a varchar field',
114   - char3 text default 'a text field'
  114 + char3 text default 'a text field',
  115 + positive_integer integer default 1,
  116 + negative_integer integer default -1
115 117 );
116 118
117 119 CREATE TABLE auto_id_tests (

0 comments on commit 5991e5c

Please sign in to comment.
Something went wrong with that request. Please try again.