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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-25 00:09:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-25 00:09:48 +0300
commitcfc6fe51003de30653a5ce48f1a1b7f46fc9075d (patch)
tree6bb54c97a01467a70dcd3e1909b03e02b6af31b8 /spec
parentaca82d5ba49a8d2cf7ca30ac4ee6dcbd62b47cff (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/mirrors_controller_spec.rb2
-rw-r--r--spec/migrations/remove_additional_application_settings_rows_spec.rb27
-rw-r--r--spec/services/grafana/proxy_service_spec.rb2
-rw-r--r--spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb2
-rw-r--r--spec/services/prometheus/proxy_service_spec.rb2
-rw-r--r--spec/support/helpers/graphql_helpers.rb9
-rw-r--r--spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb92
-rw-r--r--spec/support/shared_examples/requires_variables_shared_example.rb13
8 files changed, 144 insertions, 5 deletions
diff --git a/spec/controllers/projects/mirrors_controller_spec.rb b/spec/controllers/projects/mirrors_controller_spec.rb
index faeade0d737..8cd940978c0 100644
--- a/spec/controllers/projects/mirrors_controller_spec.rb
+++ b/spec/controllers/projects/mirrors_controller_spec.rb
@@ -189,7 +189,7 @@ describe Projects::MirrorsController do
context 'no data in cache' do
it 'requests the cache to be filled and returns a 204 response' do
- expect(ReactiveCachingWorker).to receive(:perform_async).with(cache.class, cache.id).at_least(:once)
+ expect(ExternalServiceReactiveCachingWorker).to receive(:perform_async).with(cache.class, cache.id).at_least(:once)
do_get(project)
diff --git a/spec/migrations/remove_additional_application_settings_rows_spec.rb b/spec/migrations/remove_additional_application_settings_rows_spec.rb
new file mode 100644
index 00000000000..379fa385b8e
--- /dev/null
+++ b/spec/migrations/remove_additional_application_settings_rows_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require Rails.root.join('db', 'post_migrate', '20200420162730_remove_additional_application_settings_rows.rb')
+
+describe RemoveAdditionalApplicationSettingsRows do
+ let(:application_settings) { table(:application_settings) }
+
+ it 'removes additional rows from application settings' do
+ 3.times { application_settings.create! }
+ latest_settings = application_settings.create!
+
+ disable_migrations_output { migrate! }
+
+ expect(application_settings.count).to eq(1)
+ expect(application_settings.first).to eq(latest_settings)
+ end
+
+ it 'leaves only row in application_settings' do
+ latest_settings = application_settings.create!
+
+ disable_migrations_output { migrate! }
+
+ expect(application_settings.first).to eq(latest_settings)
+ end
+end
diff --git a/spec/services/grafana/proxy_service_spec.rb b/spec/services/grafana/proxy_service_spec.rb
index 694d531c9fc..8cb7210524a 100644
--- a/spec/services/grafana/proxy_service_spec.rb
+++ b/spec/services/grafana/proxy_service_spec.rb
@@ -66,7 +66,7 @@ describe Grafana::ProxyService do
context 'with caching', :use_clean_rails_memory_store_caching do
context 'when value not present in cache' do
it 'returns nil' do
- expect(ReactiveCachingWorker)
+ expect(ExternalServiceReactiveCachingWorker)
.to receive(:perform_async)
.with(service.class, service.id, *cache_params)
diff --git a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb
index 034d6aba5d6..3eebbe98c9d 100644
--- a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb
+++ b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb
@@ -154,7 +154,7 @@ describe Metrics::Dashboard::GrafanaMetricEmbedService do
context 'when value not present in cache' do
it 'returns nil' do
- expect(ReactiveCachingWorker)
+ expect(ExternalServiceReactiveCachingWorker)
.to receive(:perform_async)
.with(service.class, service.id, *cache_params)
diff --git a/spec/services/prometheus/proxy_service_spec.rb b/spec/services/prometheus/proxy_service_spec.rb
index 5a036194d01..656ccea10de 100644
--- a/spec/services/prometheus/proxy_service_spec.rb
+++ b/spec/services/prometheus/proxy_service_spec.rb
@@ -117,7 +117,7 @@ describe Prometheus::ProxyService do
context 'when value not present in cache' do
it 'returns nil' do
- expect(ReactiveCachingWorker)
+ expect(ExternalServiceReactiveCachingWorker)
.to receive(:perform_async)
.with(subject.class, subject.id, *opts)
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index fc543186b08..b3d7f7bcece 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -246,12 +246,19 @@ module GraphqlHelpers
# Raises an error if no data is found
def graphql_data
+ # Note that `json_response` is defined as `let(:json_response)` and
+ # therefore, in a spec with multiple queries, will only contain data
+ # from the _first_ query, not subsequent ones
json_response['data'] || (raise NoData, graphql_errors)
end
def graphql_data_at(*path)
+ graphql_dig_at(graphql_data, *path)
+ end
+
+ def graphql_dig_at(data, *path)
keys = path.map { |segment| GraphqlHelpers.fieldnamerize(segment) }
- graphql_data.dig(*keys)
+ data.dig(*keys)
end
def graphql_errors
diff --git a/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
new file mode 100644
index 00000000000..e530237b4e3
--- /dev/null
+++ b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
@@ -0,0 +1,92 @@
+# frozen_string_literal: true
+
+# Use this for testing how a GraphQL query handles sorting and pagination.
+# This is particularly important when using keyset pagination connection,
+# which is the default for ActiveRecord relations, as certain sort keys
+# might not be supportable.
+#
+# sort_param: the value to specify the sort
+# data_path: the keys necessary to dig into the return GraphQL data to get the
+# returned results
+# first_param: number of items expected (like a page size)
+# expected_results: array of comparison data of all items sorted correctly
+# pagination_query: method that specifies the GraphQL query
+# pagination_results_data: method that extracts the sorted data used to compare against
+# the expected results
+#
+# Example:
+# describe 'sorting and pagination' do
+# let(:sort_project) { create(:project, :public) }
+# let(:data_path) { [:project, :issues] }
+#
+# def pagination_query(params, page_info)
+# graphql_query_for(
+# 'project',
+# { 'fullPath' => sort_project.full_path },
+# "issues(#{params}) { #{page_info} edges { node { iid weight } } }"
+# )
+# end
+#
+# def pagination_results_data(data)
+# data.map { |issue| issue.dig('node', 'iid').to_i }
+# end
+#
+# context 'when sorting by weight' do
+# ...
+# context 'when ascending' do
+# it_behaves_like 'sorted paginated query' do
+# let(:sort_param) { 'WEIGHT_ASC' }
+# let(:first_param) { 2 }
+# let(:expected_results) { [weight_issue3.iid, weight_issue5.iid, weight_issue1.iid, weight_issue4.iid, weight_issue2.iid] }
+# end
+# end
+#
+RSpec.shared_examples 'sorted paginated query' do
+ it_behaves_like 'requires variables' do
+ let(:required_variables) { [:sort_param, :first_param, :expected_results, :data_path, :current_user] }
+ end
+
+ describe do
+ let(:params) { "sort: #{sort_param}" }
+ let(:start_cursor) { graphql_data_at(*data_path, :pageInfo, :startCursor) }
+ let(:end_cursor) { graphql_data_at(*data_path, :pageInfo, :endCursor) }
+ let(:sorted_edges) { graphql_data_at(*data_path, :edges) }
+ let(:page_info) { "pageInfo { startCursor endCursor }" }
+
+ def pagination_query(params, page_info)
+ raise('pagination_query(params, page_info) must be defined in the test, see example in comment') unless defined?(super)
+
+ super
+ end
+
+ def pagination_results_data(data)
+ raise('pagination_results_data(data) must be defined in the test, see example in comment') unless defined?(super)
+
+ super(data)
+ end
+
+ before do
+ post_graphql(pagination_query(params, page_info), current_user: current_user)
+ end
+
+ context 'when sorting' do
+ it 'sorts correctly' do
+ expect(pagination_results_data(sorted_edges)).to eq expected_results
+ end
+
+ context 'when paginating' do
+ let(:params) { "sort: #{sort_param}, first: #{first_param}" }
+
+ it 'paginates correctly' do
+ expect(pagination_results_data(sorted_edges)).to eq expected_results.first(first_param)
+
+ cursored_query = pagination_query("sort: #{sort_param}, after: \"#{end_cursor}\"", page_info)
+ post_graphql(cursored_query, current_user: current_user)
+ response_data = graphql_dig_at(JSON.parse(response.body), :data, *data_path, :edges)
+
+ expect(pagination_results_data(response_data)).to eq expected_results.drop(first_param)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/shared_examples/requires_variables_shared_example.rb b/spec/support/shared_examples/requires_variables_shared_example.rb
new file mode 100644
index 00000000000..2921fccf87a
--- /dev/null
+++ b/spec/support/shared_examples/requires_variables_shared_example.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'requires variables' do
+ it 'shared example requires variables to be set', :aggregate_failures do
+ variables = Array.wrap(required_variables)
+
+ variables.each do |variable_name|
+ expect { send(variable_name) }.not_to(
+ raise_error, "The following variable must be set to use this shared example: #{variable_name}"
+ )
+ end
+ end
+end