diff options
author | Michael Kozono <mkozono@gmail.com> | 2018-01-05 01:16:13 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-01-18 21:28:55 +0300 |
commit | 5d57030e46bffcf21f1ea763d031f38330506061 (patch) | |
tree | 3c987338302fc49e4cef12f194e2ca3850853541 /spec | |
parent | 792e9ed7fa46d236c01fb14c8ad7f9b4ea4dee59 (diff) |
Delete conflicting orphaned routes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/route_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 8a3b1034f3c..88f54fd10e5 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -79,6 +79,13 @@ 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) @@ -378,4 +385,58 @@ describe Route do end end end + + describe '#delete_conflicting_orphaned_routes' do + context 'when there is a conflicting route' do + let!(:conflicting_group) { create(:group, path: 'foo') } + + before do + route.path = conflicting_group.route.path + end + + context 'when the route is orphaned' do + let!(:offending_route) { conflicting_group.route } + + before do + Group.delete(conflicting_group) # Orphan the route + end + + it 'deletes the orphaned route' do + expect do + route.valid? + end.to change { described_class.count }.from(2).to(1) + end + + it 'passes validation, as usual' do + 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 + 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 + expect(route.valid?).to be_truthy + end + end + end end |