Commit c20df30d authored by Stan Hu's avatar Stan Hu

Merge branch '211360-group-wiki-controller' into 'master'

Add group wiki controller

See merge request gitlab-org/gitlab!34383
parents 58e88479 c754a8e9
......@@ -2,6 +2,7 @@
module WikiActions
include DiffHelper
include PreviewMarkdown
include SendsBlob
include Gitlab::Utils::StrongMemoize
extend ActiveSupport::Concern
......
......@@ -81,10 +81,6 @@ class Projects::ApplicationController < ApplicationController
end
end
def apply_diff_view_cookie!
set_secure_cookie(:diff_view, params.delete(:view), type: COOKIE_TYPE_PERMANENT) if params[:view].present?
end
def require_pages_enabled!
not_found unless @project.pages_available?
end
......
......@@ -9,6 +9,7 @@ class Projects::BlobController < Projects::ApplicationController
include ActionView::Helpers::SanitizeHelper
include RedirectsForMissingPathOnTree
include SourcegraphDecorator
include DiffHelper
prepend_before_action :authenticate_user!, only: [:edit]
......
......@@ -2,7 +2,6 @@
class Projects::WikisController < Projects::ApplicationController
include WikiActions
include PreviewMarkdown
alias_method :container, :project
......
......@@ -174,6 +174,10 @@ module DiffHelper
end
end
def apply_diff_view_cookie!
set_secure_cookie(:diff_view, params.delete(:view), type: CookiesHelper::COOKIE_TYPE_PERMANENT) if params[:view].present?
end
private
def diff_btn(title, name, selected)
......
......@@ -3,7 +3,7 @@ scope(controller: :wikis) do
get :git_access
get :pages
get :new
get '/', to: redirect('%{namespace_id}/%{project_id}/wikis/home')
get '/', to: redirect { |params, request| "#{request.path}/home" }
post '/', to: 'wikis#create'
end
......
import initWikis from '~/pages/shared/wikis';
document.addEventListener('DOMContentLoaded', initWikis);
# frozen_string_literal: true
class Groups::WikisController < Groups::ApplicationController
include WikiActions
alias_method :container, :group
private
def authorize_read_wiki!
access_denied! unless can?(current_user, :read_wiki, group)
end
def authorize_create_wiki!
access_denied! unless can?(current_user, :create_wiki, group)
end
def authorize_admin_wiki!
access_denied! unless can?(current_user, :admin_wiki, group)
end
end
......@@ -13,6 +13,8 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
module: :groups,
as: :group,
constraints: { group_id: Gitlab::PathRegex.full_namespace_route_regex }) do
draw :wiki
resources :group_members, only: [], concerns: :access_requestable do
patch :override, on: :member
end
......
......@@ -35,15 +35,14 @@ module EE
end
end
override :wiki_page_url
def wiki_page_url(wiki, page, **options)
override :wiki_url
def wiki_url(wiki, **options)
if wiki.container.is_a?(Group)
# TODO: Use the new route for group wikis once we add it.
# https://gitlab.com/gitlab-org/gitlab/-/issues/211360
instance.group_canonical_url(wiki.container, **options) + "/-/wikis/#{page.to_param}"
else
super
options[:controller] = 'groups/wikis'
options[:group_id] = wiki.container
end
super
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::WikisController do
it_behaves_like 'wiki controller actions' do
let(:container) { create(:group, :public) }
let(:routing_params) { { group_id: container } }
before do
container.add_owner(user)
stub_feature_flags(group_wiki: container)
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(group_wiki: false)
end
using RSpec::Parameterized::TableSyntax
where(:method, :action) do
:get | :new
:get | :pages
:post | :create
:get | :show
:get | :edit
:get | :history
:post | :preview_markdown
:put | :update
:delete | :destroy
end
with_them do
it 'returns a 404 error' do
process action, method: method, params: routing_params.merge(id: 'page')
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
end
......@@ -5,6 +5,10 @@ require 'spec_helper'
RSpec.describe 'Group routing', "routing" do
include RSpec::Rails::RoutingExampleGroup
before do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
end
describe 'subgroup "boards"' do
it 'shows group show page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq/boards', any_args).and_return(true)
......@@ -13,43 +17,29 @@ RSpec.describe 'Group routing', "routing" do
end
it 'shows boards index page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/boards')).to route_to('groups/boards#index', group_id: 'gitlabhq')
end
end
describe 'security' do
it 'shows group dashboard' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/security/dashboard')).to route_to('groups/security/dashboard#show', group_id: 'gitlabhq')
end
it 'lists vulnerabilities' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/security/vulnerability_findings')).to route_to('groups/security/vulnerability_findings#index', group_id: 'gitlabhq')
end
it 'shows vulnerability summary' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/security/vulnerability_findings/summary')).to route_to('groups/security/vulnerability_findings#summary', group_id: 'gitlabhq')
end
it 'shows vulnerability history' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/security/vulnerability_findings/history')).to route_to('groups/security/vulnerability_findings#history', group_id: 'gitlabhq')
end
end
describe 'dependency proxy for containers' do
before do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
end
context 'image name without namespace' do
it 'routes to #manifest' do
expect(get('/v2/gitlabhq/dependency_proxy/containers/ruby/manifests/2.3.6'))
......@@ -87,41 +77,48 @@ RSpec.describe 'Group routing', "routing" do
describe 'hooks' do
it 'routes to hooks edit page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/hooks/2/edit')).to route_to('groups/hooks#edit', group_id: 'gitlabhq', id: '2')
end
end
describe 'packages' do
it 'routes to packages index page' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(get('/groups/gitlabhq/-/packages')).to route_to('groups/packages#index', group_id: 'gitlabhq')
end
end
describe 'issues' do
it 'routes post to #bulk_update' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(post('/groups/gitlabhq/-/issues/bulk_update')).to route_to('groups/issues#bulk_update', group_id: 'gitlabhq')
end
end
describe 'merge_requests' do
it 'routes post to #bulk_update' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(post('/groups/gitlabhq/-/merge_requests/bulk_update')).to route_to('groups/merge_requests#bulk_update', group_id: 'gitlabhq')
end
end
describe 'epics' do
it 'routes post to #bulk_update' do
allow(Group).to receive(:find_by_full_path).with('gitlabhq', any_args).and_return(true)
expect(post('/groups/gitlabhq/-/epics/bulk_update')).to route_to('groups/epics#bulk_update', group_id: 'gitlabhq')
end
end
# group_wikis_git_access GET /:group_id/-/wikis/git_access(.:format) groups/wikis#git_access
# group_wikis_pages GET /:group_id/-/wikis/pages(.:format) groups/wikis#pages
# group_wikis_new GET /:group_id/-/wikis/new(.:format) groups/wikis#new
# POST /:group_id/-/wikis(.:format) groups/wikis#create
# group_wiki_edit GET /:group_id/-/wikis/*id/edit groups/wikis#edit
# group_wiki_history GET /:group_id/-/wikis/*id/history groups/wikis#history
# group_wiki_preview_markdown POST /:group_id/-/wikis/*id/preview_markdown groups/wikis#preview_markdown
# group_wiki GET /:group_id/-/wikis/*id groups/wikis#show
# PUT /:group_id/-/wikis/*id groups/wikis#update
# DELETE /:group_id/-/wikis/*id groups/wikis#destroy
describe Groups::WikisController, 'routing' do
it_behaves_like 'wiki routing' do
let(:base_path) { '/groups/gitlabhq/-/wikis' }
let(:base_params) { { group_id: 'gitlabhq' } }
end
end
end
......@@ -85,9 +85,11 @@ module Gitlab
def wiki_url(wiki, **options)
return wiki_page_url(wiki, Wiki::HOMEPAGE, **options) unless options[:action]
options[:controller] = 'projects/wikis'
options[:namespace_id] = wiki.container.namespace
options[:project_id] = wiki.container
if wiki.container.is_a?(Project)
options[:controller] = 'projects/wikis'
options[:namespace_id] = wiki.container.namespace
options[:project_id] = wiki.container
end
instance.url_for(**options)
end
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Projects::WikisController do
it_behaves_like 'wiki controller actions' do
let(:container) { create(:project, :public, :repository, namespace: user.namespace) }
let(:container) { create(:project, :public, namespace: user.namespace) }
let(:routing_params) { { namespace_id: container.namespace, project_id: container } }
end
end
......@@ -3,71 +3,13 @@
require 'spec_helper'
RSpec.describe 'project routing' do
let(:base_params) { { namespace_id: 'gitlab', project_id: 'gitlabhq' } }
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)
end
# Shared examples for a resource inside a Project
#
# By default it tests all the default REST actions: index, create, new, edit,
# show, update, and destroy. You can remove actions by customizing the
# `actions` variable.
#
# It also expects a `controller` variable to be available which defines both
# the path to the resource as well as the controller name.
#
# Examples
#
# # Default behavior
# it_behaves_like 'RESTful project resources' do
# let(:controller) { 'issues' }
# end
#
# # Customizing actions
# it_behaves_like 'RESTful project resources' do
# let(:actions) { [:index] }
# let(:controller) { 'issues' }
# end
#
# # Different controller name and path
# it_behaves_like 'RESTful project resources' do
# let(:controller) { 'pages_domains' }
# let(:controller_path) { 'pages/domains' }
# end
shared_examples 'RESTful project resources' do
let(:actions) { [:index, :create, :new, :edit, :show, :update, :destroy] }
let(:controller_path) { controller }
it 'to #index' do
expect(get("/gitlab/gitlabhq/#{controller_path}")).to route_to("projects/#{controller}#index", namespace_id: 'gitlab', project_id: 'gitlabhq') if actions.include?(:index)
end
it 'to #create' do
expect(post("/gitlab/gitlabhq/#{controller_path}")).to route_to("projects/#{controller}#create", namespace_id: 'gitlab', project_id: 'gitlabhq') if actions.include?(:create)
end
it 'to #new' do
expect(get("/gitlab/gitlabhq/#{controller_path}/new")).to route_to("projects/#{controller}#new", namespace_id: 'gitlab', project_id: 'gitlabhq') if actions.include?(:new)
end
it 'to #edit' do
expect(get("/gitlab/gitlabhq/#{controller_path}/1/edit")).to route_to("projects/#{controller}#edit", namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') if actions.include?(:edit)
end
it 'to #show' do
expect(get("/gitlab/gitlabhq/#{controller_path}/1")).to route_to("projects/#{controller}#show", namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') if actions.include?(:show)
end
it 'to #update' do
expect(put("/gitlab/gitlabhq/#{controller_path}/1")).to route_to("projects/#{controller}#update", namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') if actions.include?(:update)
end
it 'to #destroy' do
expect(delete("/gitlab/gitlabhq/#{controller_path}/1")).to route_to("projects/#{controller}#destroy", namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') if actions.include?(:destroy)
end
end
# projects POST /projects(.:format) projects#create
# new_project GET /projects/new(.:format) projects#new
# files_project GET /:id/files(.:format) projects#files
......@@ -149,25 +91,19 @@ RSpec.describe 'project routing' do
end
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
# project_wikis_git_access GET /:project_id/-/wikis/git_access(.:format) projects/wikis#git_access
# project_wikis_pages GET /:project_id/-/wikis/pages(.:format) projects/wikis#pages
# project_wikis_new GET /:project_id/-/wikis/new(.:format) projects/wikis#new
# POST /:project_id/-/wikis(.:format) projects/wikis#create
# project_wiki_edit GET /:project_id/-/wikis/*id/edit projects/wikis#edit
# project_wiki_history GET /:project_id/-/wikis/*id/history projects/wikis#history
# project_wiki_preview_markdown POST /:project_id/-/wikis/*id/preview_markdown projects/wikis#preview_markdown
# project_wiki GET /:project_id/-/wikis/*id projects/wikis#show
# PUT /:project_id/-/wikis/*id projects/wikis#update
# DELETE /:project_id/-/wikis/*id projects/wikis#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')
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')
end
it_behaves_like 'RESTful project resources' do
let(:actions) { [:create, :edit, :show, :destroy] }
let(:controller) { 'wikis' }
let(:controller_path) { '/-/wikis' }
it_behaves_like 'wiki routing' do
let(:base_path) { '/gitlab/gitlabhq/-/wikis' }
end
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/wikis", "/gitlab/gitlabhq/-/wikis"
......@@ -246,10 +182,9 @@ RSpec.describe 'project routing' do
# project_deploy_key PATCH /:project_id/deploy_keys/:id(.:format) deploy_keys#update
# DELETE /:project_id/deploy_keys/:id(.:format) deploy_keys#destroy
describe Projects::DeployKeysController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:actions) { [:index, :new, :create, :edit, :update] }
let(:controller) { 'deploy_keys' }
let(:controller_path) { '/-/deploy_keys' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index new create edit update] }
let(:base_path) { '/gitlab/gitlabhq/-/deploy_keys' }
end
end
......@@ -257,10 +192,9 @@ RSpec.describe 'project routing' do
# POST /:project_id/protected_branches(.:format) protected_branches#create
# project_protected_branch DELETE /:project_id/protected_branches/:id(.:format) protected_branches#destroy
describe Projects::ProtectedBranchesController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:actions) { [:index, :create, :destroy] }
let(:controller) { 'protected_branches' }
let(:controller_path) { '/-/protected_branches' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index create destroy] }
let(:base_path) { '/gitlab/gitlabhq/-/protected_branches' }
end
end
......@@ -320,10 +254,9 @@ RSpec.describe 'project routing' do
expect(get('/gitlab/gitlabhq/-/merge_requests/1/diffs')).to route_to('projects/merge_requests#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1', tab: 'diffs')
end
it_behaves_like 'RESTful project resources' do
let(:controller) { 'merge_requests' }
let(:actions) { [:index, :edit, :show, :update] }
let(:controller_path) { '/-/merge_requests' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index edit show update] }
let(:base_path) { '/gitlab/gitlabhq/-/merge_requests' }
end
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/merge_requests", "/gitlab/gitlabhq/-/merge_requests"
......@@ -428,9 +361,9 @@ RSpec.describe 'project routing' do
expect(post('/gitlab/gitlabhq/hooks/1/test')).to route_to('projects/hooks#test', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1')
end
it_behaves_like 'RESTful project resources' do
let(:actions) { [:index, :create, :destroy, :edit, :update] }
let(:controller) { 'hooks' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index create destroy edit update] }
let(:base_path) { '/gitlab/gitlabhq/hooks' }
end
end
......@@ -465,10 +398,9 @@ RSpec.describe 'project routing' do
# POST /:project_id/commits(.:format) commits#create
# project_commit GET /:project_id/commits/:id(.:format) commits#show
describe Projects::CommitsController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:actions) { [:show] }
let(:controller) { 'commits' }
let(:controller_path) { '/-/commits' }
it_behaves_like 'resource routing' do
let(:actions) { %i[show] }
let(:base_path) { '/gitlab/gitlabhq/-/commits' }
end
it 'to #show' do
......@@ -485,10 +417,9 @@ RSpec.describe 'project routing' do
# PUT /:project_id/project_members/:id(.:format) project_members#update
# DELETE /:project_id/project_members/:id(.:format) project_members#destroy
describe Projects::ProjectMembersController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:actions) { [:index, :create, :update, :destroy] }
let(:controller) { 'project_members' }
let(:controller_path) { '/-/project_members' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index create update destroy] }
let(:base_path) { '/gitlab/gitlabhq/-/project_members' }
end
end
......@@ -501,10 +432,9 @@ RSpec.describe 'project routing' do
# DELETE /:project_id/milestones/:id(.:format) milestones#destroy
# promote_project_milestone POST /:project_id/milestones/:id/promote milestones#promote
describe Projects::MilestonesController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:controller) { 'milestones' }
let(:actions) { [:index, :create, :new, :edit, :show, :update] }
let(:controller_path) { '/-/milestones' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index create new edit show update] }
let(:base_path) { '/gitlab/gitlabhq/-/milestones' }
end
it 'to #promote' do
......@@ -534,10 +464,9 @@ RSpec.describe 'project routing' do
expect(post('/gitlab/gitlabhq/-/issues/bulk_update')).to route_to('projects/issues#bulk_update', namespace_id: 'gitlab', project_id: 'gitlabhq')
end
it_behaves_like 'RESTful project resources' do
let(:controller) { 'issues' }
let(:actions) { [:index, :create, :new, :edit, :show, :update] }
let(:controller_path) { '/-/issues' }
it_behaves_like 'resource routing' do
let(:actions) { %i[index create new edit show update] }
let(:base_path) { '/gitlab/gitlabhq/-/issues' }
end
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/issues", "/gitlab/gitlabhq/-/issues"
......@@ -558,9 +487,9 @@ RSpec.describe 'project routing' do
)
end
it_behaves_like 'RESTful project resources' do
let(:actions) { [:create, :destroy] }
let(:controller) { 'notes' }
it_behaves_like 'resource routing' do
let(:actions) { %i[create destroy] }
let(:base_path) { '/gitlab/gitlabhq/notes' }
end
end
......@@ -749,10 +678,10 @@ RSpec.describe 'project routing' do
end
describe Projects::PagesDomainsController, 'routing' do
it_behaves_like 'RESTful project resources' do
let(:actions) { [:show, :new, :create, :destroy] }
let(:controller) { 'pages_domains' }
let(:controller_path) { 'pages/domains' }
it_behaves_like 'resource routing' do
let(:actions) { %i[show new create destroy] }
let(:base_path) { '/gitlab/gitlabhq/pages/domains' }
let(:id) { 'my.domain.com' }
end
it 'to #destroy with a valid domain name' do
......
......@@ -147,6 +147,7 @@ RSpec.shared_examples 'wiki controller actions' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('shared/wikis/show')
expect(assigns(:page).title).to eq(wiki_title)
expect(assigns(:sidebar_wiki_entries)).to contain_exactly(an_instance_of(WikiPage))
expect(assigns(:sidebar_limited)).to be(false)
......@@ -159,6 +160,7 @@ RSpec.shared_examples 'wiki controller actions' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('shared/wikis/show')
expect(flash[:notice]).to eq(_('The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.'))
end
end
......@@ -167,19 +169,37 @@ RSpec.shared_examples 'wiki controller actions' do
context 'when the page does not exist' do
let(:id) { 'does not exist' }
before do
subject
end
context 'when the user can create pages' do
before do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('shared/wikis/edit')
end
it 'builds a new wiki page with the id as the title' do
expect(assigns(:page).title).to eq(id)
end
context 'when a random_title param is present' do
let(:random_title) { true }
it 'builds a new wiki page with the id as the title' do
expect(assigns(:page).title).to eq(id)
it 'builds a new wiki page with no title' do
expect(assigns(:page).title).to be_empty
end
end
end
context 'when a random_title param is present' do
let(:random_title) { true }
context 'when the user cannot create pages' do
before do
sign_out(:user)
end
it 'shows the empty state' do
subject
it 'builds a new wiki page with no title' do
expect(assigns(:page).title).to be_empty
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('shared/wikis/empty')
end
end
end
......@@ -195,6 +215,7 @@ RSpec.shared_examples 'wiki controller actions' do
it 'delivers the file with the correct headers' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq('true')
expect(response.cache_control[:public]).to be(false)
......@@ -208,6 +229,7 @@ RSpec.shared_examples 'wiki controller actions' do
it 'renders json in a correct format' do
post :preview_markdown, params: routing_params.merge(id: 'page/path', text: '*Markdown* text')
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.keys).to match_array(%w(body references))
end
end
......
# frozen_string_literal: true
# Shared examples for resource routes.
#
# By default it tests all the default REST actions: index, create, new, edit,
# show, update, and destroy. You can remove actions by customizing the
# `actions` variable.
#
# The subject is expected to be an instance of the controller under test.
#
# It also expects a `base_path` variable to be available which defines the
# base path of the controller, and a `base_params` variable which
# defines the route params the base path maps to.
#
# Examples
#
# # Default behavior
# describe Projects::CommitsController, 'routing' do
# it_behaves_like 'resource routing' do
# let(:base_path) { '/gitlab/gitlabhq/-/commits' }
# let(:base_params) { { namespace_id: 'gitlab', project_id: 'gitlabhq' } }
# end
# end
#
# # Customizing actions
# it_behaves_like 'resource routing' do
# let(:base_path) { '/gitlab/gitlabhq/-/commits' }
#
# # Specify default actions
# let(:actions) { [:index] }
#
# # Add custom actions by passing a hash with action names
# # as keys, and the HTTP method and path as values.
# let(:additional_actions) do
# {
# preview_markdown: [:post, '/:id/preview_markdown'],
# }
# end
# end
RSpec.shared_examples 'resource routing' do
let(:controller) { described_class.controller_path }
let(:id) { '123' }
let(:default_actions) do
{
index: [:get, ''],
show: [:get, '/:id'],
new: [:get, '/new'],
create: [:post, ''],
edit: [:get, '/:id/edit'],
update: [:put, '/:id'],
destroy: [:delete, '/:id']
}
end
let(:actions) { default_actions.keys }
let(:additional_actions) { {} }
it 'routes resource actions', :aggregate_failures do
selected_actions = default_actions.slice(*actions).merge(additional_actions)
selected_actions.each do |action, (method, action_path)|
expected_params = base_params.merge(controller: controller.to_s, action: action.to_s)
if action_path.include?(':id')
action_path = action_path.sub(':id', id)
expected_params[:id] = id
end
expect(public_send(method, "#{base_path}#{action_path}")).to route_to(expected_params)
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'wiki routing' do
it_behaves_like 'resource routing' do
let(:id) { 'directory/page' }
let(:actions) { %i[show new create edit update destroy] }
let(:additional_actions) do
{
pages: [:get, '/pages'],
history: [:get, '/:id/history'],
git_access: [:get, '/git_access'],
preview_markdown: [:post, '/:id/preview_markdown']
}
end
end
it 'redirects the base path to the home page', type: :request do
expect(get(base_path)).to redirect_to("#{base_path}/home")
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment