Skip to content

Commit

Permalink
Test for forged '' default before it's typecast. Closes #6156.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5596 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 20, 2006
1 parent 6e1012f commit cd6beac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion activerecord/CHANGELOG
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


* Run validations in the order they were declared. #6657 [obrie] * 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] * Simplify association proxy implementation by factoring construct_scope out of method_missing. #6643 [martin]


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class MysqlColumn < Column #:nodoc:
TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text]) TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text])


def initialize(name, default, sql_type = nil, null = true) def initialize(name, default, sql_type = nil, null = true)
@original_default = default
super super
self.default = nil if missing_default_forged_as_empty_string? @default = nil if missing_default_forged_as_empty_string?
end end


private private
Expand All @@ -107,7 +108,7 @@ def simplified_type(field_type)
# Test whether the column has default '', is not null, and is not # Test whether the column has default '', is not null, and is not
# a type allowing default ''. # a type allowing default ''.
def missing_default_forged_as_empty_string? 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
end end


Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/defaults_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DefaultTest < Test::Unit::TestCase
def test_nil_defaults_for_not_null_columns def test_nil_defaults_for_not_null_columns
column_defaults = column_defaults =
if current_adapter?(:MysqlAdapter) if current_adapter?(:MysqlAdapter)
{ 'id' => nil, 'name' => '', 'course_id' => 0 } { 'id' => nil, 'name' => '', 'course_id' => nil }
else else
{ 'id' => nil, 'name' => nil, 'course_id' => nil } { 'id' => nil, 'name' => nil, 'course_id' => nil }
end end
Expand Down

0 comments on commit cd6beac

Please sign in to comment.