mirror of
https://github.com/github/rails.git
synced 2026-01-29 00:08:15 -05:00
Test for forged '' default before it's typecast. Closes #6156.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5596 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
* Run validations in the order they were declared. #6657 [obrie]
|
||||
|
||||
* MySQL: detect when a NOT NULL column without a default value is misreported as default ''. Can't detect for string, text, and binary columns since '' is a legitimate default. #6156 [simon@redhillconsulting.com.au, obrie, Jeremy Kemper]
|
||||
* MySQL: detect when a NOT NULL column without a default value is misreported as default ''. Can't detect for string, text, and binary columns since '' is a legitimate default. #6156 [simon@redhillconsulting.com.au, obrie, Jonathan Viney, Jeremy Kemper]
|
||||
|
||||
* Simplify association proxy implementation by factoring construct_scope out of method_missing. #6643 [martin]
|
||||
|
||||
|
||||
@@ -88,8 +88,9 @@ module ActiveRecord
|
||||
TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text])
|
||||
|
||||
def initialize(name, default, sql_type = nil, null = true)
|
||||
@original_default = default
|
||||
super
|
||||
self.default = nil if missing_default_forged_as_empty_string?
|
||||
@default = nil if missing_default_forged_as_empty_string?
|
||||
end
|
||||
|
||||
private
|
||||
@@ -107,7 +108,7 @@ module ActiveRecord
|
||||
# Test whether the column has default '', is not null, and is not
|
||||
# a type allowing default ''.
|
||||
def missing_default_forged_as_empty_string?
|
||||
!null && default == '' && !TYPES_ALLOWING_EMPTY_STRING_DEFAULT.include?(type)
|
||||
!null && @original_default == '' && !TYPES_ALLOWING_EMPTY_STRING_DEFAULT.include?(type)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ class DefaultTest < Test::Unit::TestCase
|
||||
def test_nil_defaults_for_not_null_columns
|
||||
column_defaults =
|
||||
if current_adapter?(:MysqlAdapter)
|
||||
{ 'id' => nil, 'name' => '', 'course_id' => 0 }
|
||||
{ 'id' => nil, 'name' => '', 'course_id' => nil }
|
||||
else
|
||||
{ 'id' => nil, 'name' => nil, 'course_id' => nil }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user