diff options
author | Douwe Maan <douwe@selenight.nl> | 2018-01-31 19:51:05 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2018-02-06 21:06:05 +0300 |
commit | 8d69436c901a3eee674e72c67d91de3994d30e0c (patch) | |
tree | c8071b0c0c78f2f711d51999793a2b66d9a9aea9 /spec/models/user_spec.rb | |
parent | 2d5f10b2a7f05b29ca5869b2d1acb53d5bcbf50b (diff) |
Validate user namespace before saving so that errors persist on model
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 011416cc176..24d4d8f1741 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -101,7 +101,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 @@ -132,6 +132,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 @@ -2623,7 +2640,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, /Route path foo has been taken before. Please use another one, Route is invalid/) + expect { user2.save! }.to raise_error(ActiveRecord::RecordInvalid, /Namespace route path foo has been taken before/) end end |