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

graphql_name_position_spec.rb « graphql « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 42cc398ed84e44290d83406953841cf64c3084b6 (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
# frozen_string_literal: true

require 'fast_spec_helper'

require_relative '../../../../rubocop/cop/graphql/graphql_name_position'

RSpec.describe RuboCop::Cop::Graphql::GraphqlNamePosition do
  subject(:cop) { described_class.new }

  it 'adds an offense when graphql_name is not on the first line' do
    expect_offense(<<~TYPE)
      module Types
        class AType < BaseObject
        ^^^^^^^^^^^^^^^^^^^^^^^^ `graphql_name` should be the first line of the class: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#naming-conventions
          field :a_thing
          field :another_thing
          graphql_name 'ATypeName'
        end
      end
    TYPE
  end

  it 'does not add an offense for classes that have no call to graphql_name' do
    expect_no_offenses(<<~TYPE.strip)
      module Types
        class AType < BaseObject
          authorize :an_ability, :second_ability

          field :a_thing
        end
      end
    TYPE
  end

  it 'does not add an offense for classes that only call graphql_name' do
    expect_no_offenses(<<~TYPE.strip)
      module Types
        class AType < BaseObject
          graphql_name 'ATypeName'
        end
      end
    TYPE
  end
end