diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-23 03:06:01 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-23 03:06:01 +0000 |
commit | 8c7eab92cd0009f55cb999bbade43e0f969c137e (patch) | |
tree | 180cac6632448a211ddbe555191574c98e8dc385 /spec/routing | |
parent | dffeff5520e861dc6e7319b690c573186bbbd22e (diff) | |
download | gitlab-ce-8c7eab92cd0009f55cb999bbade43e0f969c137e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/routing')
-rw-r--r-- | spec/routing/project_routing_spec.rb | 42 | ||||
-rw-r--r-- | spec/routing/wiki_routing_spec.rb | 103 |
2 files changed, 133 insertions, 12 deletions
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index acdbf064a73..3e57bb70287 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -3,9 +3,12 @@ require 'spec_helper' describe 'project routing' do before do allow(Project).to receive(:find_by_full_path).and_return(false) - allow(Project).to receive(:find_by_full_path).with('gitlab/gitlabhq', any_args).and_return(true) + allow(Project).to receive(:find_by_full_path).with('gitlab/gitlabhq', any_args).and_return(project) end + set(:namespace) { create(:namespace, name: 'gitlab') } + set(:project) { create(:project, namespace: namespace, name: 'gitlabhq') } + # Shared examples for a resource inside a Project # # By default it tests all the default REST actions: index, create, new, edit, @@ -145,24 +148,39 @@ describe 'project routing' do it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/autocomplete_sources/labels", "/gitlab/gitlabhq/-/autocomplete_sources/labels" end - # pages_project_wikis GET /:project_id/wikis/pages(.:format) projects/wikis#pages - # history_project_wiki GET /:project_id/wikis/:id/history(.:format) projects/wikis#history - # project_wikis POST /:project_id/wikis(.:format) projects/wikis#create - # edit_project_wiki GET /:project_id/wikis/:id/edit(.:format) projects/wikis#edit - # project_wiki GET /:project_id/wikis/:id(.:format) projects/wikis#show - # DELETE /:project_id/wikis/:id(.:format) projects/wikis#destroy + # GET /:project_id/wikis/pages(.:format) projects/wikis#pages + # GET /:project_id/-/wiki_pages/:id/history(.:format) projects/wiki_pages#history + # POST /:project_id/-/wiki_pages(.:format) projects/wiki_pages#create + # GET /:project_id/-/wiki_pages/:id/edit(.:format) projects/wiki_pages#edit + # GET /:project_id/-/wiki_pages/:id(.:format) projects/wiki_pages#show + # DELETE /:project_id/-/wiki_pages/:id(.:format) projects/wiki_pages#destroy describe Projects::WikisController, 'routing' do - it 'to #pages' do - expect(get('/gitlab/gitlabhq/wikis/pages')).to route_to('projects/wikis#pages', namespace_id: 'gitlab', project_id: 'gitlabhq') + let(:wiki) { ProjectWiki.new(project, project.owner) } + let(:wiki_page) { create(:wiki_page, wiki: wiki) } + + it '#pages' do + expect(get('/gitlab/gitlabhq/wikis/pages')) + .to route_to('projects/wikis#pages', + namespace_id: 'gitlab', + project_id: 'gitlabhq') end - it 'to #history' do - expect(get('/gitlab/gitlabhq/wikis/1/history')).to route_to('projects/wikis#history', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') + describe '#history' do + let(:history_path) { project_wiki_history_path(project, wiki_page) } + + it 'routes to history' do + expect(get(history_path)) + .to route_to('projects/wiki_pages#history', + namespace_id: namespace.path, + project_id: project.name, + id: wiki_page.slug) + end end it_behaves_like 'RESTful project resources' do let(:actions) { [:create, :edit, :show, :destroy] } - let(:controller) { 'wikis' } + let(:controller) { 'wiki_pages' } + let(:controller_path) { '-/wiki_pages' } end end diff --git a/spec/routing/wiki_routing_spec.rb b/spec/routing/wiki_routing_spec.rb new file mode 100644 index 00000000000..94349dbaa74 --- /dev/null +++ b/spec/routing/wiki_routing_spec.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# We build URIs to wiki pages manually in various places (most notably +# in markdown generation). To ensure these do not get out of sync, these +# tests verify that our path generation assumptions are sound. +describe 'Wiki path generation assumptions' do + set(:project) { create(:project, :public, :repository) } + + let(:project_wiki) { ProjectWiki.new(project, project.owner) } + let(:some_page_name) { 'some-wiki-page' } + let(:wiki_page) do + create(:wiki_page, wiki: project_wiki, attrs: { title: some_page_name }) + end + + describe 'WikiProject#wiki_page_path', 'routing' do + it 'is consistent with routing to wiki#show' do + uri = URI.parse(project_wiki.wiki_page_path) + path = ::File.join(uri.path, some_page_name) + + expect(get('/' + path)).to route_to('projects/wiki_pages#show', + id: some_page_name, + namespace_id: project.namespace.to_param, + project_id: project.to_param) + end + end + + describe 'project_wiki_path', 'routing' do + describe 'GET' do + it 'routes to the :show action' do + path = project_wiki_path(project, wiki_page) + + expect(get('/' + path)).to route_to('projects/wiki_pages#show', + id: wiki_page.slug, + namespace_id: project.namespace.to_param, + project_id: project.to_param) + end + end + end + + describe 'project_wiki_pages_new_path', 'routing' do + describe 'GET' do + it 'routes to the :new action' do + path = project_wiki_pages_new_path(project) + + expect(get('/' + path)).to route_to('projects/wiki_pages#new', + namespace_id: project.namespace.to_param, + project_id: project.to_param) + end + end + end + + # Early versions of the wiki paths routed all wiki pages at + # /wikis/:id - this test exists to guarantee that we support + # old URIs that may be out there, saved in bookmarks, on other wikis, etc. + describe 'legacy route support', type: 'request' do + let(:path) { ::File.join(project_wikis_path(project), some_page_name) } + + before do + get(path) + end + + it 'routes to new wiki paths' do + dest = project_wiki_path(project, wiki_page) + + expect(response).to redirect_to(dest) + end + + context 'the page is nested in a directory' do + let(:some_page_name) { 'some-dir/some-deep-dir/some-page' } + let(:path) { ::File.join(project_wikis_path(project), some_page_name) } + + it 'still routes correctly' do + dest = project_wiki_path(project, wiki_page) + + expect(response).to redirect_to(dest) + end + end + + context 'the user requested the old history path' do + let(:some_page_name) { 'some-dir/some-deep-dir/some-page' } + let(:path) { ::File.join(project_wikis_path(project), some_page_name, 'history') } + + it 'redirects to the new history path' do + dest = project_wiki_history_path(project, wiki_page) + + expect(response).to redirect_to(dest) + end + end + + context 'the user requested the old edit path' do + let(:some_page_name) { 'some-dir/some-deep-dir/some-page' } + let(:path) { ::File.join(project_wikis_path(project), some_page_name, 'edit') } + + it 'redirects to the new history path' do + dest = project_wiki_edit_path(project, wiki_page) + + expect(response).to redirect_to(dest) + end + end + end +end |