Permalink
Browse files

test, regression test for unparsable PostgreSQL defaults.

This test was inspired by #14866. That PR would break this
functionality and we should make sure we notice that in the future.
  • Loading branch information...
1 parent 33fcdff commit 83e0544204a1b0125af15e1ea0e54aa30b2266ab @senny senny committed May 8, 2014
Showing with 17 additions and 0 deletions.
  1. +17 −0 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -396,6 +396,23 @@ def test_only_warn_on_first_encounter_of_unknown_oid
reset_connection
end
+ def test_unparsed_defaults_are_at_least_set_when_saving
+ with_example_table "id SERIAL PRIMARY KEY, number INTEGER NOT NULL DEFAULT (4 + 4) * 2 / 4" do
+ number_klass = Class.new(ActiveRecord::Base) do
+ self.table_name = 'ex'
+ end
+ column = number_klass.columns_hash["number"]
+ assert_nil column.default
+ assert_nil column.default_function
+
+ first_number = number_klass.new
+ assert_nil first_number.number
+
+ first_number.save!
+ assert_equal 4, first_number.reload.number
+ end
+ end
+
private
def insert(ctx, data)
binds = data.map { |name, value|

0 comments on commit 83e0544

Please sign in to comment.