Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/support/shared_examples/routing
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/support/shared_examples/routing')
-rw-r--r--spec/support/shared_examples/routing/resource_routing_shared_examples.rb73
-rw-r--r--spec/support/shared_examples/routing/wiki_routing_shared_examples.rb20
2 files changed, 93 insertions, 0 deletions
diff --git a/spec/support/shared_examples/routing/resource_routing_shared_examples.rb b/spec/support/shared_examples/routing/resource_routing_shared_examples.rb
new file mode 100644
index 00000000000..b98901a57ea
--- /dev/null
+++ b/spec/support/shared_examples/routing/resource_routing_shared_examples.rb
@@ -0,0 +1,73 @@
+# 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
diff --git a/spec/support/shared_examples/routing/wiki_routing_shared_examples.rb b/spec/support/shared_examples/routing/wiki_routing_shared_examples.rb
new file mode 100644
index 00000000000..9289934677e
--- /dev/null
+++ b/spec/support/shared_examples/routing/wiki_routing_shared_examples.rb
@@ -0,0 +1,20 @@
+# 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