Permalink
Browse files

validate uniqueness with limit in utf8

[#2653 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 87e2c18 commit c5896bfd8432f6b7a1c6cb06486c5c85eafe9450 Elise Huard committed with jeremy Aug 9, 2009
@@ -119,7 +119,7 @@ def validates_uniqueness_of(*attr_names)
comparison_operator = "IS ?"
elsif column.text?
comparison_operator = "#{connection.case_sensitive_equality_operator} ?"
- value = column.limit ? value.to_s[0, column.limit] : value.to_s
+ value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s
else
comparison_operator = "= ?"
end
@@ -238,6 +238,16 @@ def test_validate_uniqueness_with_limit
assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
end
+ def test_validate_uniqueness_with_limit_and_utf8
+ with_kcode('UTF8') do
+ # Event.title is limited to 5 characters
+ e1 = Event.create(:title => "一二三四五")
+ assert e1.valid?, "Could not create an event with a unique, 5 character title"
+ e2 = Event.create(:title => "一二三四五六七八")
+ assert !e2.valid?, "Created an event whose title, with limit taken into account, is not unique"
+ end
+ end
+
def test_validate_straight_inheritance_uniqueness
w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
assert w1.valid?, "Saving w1"

0 comments on commit c5896bf

Please sign in to comment.