Permalink
Browse files

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
  • Loading branch information...
1 parent 6e1012f commit cd6beacfb3f503fe28410a67f155bb4509e76819 @jeremy jeremy committed Nov 20, 2006
View
2 activerecord/CHANGELOG
@@ -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]
View
5 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -88,8 +88,9 @@ class MysqlColumn < Column #:nodoc:
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 @@ def simplified_type(field_type)
# 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
View
2 activerecord/test/defaults_test.rb
@@ -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

0 comments on commit cd6beac

Please sign in to comment.