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

put_group_routes_under_scope_spec.rb « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46b50d7690bc91e9f279668b67f006de1a7c1029 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../rubocop/cop/put_group_routes_under_scope'

RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do
  include CopHelper

  subject(:cop) { described_class.new }

  %w[resource resources get post put patch delete].each do |route_method|
    it "registers an offense when route is outside scope for `#{route_method}`" do
      offense = "#{route_method} :notes"
      marker = '^' * offense.size

      expect_offense(<<~PATTERN)
      scope(path: 'groups/*group_id/-', module: :groups) do
        resource :issues
      end

      #{offense}
      #{marker} Put new group routes under /-/ scope
      PATTERN
    end
  end

  it 'does not register an offense when resource inside the scope' do
    expect_no_offenses(<<~PATTERN)
      scope(path: 'groups/*group_id/-', module: :groups) do
        resource :issues
        resource :notes
      end
    PATTERN
  end

  it 'does not register an offense when resource is deep inside the scope' do
    expect_no_offenses(<<~PATTERN)
      scope(path: 'groups/*group_id/-', module: :groups) do
        resource :issues
        resource :projects do
          resource :issues do
            resource :notes
          end
        end
      end
    PATTERN
  end

  it 'does not register an offense for the root route' do
    expect_no_offenses(<<~PATTERN)
      get '/'
    PATTERN
  end

  it 'does not register an offense for the root route within scope' do
    expect_no_offenses(<<~PATTERN)
      scope(path: 'groups/*group_id/-', module: :groups) do
        get '/'
      end
    PATTERN
  end
end