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

put_project_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: 9d226db09ef6b75b80ce5e55085d0f924900eb93 (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
# frozen_string_literal: true

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

RSpec.describe RuboCop::Cop::PutProjectRoutesUnderScope do
  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 '-' do
        resource :issues
      end

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

  it 'does not register an offense when resource inside the scope' do
    expect_no_offenses(<<~PATTERN)
      scope '-' 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 '-' 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 '-' do
        get '/'
      end
    PATTERN
  end
end