summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-05-01 16:48:05 -0700
committerMichael Kozono <mkozono@gmail.com>2017-05-05 12:11:58 -0700
commita0368e91310a3b2c0e9e0b717f931a482eb0b90a (patch)
tree7286025822c9e53ed8ff660ecfe276a3ee818034 /spec
parent7d02bcd2e0165a90a9f2c1edb34b064ff76afd69 (diff)
downloadgitlab-ce-a0368e91310a3b2c0e9e0b717f931a482eb0b90a.tar.gz
Create redirect routes on path change
Diffstat (limited to 'spec')
-rw-r--r--spec/models/route_spec.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb
index 171a51fcc5b..c95043469a8 100644
--- a/spec/models/route_spec.rb
+++ b/spec/models/route_spec.rb
@@ -26,7 +26,20 @@ describe Route, models: true do
end
end
- describe '#rename_descendants' do
+ describe '.direct_descendant_routes' do
+ let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
+ let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
+ let!(:another_group) { create(:group, path: 'other') }
+ let!(:similar_group) { create(:group, path: 'gitllab') }
+ let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) }
+
+ it 'returns correct routes' do
+ expect(Route.direct_descendant_routes('git_lab')).to match_array([nested_group.route])
+ expect(Route.direct_descendant_routes('git_lab/test')).to match_array([deep_nested_group.route])
+ end
+ end
+
+ describe '#rename_direct_descendant_routes' do
let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
let!(:similar_group) { create(:group, path: 'gitlab-org', name: 'gitlab-org') }
@@ -77,4 +90,23 @@ describe Route, models: true do
end
end
end
+
+ describe '#create_redirect_if_path_changed' do
+ context 'if the path changed' do
+ it 'creates a RedirectRoute for the old path' do
+ route.path = 'new-path'
+ route.save!
+ redirect = route.source.redirect_routes.first
+ expect(redirect.path).to eq('git_lab')
+ end
+ end
+
+ context 'if the path did not change' do
+ it 'does not create a RedirectRoute' do
+ route.updated_at = Time.zone.now.utc
+ route.save!
+ expect(route.source.redirect_routes).to be_empty
+ end
+ end
+ end
end