summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorSanad Liaquat <sliaquat@gitlab.com>2018-09-21 14:10:20 +0000
committerDouwe Maan <douwe@gitlab.com>2018-09-21 14:10:20 +0000
commit0896d6942d30e3cc743c85dcc8fe9699a2a02289 (patch)
tree05d2e8d6808de79160e4b2a7aefa64bea2c3d001 /spec/rubocop
parentf93200897703a7610ee054d050ef92acdc7eeb1f (diff)
downloadgitlab-ce-0896d6942d30e3cc743c85dcc8fe9699a2a02289.tar.gz
Fix leading slash in redirects and add cop
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
new file mode 100644
index 00000000000..c9eb61ccc72
--- /dev/null
+++ b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'rubocop'
+require_relative '../../../rubocop/cop/avoid_route_redirect_leading_slash'
+
+describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ before do
+ allow(cop).to receive(:in_routes?).and_return(true)
+ end
+
+ it 'registers an offense when redirect has a leading slash' do
+ expect_offense(<<~PATTERN.strip_indent)
+ root to: redirect("/-/route")
+ ^^^^^^^^^^^^^^^^^^^^ Do not use a leading "/" in route redirects
+ PATTERN
+ end
+
+ it 'does not register an offense when redirect does not have a leading slash' do
+ expect_no_offenses(<<~PATTERN.strip_indent)
+ root to: redirect("-/route")
+ PATTERN
+ end
+
+ it 'autocorrect `/-/route` to `-/route`' do
+ expect(autocorrect_source('redirect("/-/route")')).to eq('redirect("-/route")')
+ end
+end