summaryrefslogtreecommitdiff
path: root/spec/models/user_spec.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-02-06 18:40:09 +0000
committerRobert Speicher <rspeicher@gmail.com>2018-02-14 14:17:36 -0600
commit2008eb9900e2231f2e08f39720ff8c72189e8435 (patch)
tree8df742044e341fc3244b91714ee8c8e609acd16a /spec/models/user_spec.rb
parentede2f4e5c5b62d4e96228097a19a3ef21212be42 (diff)
downloadgitlab-ce-2008eb9900e2231f2e08f39720ff8c72189e8435.tar.gz
Merge branch 'dm-user-namespace-route-path-validation' into 'master'
Validate user namespace before saving so that errors persist on model Closes #42140 See merge request gitlab-org/gitlab-ce!16902
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r--spec/models/user_spec.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 8d0eaf565a7..4bd5da1025d 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -103,7 +103,7 @@ describe User do
user = build(:user, username: 'dashboard')
expect(user).not_to be_valid
- expect(user.errors.values).to eq [['dashboard is a reserved name']]
+ expect(user.errors.messages[:username]).to eq ['dashboard is a reserved name']
end
it 'allows child names' do
@@ -134,6 +134,23 @@ describe User do
expect(user.errors.messages[:username].first).to match('cannot be changed if a personal project has container registry tags')
end
end
+
+ context 'when the username was used by another user before' do
+ let(:username) { 'foo' }
+ let!(:other_user) { create(:user, username: username) }
+
+ before do
+ other_user.username = 'bar'
+ other_user.save!
+ end
+
+ it 'is invalid' do
+ user = build(:user, username: username)
+
+ expect(user).not_to be_valid
+ expect(user.errors.messages[:"namespace.route.path"].first).to eq('foo has been taken before. Please use another one')
+ end
+ end
end
it 'has a DB-level NOT NULL constraint on projects_limit' do
@@ -2603,7 +2620,7 @@ describe User do
it 'should raise an ActiveRecord::RecordInvalid exception' do
user2 = build(:user, username: 'foo')
- expect { user2.save! }.to raise_error(ActiveRecord::RecordInvalid, /Path foo has been taken before/)
+ expect { user2.save! }.to raise_error(ActiveRecord::RecordInvalid, /Namespace route path foo has been taken before/)
end
end