diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/rubocop/cop/graphql/enum_values_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql/enum_values_spec.rb')
-rw-r--r-- | spec/rubocop/cop/graphql/enum_values_spec.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/enum_values_spec.rb b/spec/rubocop/cop/graphql/enum_values_spec.rb new file mode 100644 index 00000000000..5609c86d9ec --- /dev/null +++ b/spec/rubocop/cop/graphql/enum_values_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' +require_relative '../../../../rubocop/cop/graphql/enum_values' + +RSpec.describe RuboCop::Cop::Graphql::EnumValues do + it 'adds an offense when enum value is not uppercase' do + expect_offense(<<~ENUM) + module Types + class FakeEnum < BaseEnum + graphql_name 'Fake' + + value 'downcase', description: "Downcase." + ^^^^^^^^^^ #{described_class::MSG} + end + end + ENUM + end + + context 'when values are set dynamically' do + it 'adds an offense when enum value is set without `:upcase`' do + expect_offense(<<~ENUM) + VALUES = ['FOO', 'bar'] + + module Types + class FakeEnum < BaseEnum + graphql_name 'Fake' + + VALUES.each do |val| + value val, description: "Dynamic value." + ^^^ #{described_class::MSG} + end + end + end + ENUM + end + + it 'adds no offense when enum value is deprecated' do + expect_no_offenses(<<~ENUM) + module Types + class FakeEnum < BaseEnum + graphql_name 'Fake' + + value 'foo', deprecated: { reason: 'Use something else' } + end + end + ENUM + end + + it 'adds no offense when enum value is uppercased literally' do + expect_no_offenses(<<~'ENUM') + module Types + class FakeEnum < BaseEnum + graphql_name 'Fake' + + value 'FOO' + end + end + ENUM + end + + it 'adds no offense when enum value is calling upcased' do + expect_no_offenses(<<~'ENUM') + VALUES = ['FOO', 'bar'] + + module Types + class FakeEnum < BaseEnum + graphql_name 'Fake' + + VALUES.each do |val| + value val.underscore.upcase, description: "Dynamic value." + value "#{field.upcase.tr(' ', '_')}_ASC" + end + end + end + ENUM + end + end +end |