diff options
Diffstat (limited to 'spec')
10 files changed, 112 insertions, 11 deletions
diff --git a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb index 1768f97de54..07c2c6606d8 100644 --- a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb +++ b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb @@ -136,7 +136,7 @@ RSpec.describe Gitlab::Database::Partitioning::SlidingListStrategy do end context 'when some partitions are true for detach_partition_if' do - let(:detach_partition_if) { ->(p) { p != 5 } } + let(:detach_partition_if) { ->(p) { p.value != 5 } } it 'is the leading set of partitions before that value' do # should not contain partition 2 since it's the default value for the partition column diff --git a/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb b/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb new file mode 100644 index 00000000000..5858986dfc8 --- /dev/null +++ b/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe Gitlab::Graphql::Limit::FieldCallCount do + include GraphqlHelpers + + let(:field_args) { {} } + let(:owner) { fresh_object_type } + let(:field) do + ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) do + extension(::Gitlab::Graphql::Limit::FieldCallCount, limit: 1) + end + end + + let(:query) do + GraphQL::Query.new(GitlabSchema) + end + + def resolve_value + resolve_field(field, { value: 'foo' }, object_type: owner, query: query) + end + + it 'allows the call' do + expect { resolve_value }.not_to raise_error + end + + it 'executes the extension' do + expect(described_class).to receive(:new).and_call_original + + resolve_value + end + + it 'returns an error when the field is called multiple times' do + resolve_value + + expect(resolve_value).to be_an_instance_of(Gitlab::Graphql::Errors::LimitError) + end + + context 'when limit is not specified' do + let(:field) do + ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) do + extension(::Gitlab::Graphql::Limit::FieldCallCount) + end + end + + it 'returns an error' do + expect(resolve_value).to be_an_instance_of(Gitlab::Graphql::Errors::ArgumentError) + end + end + + context 'when the field is not extended' do + let(:field) do + ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) + end + + it 'allows the call' do + expect { resolve_value }.not_to raise_error + end + + it 'does not execute the extension' do + expect(described_class).not_to receive(:new) + + resolve_value + end + end +end diff --git a/spec/models/loose_foreign_keys/deleted_record_spec.rb b/spec/models/loose_foreign_keys/deleted_record_spec.rb index 9ee5b7340f3..a909252a78c 100644 --- a/spec/models/loose_foreign_keys/deleted_record_spec.rb +++ b/spec/models/loose_foreign_keys/deleted_record_spec.rb @@ -66,7 +66,7 @@ RSpec.describe LooseForeignKeys::DeletedRecord, type: :model do let(:partition_manager) { Gitlab::Database::Partitioning::PartitionManager.new(described_class) } describe 'next_partition_if callback' do - let(:active_partition) { described_class.partitioning_strategy.active_partition.value } + let(:active_partition) { described_class.partitioning_strategy.active_partition } subject(:value) { described_class.partitioning_strategy.next_partition_if.call(active_partition) } @@ -98,7 +98,7 @@ RSpec.describe LooseForeignKeys::DeletedRecord, type: :model do end describe 'detach_partition_if callback' do - let(:active_partition) { described_class.partitioning_strategy.active_partition.value } + let(:active_partition) { described_class.partitioning_strategy.active_partition } subject(:value) { described_class.partitioning_strategy.detach_partition_if.call(active_partition) } diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index 68230e81c50..5bce6a2cc3f 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -105,7 +105,7 @@ RSpec.describe PersonalAccessToken do end end - describe '.last_used_before' do + describe '.last_used_before_or_unused' do let(:last_used_at) { 1.month.ago.beginning_of_hour } let!(:unused_token) { create(:personal_access_token) } let!(:used_token) do @@ -135,7 +135,7 @@ RSpec.describe PersonalAccessToken do ) end - subject { described_class.last_used_before(last_used_at) } + subject { described_class.last_used_before_or_unused(last_used_at) } it { is_expected.to contain_exactly(old_unused_token, old_formerly_used_token) } end diff --git a/spec/requests/api/graphql/ci/jobs_spec.rb b/spec/requests/api/graphql/ci/jobs_spec.rb index 8c4ab13fc35..fa8fb1d54aa 100644 --- a/spec/requests/api/graphql/ci/jobs_spec.rb +++ b/spec/requests/api/graphql/ci/jobs_spec.rb @@ -335,4 +335,35 @@ RSpec.describe 'Query.project.pipeline' do end end end + + context 'when querying jobs for multiple projects' do + let(:query) do + %( + query { + projects { + nodes { + jobs { + nodes { + name + } + } + } + } + } + ) + end + + before do + create_list(:project, 2).each do |project| + project.add_developer(user) + create(:ci_build, project: project) + end + end + + it 'returns an error' do + post_graphql(query, current_user: user) + + expect_graphql_errors_to_include [/"jobs" field can be requested only for 1 Project\(s\) at a time./] + end + end end diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb index 8bd002d533a..bd90753f9ad 100644 --- a/spec/requests/api/graphql/ci/runner_spec.rb +++ b/spec/requests/api/graphql/ci/runner_spec.rb @@ -429,6 +429,8 @@ RSpec.describe 'Query.runner(id)' do 'jobs' => nil, # returning jobs not allowed for more than 1 runner (see RunnerJobsResolver) 'projectCount' => nil, 'projects' => nil) + + expect_graphql_errors_to_include [/"jobs" field can be requested only for 1 CiRunner\(s\) at a time./] end end end diff --git a/spec/requests/api/graphql/environments/deployments_query_spec.rb b/spec/requests/api/graphql/environments/deployments_query_spec.rb index 95cc83e9463..6da00057449 100644 --- a/spec/requests/api/graphql/environments/deployments_query_spec.rb +++ b/spec/requests/api/graphql/environments/deployments_query_spec.rb @@ -238,8 +238,9 @@ RSpec.describe 'Environments Deployments query' do ) end - it 'returnes an error for preventing N+1 queries' do - expect(subject['errors'][0]['message']).to include('exceeds max complexity') + it 'returns an error for preventing N+1 queries' do + expect(subject['errors'][0]['message']) + .to include('"deployments" field can be requested only for 1 Environment(s) at a time.') end end diff --git a/spec/requests/api/graphql/group/packages_spec.rb b/spec/requests/api/graphql/group/packages_spec.rb index adee556db3a..cf8736db5af 100644 --- a/spec/requests/api/graphql/group/packages_spec.rb +++ b/spec/requests/api/graphql/group/packages_spec.rb @@ -39,7 +39,7 @@ RSpec.describe 'getting a package list for a group' do it 'returns an error for the second group and data for the first' do expect(a_packages_names).to contain_exactly(group_one_package.name) - expect_graphql_errors_to_include [/Packages can be requested only for one group at a time/] + expect_graphql_errors_to_include [/"packages" field can be requested only for 1 Group\(s\) at a time./] expect(graphql_data_at(:b, :packages)).to be(nil) end end diff --git a/spec/requests/api/graphql/packages/package_spec.rb b/spec/requests/api/graphql/packages/package_spec.rb index c28b37db5af..b9bb57c7df7 100644 --- a/spec/requests/api/graphql/packages/package_spec.rb +++ b/spec/requests/api/graphql/packages/package_spec.rb @@ -97,7 +97,7 @@ RSpec.describe 'package details' do expect(graphql_data_at(:a, :name)).to eq(composer_package.name) - expect_graphql_errors_to_include [/Package details can be requested only for one package at a time/] + expect_graphql_errors_to_include [/"package" field can be requested only for 1 Query\(s\) at a time./] expect(graphql_data_at(:b)).to be(nil) end end diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 44e005d6022..9d745f2cb70 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -130,11 +130,12 @@ module GraphqlHelpers current_user: :not_given, # The current user (specified explicitly, overrides ctx[:current_user]) schema: GitlabSchema, # A specific schema instance object_type: described_class, # The `BaseObject` type this field belongs to - arg_style: :internal_prepared # Args are in internal format, but should use more rigorous processing + arg_style: :internal_prepared, # Args are in internal format, but should use more rigorous processing + query: nil # Query to evaluate the field ) field = to_base_field(field, object_type) ctx[:current_user] = current_user unless current_user == :not_given - query = GraphQL::Query.new(schema, context: ctx.to_h) + query ||= GraphQL::Query.new(schema, context: ctx.to_h) extras[:lookahead] = negative_lookahead if extras[:lookahead] == :not_given && field.extras.include?(:lookahead) query_ctx = query.context |