]> git.openstreetmap.org Git - rails.git/commitdiff
testing the display name
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Thu, 17 Jul 2008 10:44:06 +0000 (10:44 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Thu, 17 Jul 2008 10:44:06 +0000 (10:44 +0000)
test/unit/user_test.rb

index 583b06e69492dce35a7d2a49fb4192e837ef1804..489f76a1da842b9770a95584e084258e7881e791 100644 (file)
@@ -63,6 +63,25 @@ class UserTest < Test::Unit::TestCase
     user.display_name = ""
     assert !user.valid?
     user.display_name = nil
+    # Don't understand why it isn't allowing a nil value, 
+    # when the validates statements specifically allow it
+    # It appears the database does not allow null values
     assert !user.valid?
   end
+  
+  def test_display_name_valid
+    ok = [ "Name", "'me", "he\"", "#ping", "<hr>"]
+    bad = [ "<hr/>", "test@example.com", "s/f", "/", ";", ".", ",", "?", "/;.,?" ]
+    ok.each do |display_name|
+      user = users(:normal_user)
+      user.display_name = display_name
+      assert user.valid?, "#{display_name} is invalid, when it should be"
+    end
+    
+    bad.each do |display_name|
+      user = users(:normal_user)
+      user.display_name = display_name
+      assert !user.valid?, "#{display_name} is valid when it shouldn't be"
+    end
+  end
 end