diff options
author | Michael Kozono <mkozono@gmail.com> | 2018-01-09 13:06:21 -0800 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2018-01-11 09:24:59 -0800 |
commit | 1dc30595e34eac0fcfa28e0dca2b7a22c02bacc3 (patch) | |
tree | 64a95f7cd5d688633724df9b9cf2815473e03260 /spec/models/route_spec.rb | |
parent | 685780d5b4606dce440ba8121e774fd6e7884ea2 (diff) | |
download | gitlab-ce-1dc30595e34eac0fcfa28e0dca2b7a22c02bacc3.tar.gz |
Revert "Revert "Fix Route validation for unchanged path""
This reverts commit 3576d59ae95a61dd20e997a619dbc6c8e8a70276.
Diffstat (limited to 'spec/models/route_spec.rb')
-rw-r--r-- | spec/models/route_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index ddad6862a63..2f141d96144 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -16,6 +16,66 @@ describe Route do it { is_expected.to validate_presence_of(:source) } it { is_expected.to validate_presence_of(:path) } it { is_expected.to validate_uniqueness_of(:path).case_insensitive } + + describe '#ensure_permanent_paths' do + context 'when the route is not yet persisted' do + let(:new_route) { Route.new(path: 'foo', source: build(:group)) } + + context 'when permanent conflicting redirects exist' do + it 'is invalid' do + redirect = RedirectRoute.new(path: 'foo/bar/baz', source: create(:group), permanent: true) + redirect.save!(validate: false) + + expect(new_route.valid?).to be_falsey + expect(new_route.errors.first[1]).to eq('foo has been taken before. Please use another one') + end + end + + context 'when no permanent conflicting redirects exist' do + it 'is valid' do + expect(new_route.valid?).to be_truthy + end + end + end + + context 'when path has changed' do + before do + route.path = 'foo' + end + + context 'when permanent conflicting redirects exist' do + it 'is invalid' do + redirect = RedirectRoute.new(path: 'foo/bar/baz', source: create(:group), permanent: true) + redirect.save!(validate: false) + + expect(route.valid?).to be_falsey + expect(route.errors.first[1]).to eq('foo has been taken before. Please use another one') + end + end + + context 'when no permanent conflicting redirects exist' do + it 'is valid' do + expect(route.valid?).to be_truthy + end + end + end + + context 'when path has not changed' do + context 'when permanent conflicting redirects exist' do + it 'is valid' do + redirect = RedirectRoute.new(path: 'git_lab/foo/bar', source: create(:group), permanent: true) + redirect.save!(validate: false) + + expect(route.valid?).to be_truthy + end + end + context 'when no permanent conflicting redirects exist' do + it 'is valid' do + expect(route.valid?).to be_truthy + end + end + end + end end describe 'callbacks' do |