]> git.openstreetmap.org Git - rails.git/commitdiff
Changed User model to not allow nil display_name (w/ tests)
authorJ Guthrie <jamie.guthrie@gmail.com>
Mon, 5 Nov 2018 15:40:37 +0000 (15:40 +0000)
committerJ Guthrie <jamie.guthrie@gmail.com>
Mon, 5 Nov 2018 15:40:37 +0000 (15:40 +0000)
app/models/user.rb
test/models/user_test.rb

index 0b0d37326a2c8b6b0b9d31849492eb71fcf04825..17985e05f45d1ad56d126b2886d5b20b81f5db48 100644 (file)
@@ -88,7 +88,7 @@ class User < ActiveRecord::Base
                     :default_url => "/assets/:class/:attachment/:style.png",
                     :styles => { :large => "100x100>", :small => "50x50>" }
 
-  validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
+  validates :display_name, :presence => true, :length => 3..255,
                            :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
   validates :display_name, :if => proc { |u| u.display_name_changed? },
                            :uniqueness => { :case_sensitive => false }
index 0e618cd22c86ec3058c0f699c6dfc1730a307bfc..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_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