Commit acd98810 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-fix-user-namespace_uniq' into 'master'

Properly check for a pre-existing error in `User#namespace_uniq`

Rails adds an empty error to the Errors object even if you just call
`#[]` on it:

```
[1] pry(main)> u = User.last
[2] pry(main)> u.errors.keys
=> []
[3] pry(main)> u.errors[:username].present?
=> false
[4] pry(main)> u.errors.keys
=> [:username]
```

See merge request !3017
parents 204a9895 128757a7
...@@ -373,7 +373,8 @@ class User < ActiveRecord::Base ...@@ -373,7 +373,8 @@ class User < ActiveRecord::Base
def namespace_uniq def namespace_uniq
# Return early if username already failed the first uniqueness validation # Return early if username already failed the first uniqueness validation
return if self.errors[:username].include?('has already been taken') return if self.errors.key?(:username) &&
self.errors[:username].include?('has already been taken')
namespace_name = self.username namespace_name = self.username
existing_namespace = Namespace.by_path(namespace_name) existing_namespace = Namespace.by_path(namespace_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment