diff options
Diffstat (limited to 'spec')
4 files changed, 190 insertions, 5 deletions
diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index 817223bd91a..94d38353189 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -36,7 +36,9 @@ describe Admin::IntegrationsController do let(:integration) { create(:jira_service, :instance) } before do - put :update, params: { id: integration.class.to_param, service: { url: url } } + allow(PropagateIntegrationWorker).to receive(:perform_async) + + put :update, params: { id: integration.class.to_param, overwrite: true, service: { url: url } } end context 'valid params' do @@ -46,6 +48,10 @@ describe Admin::IntegrationsController do expect(response).to have_gitlab_http_status(:found) expect(integration.reload.url).to eq(url) end + + it 'calls to PropagateIntegrationWorker' do + expect(PropagateIntegrationWorker).to have_received(:perform_async).with(integration.id, true) + end end context 'invalid params' do @@ -56,6 +62,10 @@ describe Admin::IntegrationsController do expect(response).to render_template(:edit) expect(integration.reload.url).not_to eq(url) end + + it 'does not call to PropagateIntegrationWorker' do + expect(PropagateIntegrationWorker).not_to have_received(:perform_async) + end end end end diff --git a/spec/requests/api/graphql/tasks/task_completion_status_spec.rb b/spec/requests/api/graphql/tasks/task_completion_status_spec.rb index c727750c0ce..c47406ea534 100644 --- a/spec/requests/api/graphql/tasks/task_completion_status_spec.rb +++ b/spec/requests/api/graphql/tasks/task_completion_status_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' describe 'getting task completion status information' do include GraphqlHelpers - DESCRIPTION_0_DONE = '- [ ] task 1\n- [ ] task 2' - DESCRIPTION_1_DONE = '- [x] task 1\n- [ ] task 2' - DESCRIPTION_2_DONE = '- [x] task 1\n- [x] task 2' + description_0_done = '- [ ] task 1\n- [ ] task 2' + description_1_done = '- [x] task 1\n- [ ] task 2' + description_2_done = '- [x] task 1\n- [x] task 2' let_it_be(:user1) { create(:user) } let_it_be(:project) { create(:project, :repository, :public) } @@ -42,7 +42,7 @@ describe 'getting task completion status information' do end end - [DESCRIPTION_0_DONE, DESCRIPTION_1_DONE, DESCRIPTION_2_DONE].each do |desc| + [description_0_done, description_1_done, description_2_done].each do |desc| context "with description #{desc}" do context 'when type is issue' do it_behaves_like 'graphql task completion status provider', 'issue' do diff --git a/spec/services/admin/propagate_integration_service_spec.rb b/spec/services/admin/propagate_integration_service_spec.rb new file mode 100644 index 00000000000..843b78a41e9 --- /dev/null +++ b/spec/services/admin/propagate_integration_service_spec.rb @@ -0,0 +1,149 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Admin::PropagateIntegrationService do + describe '.propagate' do + let(:excluded_attributes) { %w[id project_id inherit_from_id instance created_at updated_at title description] } + let!(:project) { create(:project) } + let!(:instance_integration) do + JiraService.create!( + instance: true, + active: true, + push_events: true, + url: 'http://update-jira.instance.com', + username: 'user', + password: 'secret' + ) + end + + let!(:inherited_integration) do + JiraService.create!( + project: create(:project), + inherit_from_id: instance_integration.id, + instance: false, + active: true, + push_events: false, + url: 'http://jira.instance.com', + username: 'user', + password: 'secret' + ) + end + + let!(:not_inherited_integration) do + JiraService.create!( + project: create(:project), + inherit_from_id: nil, + instance: false, + active: true, + push_events: false, + url: 'http://jira.instance.com', + username: 'user', + password: 'secret' + ) + end + + let!(:another_inherited_integration) do + BambooService.create!( + project: create(:project), + inherit_from_id: instance_integration.id, + instance: false, + active: true, + push_events: false, + bamboo_url: 'http://gitlab.com', + username: 'mic', + password: 'password', + build_key: 'build' + ) + end + + shared_examples 'inherits settings from integration' do + it 'updates the inherited integrations' do + described_class.propagate(integration: instance_integration, overwrite: overwrite) + + expect(integration.reload.inherit_from_id).to eq(instance_integration.id) + expect(integration.attributes.except(*excluded_attributes)) + .to eq(instance_integration.attributes.except(*excluded_attributes)) + end + + context 'integration with data fields' do + let(:excluded_attributes) { %w[id service_id created_at updated_at] } + + it 'updates the data fields from inherited integrations' do + described_class.propagate(integration: instance_integration, overwrite: overwrite) + + expect(integration.reload.data_fields.attributes.except(*excluded_attributes)) + .to eq(instance_integration.data_fields.attributes.except(*excluded_attributes)) + end + end + end + + shared_examples 'does not inherit settings from integration' do + it 'does not update the not inherited integrations' do + described_class.propagate(integration: instance_integration, overwrite: overwrite) + + expect(integration.reload.attributes.except(*excluded_attributes)) + .not_to eq(instance_integration.attributes.except(*excluded_attributes)) + end + end + + context 'update only inherited integrations' do + let(:overwrite) { false } + + it_behaves_like 'inherits settings from integration' do + let(:integration) { inherited_integration } + end + + it_behaves_like 'does not inherit settings from integration' do + let(:integration) { not_inherited_integration } + end + + it_behaves_like 'does not inherit settings from integration' do + let(:integration) { another_inherited_integration } + end + + it_behaves_like 'inherits settings from integration' do + let(:integration) { project.jira_service } + end + end + + context 'update all integrations' do + let(:overwrite) { true } + + it_behaves_like 'inherits settings from integration' do + let(:integration) { inherited_integration } + end + + it_behaves_like 'inherits settings from integration' do + let(:integration) { not_inherited_integration } + end + + it_behaves_like 'does not inherit settings from integration' do + let(:integration) { another_inherited_integration } + end + + it_behaves_like 'inherits settings from integration' do + let(:integration) { project.jira_service } + end + end + + it 'updates project#has_external_issue_tracker for issue tracker services' do + described_class.propagate(integration: instance_integration, overwrite: true) + + expect(project.reload.has_external_issue_tracker).to eq(true) + end + + it 'updates project#has_external_wiki for external wiki services' do + instance_integration = ExternalWikiService.create!( + instance: true, + active: true, + push_events: false, + external_wiki_url: 'http://external-wiki-url.com' + ) + + described_class.propagate(integration: instance_integration, overwrite: true) + + expect(project.reload.has_external_wiki).to eq(true) + end + end +end diff --git a/spec/workers/propagate_integration_worker_spec.rb b/spec/workers/propagate_integration_worker_spec.rb new file mode 100644 index 00000000000..e49869a38e9 --- /dev/null +++ b/spec/workers/propagate_integration_worker_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe PropagateIntegrationWorker do + describe '#perform' do + let(:integration) do + PushoverService.create( + template: true, + active: true, + device: 'MyDevice', + sound: 'mic', + priority: 4, + user_key: 'asdf', + api_key: '123456789' + ) + end + + it 'calls the propagate service with the integration' do + expect(Admin::PropagateIntegrationService).to receive(:propagate) + .with(integration: integration, overwrite: true) + + subject.perform(integration.id, true) + end + end +end |