diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/models/route_spec.rb | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/models/route_spec.rb')
-rw-r--r-- | spec/models/route_spec.rb | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 0489a4fb995..929eaca85f7 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -22,13 +22,6 @@ RSpec.describe Route do end describe 'callbacks' do - context 'before validation' do - it 'calls #delete_conflicting_orphaned_routes' do - expect(route).to receive(:delete_conflicting_orphaned_routes) - route.valid? - end - end - context 'after update' do it 'calls #create_redirect_for_old_path' do expect(route).to receive(:create_redirect_for_old_path) @@ -44,7 +37,7 @@ RSpec.describe Route do context 'after create' do it 'calls #delete_conflicting_redirects' do route.destroy! - new_route = described_class.new(source: group, path: group.path) + new_route = described_class.new(source: group, path: group.path, namespace: group) expect(new_route).to receive(:delete_conflicting_redirects) new_route.save! end @@ -275,7 +268,7 @@ RSpec.describe Route do end end - describe '#delete_conflicting_orphaned_routes' do + describe 'conflicting routes validation' do context 'when there is a conflicting route' do let!(:conflicting_group) { create(:group, path: 'foo') } @@ -283,47 +276,31 @@ RSpec.describe Route do route.path = conflicting_group.route.path end - context 'when the route is orphaned' do + context 'when deleting the conflicting route' do let!(:offending_route) { conflicting_group.route } - before do - Group.delete(conflicting_group) # Orphan the route - end + it 'does not delete the original route' do + # before deleting the route, check its there + expect(Route.where(path: offending_route.path).count).to eq(1) - it 'deletes the orphaned route' do expect do - route.valid? - end.to change { described_class.count }.from(2).to(1) - end + Group.delete(conflicting_group) # delete group with conflicting route + end.to change { described_class.count }.by(-1) - it 'passes validation, as usual' do + # check the conflicting route is gone + expect(Route.where(path: offending_route.path).count).to eq(0) + expect(route.path).to eq(offending_route.path) expect(route.valid?).to be_truthy end end - context 'when the route is not orphaned' do - it 'does not delete the conflicting route' do - expect do - route.valid? - end.not_to change { described_class.count } - end - - it 'fails validation, as usual' do - expect(route.valid?).to be_falsey - end + it 'fails validation' do + expect(route.valid?).to be_falsey end end context 'when there are no conflicting routes' do - it 'does not delete any routes' do - route - - expect do - route.valid? - end.not_to change { described_class.count } - end - - it 'passes validation, as usual' do + it 'passes validation' do expect(route.valid?).to be_truthy end end |