Index: test/validations_test.rb =================================================================== --- test/validations_test.rb (リビジョン 3499) +++ test/validations_test.rb (作業コピー) @@ -365,6 +365,30 @@ assert !Topic.create("title" => "monkey", "content" => "abc").valid? end + def kcode_scope(kcode) + orig_kcode = $KCODE + $KCODE = 'UTF8' + begin + yield + ensure + $KCODE = orig_kcode + end + end + + def test_validates_length_of_utf8 + kcode_scope('UTF8') do + Topic.validates_length_of :title, :minimum => 5 + + t = Topic.create("title" => "日本語環境", "content" => "whatever") + assert t.valid? + + t.title = "日本語" + assert !t.valid? + assert t.errors.on(:title) + assert_equal "is too short (min is 5 characters)", t.errors["title"] + end + end + def test_validates_length_of_using_minimum Topic.validates_length_of :title, :minimum => 5 Index: lib/active_record/validations.rb =================================================================== --- lib/active_record/validations.rb (リビジョン 3499) +++ lib/active_record/validations.rb (作業コピー) @@ -459,7 +459,7 @@ message = (options[:message] || options[message_options[option]]) % option_value validates_each(attrs, options) do |record, attr, value| - record.errors.add(attr, message) unless !value.nil? and value.size.method(validity_checks[option])[option_value] + record.errors.add(attr, message) unless !value.nil? and value.split(//).size.method(validity_checks[option])[option_value] end end end