summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-20 09:09:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-20 09:09:22 +0000
commit196ada0844fff7642463fbd08a44609a1e1fa713 (patch)
tree7160cacde0b36d73a35e84d685824dd8633dfc0a /spec
parente380e59ef5d1aa03922df49626c302da5eb30699 (diff)
downloadgitlab-ce-196ada0844fff7642463fbd08a44609a1e1fa713.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/types/base_field_spec.rb62
-rw-r--r--spec/lib/gitlab/graphql/docs/renderer_spec.rb12
-rw-r--r--spec/models/namespace_spec.rb2
3 files changed, 68 insertions, 8 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb
index 9251eaee3df..915700f6437 100644
--- a/spec/graphql/types/base_field_spec.rb
+++ b/spec/graphql/types/base_field_spec.rb
@@ -175,7 +175,7 @@ describe Types::BaseField do
let(:flag) { :test_flag }
it 'prepends the description' do
- expect(field.description). to eq 'Test description. Available only when feature flag `test_flag` is enabled.'
+ expect(field.description). to eq 'Test description. Available only when feature flag `test_flag` is enabled'
end
context 'falsey feature_flag values' do
@@ -196,4 +196,64 @@ describe Types::BaseField do
end
end
end
+
+ describe '`deprecated` property' do
+ def test_field(args = {})
+ base_args = { name: 'test', type: GraphQL::STRING_TYPE, null: true }
+
+ described_class.new(**base_args.merge(args))
+ end
+
+ describe 'validations' do
+ it 'raises an informative error if `deprecation_reason` is used' do
+ expect { test_field(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'
+ )
+ end
+
+ it 'raises an error if a required property is missing', :aggregate_failures do
+ expect { test_field(deprecated: { milestone: 1.0 }) }.to raise_error(
+ ArgumentError,
+ 'Please provide a `reason` within `deprecated`'
+ )
+ expect { test_field(deprecated: { reason: 'Deprecation reason' }) }.to raise_error(
+ ArgumentError,
+ 'Please provide a `milestone` within `deprecated`'
+ )
+ end
+ end
+
+ it 'adds a formatted `deprecated_reason` to the field' do
+ field = test_field(deprecated: { milestone: 1.0, reason: 'Deprecation reason' })
+
+ expect(field.deprecation_reason).to eq('Deprecation reason. Deprecated in 1.0')
+ end
+
+ it 'appends to the description if given' do
+ field = test_field(
+ deprecated: { milestone: 1.0, reason: 'Deprecation reason' },
+ description: 'Field description'
+ )
+
+ expect(field.description).to eq('Field description. Deprecated in 1.0: Deprecation reason')
+ end
+
+ it 'does not append to the description if it is absent' do
+ field = test_field(deprecated: { milestone: 1.0, reason: 'Deprecation reason' })
+
+ expect(field.description).to be_nil
+ end
+
+ it 'interacts well with the `feature_flag` property' do
+ field = test_field(
+ deprecated: { milestone: 1.0, reason: 'Deprecation reason' },
+ description: 'Field description',
+ feature_flag: 'foo_flag'
+ )
+
+ expect(field.description).to eq('Field description. Available only when feature flag `foo_flag` is enabled. Deprecated in 1.0: Deprecation reason')
+ end
+ end
end
diff --git a/spec/lib/gitlab/graphql/docs/renderer_spec.rb b/spec/lib/gitlab/graphql/docs/renderer_spec.rb
index 5ba70bb8f0a..3982c79e23c 100644
--- a/spec/lib/gitlab/graphql/docs/renderer_spec.rb
+++ b/spec/lib/gitlab/graphql/docs/renderer_spec.rb
@@ -6,7 +6,7 @@ describe Gitlab::Graphql::Docs::Renderer do
describe '#contents' do
# Returns a Schema that uses the given `type`
def mock_schema(type)
- query_type = Class.new(GraphQL::Schema::Object) do
+ query_type = Class.new(Types::BaseObject) do
graphql_name 'QueryType'
field :foo, type, null: true
@@ -27,7 +27,7 @@ describe Gitlab::Graphql::Docs::Renderer do
context 'A type with a field with a [Array] return type' do
let(:type) do
- Class.new(GraphQL::Schema::Object) do
+ Class.new(Types::BaseObject) do
graphql_name 'ArrayTest'
field :foo, [GraphQL::STRING_TYPE], null: false, description: 'A description'
@@ -49,7 +49,7 @@ describe Gitlab::Graphql::Docs::Renderer do
context 'A type with fields defined in reverse alphabetical order' do
let(:type) do
- Class.new(GraphQL::Schema::Object) do
+ Class.new(Types::BaseObject) do
graphql_name 'OrderingTest'
field :foo, GraphQL::STRING_TYPE, null: false, description: 'A description of foo field'
@@ -73,10 +73,10 @@ describe Gitlab::Graphql::Docs::Renderer do
context 'A type with a deprecated field' do
let(:type) do
- Class.new(GraphQL::Schema::Object) do
+ Class.new(Types::BaseObject) do
graphql_name 'DeprecatedTest'
- field :foo, GraphQL::STRING_TYPE, null: false, deprecation_reason: 'This is deprecated', description: 'A description'
+ field :foo, GraphQL::STRING_TYPE, null: false, deprecated: { reason: 'This is deprecated', milestone: 1.0 }, description: 'A description'
end
end
@@ -86,7 +86,7 @@ describe Gitlab::Graphql::Docs::Renderer do
| Name | Type | Description |
| --- | ---- | ---------- |
- | `foo` **{warning-solid}** | String! | **Deprecated:** This is deprecated |
+ | `foo` **{warning-solid}** | String! | **Deprecated:** This is deprecated. Deprecated in 1.0 |
DOC
is_expected.to include(expectation)
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 78b93b303f7..ed7ef8b2b8e 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -194,7 +194,7 @@ describe Namespace do
describe '.find_by_pages_host' do
it 'finds namespace by GitLab Pages host and is case-insensitive' do
- namespace = create(:namespace, name: 'topnamespace')
+ namespace = create(:namespace, name: 'topNAMEspace', path: 'topNAMEspace')
create(:namespace, name: 'annother_namespace')
host = "TopNamespace.#{Settings.pages.host.upcase}"