<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=147741" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tomhughes">@tomhughes</a> <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=360803" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gravitystorm">@gravitystorm</a>  How should <code>display_name: nil</code> be handled?</p>
<p>The database has a NOT NULL constraint, but the validations explicitly state <code>allow_nil: true</code> and the original tests expected nil to pass</p>
<p><a href="https://github.com/openstreetmap/openstreetmap-website/blob/b931d6f516d049ac42fcd70f33f130c252f5d0a9/test/unit/user_test.rb#L65-L69">https://github.com/openstreetmap/openstreetmap-website/blob/b931d6f516d049ac42fcd70f33f130c252f5d0a9/test/unit/user_test.rb#L65-L69</a></p>
<pre><code>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?
</code></pre>
<p>I've figured out why the validations were rejecting nil (the leading/trailing whitespaces validations were triggering on nil)</p>
<p>The new code now allows for a nil value to actually be valid now, providing thats the actual desired behaviour..</p>
<p>So, should nil be a valid value for display_name at the rails-level validations? (even though the database will reject it!) It doesn't really make sense to me to not validate against it</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/2044#issuecomment-435736677">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABWnLfTxJPJoTsbhTmV0ksQJlke-YYdSks5ur6H8gaJpZM4YNX4E">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABWnLV9OmOYkpYi_DdhjgmKUGShT6e8Iks5ur6H8gaJpZM4YNX4E.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openstreetmap/openstreetmap-website","title":"openstreetmap/openstreetmap-website","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/openstreetmap/openstreetmap-website"}},"updates":{"snippets":[{"icon":"PERSON","message":"@jguthrie100 in #2044: @tomhughes @gravitystorm  How should `display_name: nil` be handled?\r\n\r\nThe database has a NOT NULL constraint, but the validations explicitly state `allow_nil: true` and the original tests expected nil to pass\r\n\r\nhttps://github.com/openstreetmap/openstreetmap-website/blob/b931d6f516d049ac42fcd70f33f130c252f5d0a9/test/unit/user_test.rb#L65-L69\r\n\r\n    user.display_name = nil\r\n    # Don't understand why it isn't allowing a nil value, \r\n    # when the validates statements specifically allow it\r\n    # It appears the database does not allow null values\r\n    assert !user.valid?\r\n\r\nI've figured out why the validations were rejecting nil (the leading/trailing whitespaces validations were triggering on nil)\r\n\r\nThe new code now allows for a nil value to actually be valid now, providing thats the actual desired behaviour..\r\n\r\nSo, should nil be a valid value for display_name at the rails-level validations? (even though the database will reject it!) It doesn't really make sense to me to not validate against it"}],"action":{"name":"View Pull Request","url":"https://github.com/openstreetmap/openstreetmap-website/pull/2044#issuecomment-435736677"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/2044#issuecomment-435736677",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/2044#issuecomment-435736677",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [openstreetmap/openstreetmap-website] Specifiy invalid chars in username error message (#2044)",
"sections": [
{
"text": "",
"activityTitle": "**Jamie Guthrie**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@jguthrie100",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"issueId\": 2044,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close pull request",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"PullRequestClose\",\n\"repositoryFullName\": \"openstreetmap/openstreetmap-website\",\n\"pullRequestId\": 2044\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/openstreetmap/openstreetmap-website/pull/2044#issuecomment-435736677"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 406158852\n}"
}
],
"themeColor": "26292E"
}
]</script>