diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/admin/admin_runners_spec.rb | 2 | ||||
-rw-r--r-- | spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js | 58 | ||||
-rw-r--r-- | spec/graphql/types/ci/job_artifact_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/workhorse_spec.rb | 16 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/config_variables_spec.rb | 15 | ||||
-rw-r--r-- | spec/services/service_ping/submit_service_ping_service_spec.rb | 135 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/database/without_check_constraint.rb | 52 | ||||
-rw-r--r-- | spec/support_specs/database/without_check_constraint_spec.rb | 85 | ||||
-rw-r--r-- | spec/tasks/gitlab/usage_data_rake_spec.rb | 36 | ||||
-rw-r--r-- | spec/views/profiles/preferences/show.html.haml_spec.rb | 4 | ||||
-rw-r--r-- | spec/workers/gitlab_service_ping_worker_spec.rb | 21 |
12 files changed, 305 insertions, 122 deletions
diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 8e71c256e25..8228a58fdbb 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -50,7 +50,7 @@ RSpec.describe "Admin Runners" do it 'shows an instance badge' do within_runner_row(instance_runner.id) do - expect(page).to have_selector '.badge', text: 'Instance' + expect(page).to have_selector '.badge', text: s_('Runners|Instance') end end end diff --git a/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js new file mode 100644 index 00000000000..924dab60704 --- /dev/null +++ b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js @@ -0,0 +1,58 @@ +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import BranchRule, { + i18n, +} from '~/projects/settings/repository/branch_rules/components/branch_rule.vue'; + +const defaultProps = { + name: 'main', + isDefault: true, + isProtected: true, + approvalDetails: ['requires approval from TEST', '2 status checks'], +}; + +describe('Branch rule', () => { + let wrapper; + + const createComponent = (props = {}) => { + wrapper = shallowMountExtended(BranchRule, { propsData: { ...defaultProps, ...props } }); + }; + + const findDefaultBadge = () => wrapper.findByText(i18n.defaultLabel); + const findProtectedBadge = () => wrapper.findByText(i18n.protectedLabel); + const findBranchName = () => wrapper.findByText(defaultProps.name); + const findProtectionDetailsList = () => wrapper.findByRole('list'); + const findProtectionDetailsListItems = () => wrapper.findAllByRole('listitem'); + + beforeEach(() => createComponent()); + + it('renders the branch name', () => { + expect(findBranchName().exists()).toBe(true); + }); + + describe('badges', () => { + it('renders both default and protected badges', () => { + expect(findDefaultBadge().exists()).toBe(true); + expect(findProtectedBadge().exists()).toBe(true); + }); + + it('does not render default badge if isDefault is set to false', () => { + createComponent({ isDefault: false }); + expect(findDefaultBadge().exists()).toBe(false); + }); + + it('does not render protected badge if isProtected is set to false', () => { + createComponent({ isProtected: false }); + expect(findProtectedBadge().exists()).toBe(false); + }); + }); + + it('does not render the protection details list of no details are present', () => { + createComponent({ approvalDetails: null }); + expect(findProtectionDetailsList().exists()).toBe(false); + }); + + it('renders the protection details list items', () => { + expect(findProtectionDetailsListItems().at(0).text()).toBe(defaultProps.approvalDetails[0]); + expect(findProtectionDetailsListItems().at(1).text()).toBe(defaultProps.approvalDetails[1]); + }); +}); diff --git a/spec/graphql/types/ci/job_artifact_type_spec.rb b/spec/graphql/types/ci/job_artifact_type_spec.rb index 58b5f9cfcb7..3e054faf0c9 100644 --- a/spec/graphql/types/ci/job_artifact_type_spec.rb +++ b/spec/graphql/types/ci/job_artifact_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['CiJobArtifact'] do it 'has the correct fields' do - expected_fields = [:download_path, :file_type, :name] + expected_fields = [:id, :download_path, :file_type, :name, :size, :expire_at] expect(described_class).to have_graphql_fields(*expected_fields) end diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb index 703a4b5399e..7209263445c 100644 --- a/spec/lib/gitlab/workhorse_spec.rb +++ b/spec/lib/gitlab/workhorse_spec.rb @@ -366,9 +366,25 @@ RSpec.describe Gitlab::Workhorse do expect(Gitlab::Redis::SharedState).to receive(:with).and_call_original expect_any_instance_of(::Redis).to receive(:publish) .with(described_class::NOTIFICATION_CHANNEL, "test-key=test-value") + expect_any_instance_of(::Redis).to receive(:publish) + .with(described_class::NOTIFICATION_CHANNEL + ':test-key', "test-value") subject end + + context 'when workhorse_long_polling_publish_many is disabled' do + before do + stub_feature_flags(workhorse_long_polling_publish_many: false) + end + + it 'set and notify' do + expect(Gitlab::Redis::SharedState).to receive(:with).and_call_original + expect_any_instance_of(::Redis).to receive(:publish) + .with(described_class::NOTIFICATION_CHANNEL, "test-key=test-value") + + subject + end + end end context 'when we set a new key' do diff --git a/spec/requests/api/graphql/ci/config_variables_spec.rb b/spec/requests/api/graphql/ci/config_variables_spec.rb index c010ea3b9d4..2b5a5d0dc93 100644 --- a/spec/requests/api/graphql/ci/config_variables_spec.rb +++ b/spec/requests/api/graphql/ci/config_variables_spec.rb @@ -6,15 +6,15 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do include GraphqlHelpers include ReactiveCachingHelpers - let_it_be(:project) { create(:project, :repository, :public) } - let_it_be(:user) { create(:user) } let_it_be(:content) do File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) end - let(:sha) { project.commit.sha } + let_it_be(:project) { create(:project, :custom_repo, :public, files: { '.gitlab-ci.yml' => content }) } + let_it_be(:user) { create(:user) } let(:service) { Ci::ListConfigVariablesService.new(project, user) } + let(:sha) { project.repository.commit.sha } let(:query) do %( @@ -33,7 +33,6 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do context 'when the user has the correct permissions' do before do project.add_maintainer(user) - stub_ci_pipeline_yaml_file(content) allow(Ci::ListConfigVariablesService) .to receive(:new) .and_return(service) @@ -45,6 +44,11 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do end it 'returns the CI variables for the config' do + expect(service) + .to receive(:execute) + .with(sha) + .and_call_original + post_graphql(query, current_user: user) expect(graphql_data.dig('project', 'ciConfigVariables')).to contain_exactly( @@ -63,8 +67,6 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do end context 'when the cache is empty' do - let(:sha) { 'main' } - it 'returns nothing' do post_graphql(query, current_user: user) @@ -76,7 +78,6 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do context 'when the user is not authorized' do before do project.add_guest(user) - stub_ci_pipeline_yaml_file(content) allow(Ci::ListConfigVariablesService) .to receive(:new) .and_return(service) diff --git a/spec/services/service_ping/submit_service_ping_service_spec.rb b/spec/services/service_ping/submit_service_ping_service_spec.rb index 70de02723cd..5dbf5edb776 100644 --- a/spec/services/service_ping/submit_service_ping_service_spec.rb +++ b/spec/services/service_ping/submit_service_ping_service_spec.rb @@ -54,11 +54,13 @@ RSpec.describe ServicePing::SubmitService do let(:service_ping_payload_url) { File.join(described_class::STAGING_BASE_URL, described_class::USAGE_DATA_PATH) } let(:service_ping_errors_url) { File.join(described_class::STAGING_BASE_URL, described_class::ERROR_PATH) } let(:service_ping_metadata_url) { File.join(described_class::STAGING_BASE_URL, described_class::METADATA_PATH) } + let!(:usage_data) { { uuid: 'uuid', recorded_at: Time.current } } + + let(:subject) { described_class.new(payload: usage_data) } shared_examples 'does not run' do it do expect(Gitlab::HTTP).not_to receive(:post) - expect(Gitlab::Usage::ServicePingReport).not_to receive(:for) subject.execute end @@ -69,7 +71,7 @@ RSpec.describe ServicePing::SubmitService do expect(Gitlab::HTTP).not_to receive(:post).with(service_ping_payload_url, any_args) expect { subject.execute }.to raise_error(described_class::SubmissionError) do |error| - expect(error.message).to include('Usage data is blank') + expect(error.message).to include('Usage data payload is blank') end end end @@ -118,13 +120,18 @@ RSpec.describe ServicePing::SubmitService do allow(ServicePing::ServicePingSettings).to receive(:product_intelligence_enabled?).and_return(true) end - it 'generates service ping' do - stub_response(body: with_dev_ops_score_params) - stub_response(body: nil, url: service_ping_metadata_url, status: 201) + it 'submits a service ping payload without errors', :aggregate_failures do + response = stub_response(body: with_dev_ops_score_params) + error_response = stub_response(body: nil, url: service_ping_errors_url, status: 201) + metadata_response = stub_response(body: nil, url: service_ping_metadata_url, status: 201) - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_call_original + expect(Gitlab::HTTP).to receive(:post).twice.and_call_original subject.execute + + expect(response).to have_been_requested + expect(error_response).not_to have_been_requested + expect(metadata_response).to have_been_requested end end @@ -155,15 +162,9 @@ RSpec.describe ServicePing::SubmitService do expect(response).to have_been_requested end - it 'forces a refresh of usage data statistics before submitting' do - stub_response(body: with_dev_ops_score_params) - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_call_original - - subject.execute - end - context 'when conv_index data is passed' do + let(:usage_data) { { uuid: 'uuid', recorded_at: Time.current } } + before do stub_response(body: with_conv_index_params) end @@ -171,21 +172,17 @@ RSpec.describe ServicePing::SubmitService do it_behaves_like 'saves DevOps report data from the response' it 'saves usage_data_id to version_usage_data_id_value' do - recorded_at = Time.current - usage_data = { uuid: 'uuid', recorded_at: recorded_at } - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values) - .and_return(usage_data) - subject.execute - raw_usage_data = RawUsageData.find_by(recorded_at: recorded_at) + raw_usage_data = RawUsageData.find_by(recorded_at: usage_data[:recorded_at]) expect(raw_usage_data.version_usage_data_id_value).to eq(31643) end end context 'when only usage_data_id is passed in response' do + let(:usage_data) { { uuid: 'uuid', recorded_at: Time.current } } + before do stub_response(body: with_usage_data_id_params) end @@ -195,15 +192,9 @@ RSpec.describe ServicePing::SubmitService do end it 'saves usage_data_id to version_usage_data_id_value' do - recorded_at = Time.current - usage_data = { uuid: 'uuid', recorded_at: recorded_at } - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values) - .and_return(usage_data) - subject.execute - raw_usage_data = RawUsageData.find_by(recorded_at: recorded_at) + raw_usage_data = RawUsageData.find_by(recorded_at: usage_data[:recorded_at]) expect(raw_usage_data.version_usage_data_id_value).to eq(31643) end @@ -232,6 +223,8 @@ RSpec.describe ServicePing::SubmitService do end context 'with saving raw_usage_data' do + let(:usage_data) { { uuid: 'uuid', recorded_at: Time.current } } + before do stub_response(body: with_dev_ops_score_params) end @@ -241,17 +234,10 @@ RSpec.describe ServicePing::SubmitService do end it 'saves the correct payload' do - recorded_at = Time.current - usage_data = { uuid: 'uuid', recorded_at: recorded_at } - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values) - .and_return(usage_data) - subject.execute - raw_usage_data = RawUsageData.find_by(recorded_at: recorded_at) + raw_usage_data = RawUsageData.find_by(recorded_at: usage_data[:recorded_at]) - expect(raw_usage_data.recorded_at).to be_like_time(recorded_at) expect(raw_usage_data.payload.to_json).to eq(usage_data.to_json) end end @@ -269,90 +255,30 @@ RSpec.describe ServicePing::SubmitService do end context 'and usage data is empty string' do - before do - allow(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return({}) - end + let(:usage_data) { {} } it_behaves_like 'does not send a blank usage ping payload' end context 'and usage data is nil' do - before do - allow(ServicePing::BuildPayload).to receive(:execute).and_return(nil) - allow(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values).and_return(nil) - end + let(:usage_data) { nil } it_behaves_like 'does not send a blank usage ping payload' end - context 'if payload service fails' do - before do - stub_response(body: with_dev_ops_score_params) - - allow(ServicePing::BuildPayload).to receive_message_chain(:new, :execute) - .and_raise(described_class::SubmissionError, 'SubmissionError') - end - - it 'calls Gitlab::Usage::ServicePingReport .for method' do - usage_data = build_usage_data - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values) - .and_return(usage_data) - - subject.execute - end - - it 'submits error' do - expect(Gitlab::HTTP).to receive(:post).with(URI.join(service_ping_payload_url), any_args) - .and_call_original - expect(Gitlab::HTTP).to receive(:post).with(URI.join(service_ping_errors_url), any_args) - .and_call_original - expect(Gitlab::HTTP).to receive(:post).with(URI.join(service_ping_metadata_url), any_args) - .and_call_original - - subject.execute - end - end - - context 'calls BuildPayload first' do - before do - stub_response(body: with_dev_ops_score_params) - end - - it 'returns usage data' do - usage_data = build_usage_data - - expect_next_instance_of(ServicePing::BuildPayload) do |service| - expect(service).to receive(:execute).and_return(usage_data) - end - - subject.execute - end - end - context 'if version app response fails' do before do stub_response(body: with_dev_ops_score_params, status: 404) - - usage_data = build_usage_data - allow_next_instance_of(ServicePing::BuildPayload) do |service| - allow(service).to receive(:execute).and_return(usage_data) - end end - it 'calls Gitlab::Usage::ServicePingReport .for method' do - usage_data = build_usage_data - - expect(Gitlab::Usage::ServicePingReport).to receive(:for).with(output: :all_metrics_values) - .and_return(usage_data) - + it 'raises SubmissionError' do # SubmissionError is raised as a result of 404 in response from HTTP Request expect { subject.execute }.to raise_error(described_class::SubmissionError) end end context 'when skip_db_write passed to service' do - let(:subject) { ServicePing::SubmitService.new(skip_db_write: true) } + let(:subject) { described_class.new(payload: usage_data, skip_db_write: true) } before do stub_response(body: with_dev_ops_score_params) @@ -377,13 +303,10 @@ RSpec.describe ServicePing::SubmitService do stub_database_flavor_check stub_application_setting(usage_ping_enabled: true) stub_response(body: with_conv_index_params) - allow_next_instance_of(ServicePing::BuildPayload) do |service| - allow(service).to receive(:execute).and_return(payload) - end end let(:metric_double) { instance_double(Gitlab::Usage::ServicePing::LegacyMetricTimingDecorator, duration: 123) } - let(:payload) do + let(:usage_data) do { uuid: 'uuid', metric_a: metric_double, @@ -425,8 +348,4 @@ RSpec.describe ServicePing::SubmitService do status: status ) end - - def build_usage_data - { uuid: 'uuid', recorded_at: Time.current } - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 929f06220eb..160f7fda543 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -173,6 +173,7 @@ RSpec.configure do |config| config.include TestEnv config.include FileReadHelpers config.include Database::MultipleDatabases + config.include Database::WithoutCheckConstraint config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :view config.include Devise::Test::IntegrationHelpers, type: :feature diff --git a/spec/support/database/without_check_constraint.rb b/spec/support/database/without_check_constraint.rb new file mode 100644 index 00000000000..b361f4374b8 --- /dev/null +++ b/spec/support/database/without_check_constraint.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +# Temporarily disable the named constraint on the table within the block. +# +# without_constraint('members', 'check_1234') do +# create_invalid_data +# end +module Database + module WithoutCheckConstraint + def without_check_constraint(table, name, connection:) + saved_constraint = constraint(table, name, connection) + + constraint_error!(table, name, connection) if saved_constraint.nil? + + begin + connection.remove_check_constraint(table, name: name) + connection.transaction do + yield + raise ActiveRecord::Rollback + end + ensure + restore_constraint(saved_constraint, connection) + end + end + + private + + def constraint_error!(table, name, connection) + msg = if connection.table_exists?(table) + "'#{table}' table does not contain constraint called '#{name}'" + else + "'#{table}' does not exist" + end + + raise msg + end + + def constraint(table, name, connection) + connection + .check_constraints(table) + .find { |constraint| constraint.options[:name] == name } + end + + def restore_constraint(constraint, connection) + connection.add_check_constraint( + constraint.table_name, + constraint.expression, + **constraint.options + ) + end + end +end diff --git a/spec/support_specs/database/without_check_constraint_spec.rb b/spec/support_specs/database/without_check_constraint_spec.rb new file mode 100644 index 00000000000..d78eafd4a32 --- /dev/null +++ b/spec/support_specs/database/without_check_constraint_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Database::WithoutCheckConstraint' do + include MigrationsHelpers + + describe '.without_check_constraint' do + let(:connection) { ApplicationRecord.connection } + let(:table_name) { '_test_table' } + let(:constraint_name) { 'check_1234' } + let(:model) { table(table_name) } + + before do + # Drop test table in case it's left from a previous execution. + connection.exec_query("DROP TABLE IF EXISTS #{table_name}") + # Model has an attribute called 'name' that can't be NULL. + connection.exec_query(<<-SQL) + CREATE TABLE #{table_name} ( + name text + CONSTRAINT #{constraint_name} CHECK (name IS NOT NULL) + ); + SQL + end + + context 'with invalid table' do + subject do + without_check_constraint('no_such_table', constraint_name, connection: connection) {} + end + + it 'raises exception' do + msg = "'no_such_table' does not exist" + expect { subject }.to raise_error(msg) + end + end + + context 'with invalid constraint name' do + subject do + without_check_constraint(table_name, 'no_such_constraint', connection: connection) {} + end + + it 'raises exception' do + msg = "'#{table_name}' table does not contain constraint called 'no_such_constraint'" + expect { subject }.to raise_error(msg) + end + end + + context 'with constraint' do + subject { connection.check_constraints(table_name) } + + it 'removes inside block' do + without_check_constraint(table_name, constraint_name, connection: connection) do + expect(subject).to be_empty + end + end + + it 'restores outside block' do + saved_constraints = subject + + without_check_constraint(table_name, constraint_name, connection: connection) do + end + + expect(subject).to eq(saved_constraints) + end + end + + context 'when creating an invalid record' do + subject(:invalid_record) { model.create!(name: nil) } + + it 'enables invalid record creation inside block' do + without_check_constraint(table_name, constraint_name, connection: connection) do + expect(invalid_record).to be_persisted + expect(invalid_record.name).to be_nil + end + end + + it 'rolls back changes made within the block' do + without_check_constraint(table_name, constraint_name, connection: connection) do + invalid_record + end + expect(model.all).to be_empty + end + end + end +end diff --git a/spec/tasks/gitlab/usage_data_rake_spec.rb b/spec/tasks/gitlab/usage_data_rake_spec.rb index 207a9884090..f54d06f406f 100644 --- a/spec/tasks/gitlab/usage_data_rake_spec.rb +++ b/spec/tasks/gitlab/usage_data_rake_spec.rb @@ -3,6 +3,7 @@ require 'rake_helper' RSpec.describe 'gitlab:usage data take tasks', :silence_stdout do + include StubRequests include UsageDataHelpers let(:metrics_file) { Rails.root.join('tmp', 'test', 'sql_metrics_queries.json') } @@ -44,4 +45,39 @@ RSpec.describe 'gitlab:usage data take tasks', :silence_stdout do expect(Pathname.new(metrics_file)).to exist end end + + describe 'generate_and_send' do + let(:service_ping_payload_url) do + File.join(ServicePing::SubmitService::STAGING_BASE_URL, ServicePing::SubmitService::USAGE_DATA_PATH) + end + + let(:service_ping_metadata_url) do + File.join(ServicePing::SubmitService::STAGING_BASE_URL, ServicePing::SubmitService::METADATA_PATH) + end + + let(:payload) { { recorded_at: Time.current } } + + before do + allow_next_instance_of(ServicePing::BuildPayload) do |service| + allow(service).to receive(:execute).and_return(payload) + end + stub_response(body: payload.merge(conv_index: { usage_data_id: 123 })) + stub_response(body: nil, url: service_ping_metadata_url, status: 201) + end + + it 'generates and sends Service Ping payload' do + expect { run_rake_task('gitlab:usage_data:generate_and_send') }.to output(/.*201.*/).to_stdout + end + + private + + def stub_response(url: service_ping_payload_url, body:, status: 201) + stub_full_request(url, method: :post) + .to_return( + headers: { 'Content-Type' => 'application/json' }, + body: body.to_json, + status: status + ) + end + end end diff --git a/spec/views/profiles/preferences/show.html.haml_spec.rb b/spec/views/profiles/preferences/show.html.haml_spec.rb index 2fe941b9f14..4e4499c3252 100644 --- a/spec/views/profiles/preferences/show.html.haml_spec.rb +++ b/spec/views/profiles/preferences/show.html.haml_spec.rb @@ -54,8 +54,8 @@ RSpec.describe 'profiles/preferences/show' do end it 'has helpful homepage setup guidance' do - expect(rendered).to have_field('Homepage content') - expect(rendered).to have_content('Choose what content you want to see on your homepage.') + expect(rendered).to have_field('Dashboard') + expect(rendered).to have_content('Choose what content you want to see by default on your dashboard.') end end diff --git a/spec/workers/gitlab_service_ping_worker_spec.rb b/spec/workers/gitlab_service_ping_worker_spec.rb index c88708dc50a..f17847a7b33 100644 --- a/spec/workers/gitlab_service_ping_worker_spec.rb +++ b/spec/workers/gitlab_service_ping_worker_spec.rb @@ -14,21 +14,36 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do allow(subject).to receive(:sleep) end - it 'does not run for GitLab.com' do + it 'does not run for GitLab.com when triggered from cron' do allow(Gitlab).to receive(:com?).and_return(true) expect(ServicePing::SubmitService).not_to receive(:new) subject.perform end + it 'runs for GitLab.com when triggered manually' do + allow(Gitlab).to receive(:com?).and_return(true) + expect(ServicePing::SubmitService).to receive(:new) + + subject.perform('triggered_from_cron' => false) + end + it 'delegates to ServicePing::SubmitService' do - expect_next_instance_of(ServicePing::SubmitService, payload: payload) do |service| + expect_next_instance_of(ServicePing::SubmitService, payload: payload, skip_db_write: false) do |service| expect(service).to receive(:execute) end subject.perform end + it 'passes Hash arguments to ServicePing::SubmitService' do + expect_next_instance_of(ServicePing::SubmitService, payload: payload, skip_db_write: true) do |service| + expect(service).to receive(:execute) + end + + subject.perform('skip_db_write' => true) + end + context 'payload computation' do it 'creates RawUsageData entry when there is NO entry with the same recorded_at timestamp' do expect { subject.perform }.to change { RawUsageData.count }.by(1) @@ -46,7 +61,7 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do allow(::ServicePing::BuildPayload).to receive(:new).and_raise(error) expect(::Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(error) - expect_next_instance_of(::ServicePing::SubmitService, payload: nil) do |service| + expect_next_instance_of(::ServicePing::SubmitService, payload: nil, skip_db_write: false) do |service| expect(service).to receive(:execute) end |