summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb
blob: 3caf153c2fadbcdce01a89fb0bc46baa5b641460 (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
64
65
66
67
68
69
70
# frozen_string_literal: true

RSpec.shared_examples 'Gitlab-style deprecations' do
  describe 'validations' do
    it 'raises an informative error if `deprecation_reason` is used' do
      expect { subject(deprecation_reason: 'foo') }.to raise_error(
        ArgumentError,
        'Use `deprecated` property instead of `deprecation_reason`. ' \
        'See https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#deprecating-fields-arguments-and-enum-values'
      )
    end

    it 'raises an error if a required property is missing', :aggregate_failures do
      expect { subject(deprecated: { milestone: '1.10' }) }.to raise_error(
        ArgumentError,
        include("Reason can't be blank")
      )
      expect { subject(deprecated: { reason: 'Deprecation reason' }) }.to raise_error(
        ArgumentError,
        include("Milestone can't be blank")
      )
    end

    it 'raises an error if milestone is not a String', :aggregate_failures do
      expect { subject(deprecated: { milestone: 1.10, reason: 'Deprecation reason' }) }.to raise_error(
        ArgumentError,
        include("Milestone must be a string")
      )
    end
  end

  it 'adds a formatted `deprecated_reason` to the subject' do
    deprecable = subject(deprecated: { milestone: '1.10', reason: 'Deprecation reason' })

    expect(deprecable.deprecation_reason).to eq('Deprecation reason. Deprecated in 1.10.')
  end

  it 'appends to the description if given' do
    deprecable = subject(
      deprecated: { milestone: '1.10', reason: 'Deprecation reason' },
      description: 'Deprecable description.'
    )

    expect(deprecable.description).to eq('Deprecable description. Deprecated in 1.10: Deprecation reason.')
  end

  it 'does not append to the description if it is absent' do
    deprecable = subject(deprecated: { milestone: '1.10', reason: 'Deprecation reason' })

    expect(deprecable.description).to be_nil
  end

  it 'adds information about the replacement if provided' do
    deprecable = subject(deprecated: { milestone: '1.10', reason: :renamed, replacement: 'Foo.bar' })

    expect(deprecable.deprecation_reason).to include 'Please use `Foo.bar`'
  end

  it 'supports named reasons: renamed' do
    deprecable = subject(deprecated: { milestone: '1.10', reason: :renamed })

    expect(deprecable.deprecation_reason).to include 'This was renamed.'
  end

  it 'supports named reasons: alpha' do
    deprecable = subject(deprecated: { milestone: '1.10', reason: :alpha })

    expect(deprecable.deprecation_reason).to include 'This feature is in Alpha'
  end
end