]> git.openstreetmap.org Git - rails.git/blobdiff - test/models/user_test.rb
Changed User model to not allow nil display_name (w/ tests)
[rails.git] / test / models / user_test.rb
index 168b9c3fa32672510da6eeb021413b2b6136b96f..584f5df0e97c989a2618f25280c16dc5e99ea8a4 100644 (file)
@@ -65,16 +65,13 @@ class UserTest < ActiveSupport::TestCase
   def test_display_name_length
     user = build(:user)
     user.display_name = "123"
-    assert user.valid?, " should allow nil display name"
+    assert user.valid?, "should allow 3 char name name"
     user.display_name = "12"
-    assert !user.valid?, "should not allow 2 char name"
+    assert_not user.valid?, "should not allow 2 char name"
     user.display_name = ""
-    assert_not user.valid?
+    assert_not user.valid?, "should not allow blank/0 char name"
     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_not user.valid?
+    assert_not user.valid?, "should not allow nil value"
   end
 
   def test_display_name_valid
@@ -89,7 +86,8 @@ class UserTest < ActiveSupport::TestCase
            "aa,", "aa?", "/;.,?", "も対応します/", "#ping",
            "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar",
            "new", "terms", "save", "confirm", "confirm-email",
-           "go_public", "reset-password", "forgot-password", "suspended"]
+           "go_public", "reset-password", "forgot-password", "suspended",
+           "trailing whitespace ", " leading whitespace"]
     ok.each do |display_name|
       user = build(:user)
       user.display_name = display_name
@@ -99,7 +97,7 @@ class UserTest < ActiveSupport::TestCase
     bad.each do |display_name|
       user = build(:user)
       user.display_name = display_name
-      assert !user.valid?, "#{display_name} is valid when it shouldn't be"
+      assert_not user.valid?, "#{display_name} is valid when it shouldn't be"
     end
   end