diff options
Diffstat (limited to 'spec/controllers/projects/services_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/services_controller_spec.rb | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index baf3bde83bd..419b5c7e101 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -174,6 +174,8 @@ RSpec.describe Projects::ServicesController do let(:redirect_url) { edit_project_service_path(project, integration) } before do + stub_jira_integration_test + put :update, params: params end @@ -222,12 +224,48 @@ RSpec.describe Projects::ServicesController do end end - context 'when param `inherit_from_id` is set to some value' do - let(:instance_service) { create(:jira_integration, :instance) } - let(:integration_params) { { inherit_from_id: instance_service.id } } + context 'when param `inherit_from_id` is set to an instance integration' do + let(:instance_integration) { create(:jira_integration, :instance, url: 'http://instance.com', password: 'instance') } + let(:integration_params) { { inherit_from_id: instance_integration.id, url: 'http://custom.com', password: 'custom' } } + + it 'ignores submitted params and inherits instance settings' do + expect(integration.reload).to have_attributes( + inherit_from_id: instance_integration.id, + url: instance_integration.url, + password: instance_integration.password + ) + end + end + + context 'when param `inherit_from_id` is set to a group integration' do + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:jira_integration) { create(:jira_integration, project: project) } - it 'sets inherit_from_id to value' do - expect(integration.reload.inherit_from_id).to eq(instance_service.id) + let(:group_integration) { create(:jira_integration, group: group, project: nil, url: 'http://group.com', password: 'group') } + let(:integration_params) { { inherit_from_id: group_integration.id, url: 'http://custom.com', password: 'custom' } } + + it 'ignores submitted params and inherits group settings' do + expect(integration.reload).to have_attributes( + inherit_from_id: group_integration.id, + url: group_integration.url, + password: group_integration.password + ) + end + end + + context 'when param `inherit_from_id` is set to an unrelated group' do + let_it_be(:group) { create(:group) } + + let(:group_integration) { create(:jira_integration, group: group, project: nil, url: 'http://group.com', password: 'group') } + let(:integration_params) { { inherit_from_id: group_integration.id, url: 'http://custom.com', password: 'custom' } } + + it 'ignores the param and saves the submitted settings' do + expect(integration.reload).to have_attributes( + inherit_from_id: nil, + url: 'http://custom.com', + password: 'custom' + ) end end end @@ -239,22 +277,39 @@ RSpec.describe Projects::ServicesController do end context 'when update succeeds' do - let(:integration_params) { { url: 'http://example.com' } } + let(:integration_params) { { url: 'http://example.com', password: 'password' } } - it 'returns JSON response with no errors' do + it 'returns success response' do expect(response).to be_successful - expect(json_response).to include('active' => true, 'errors' => {}) + expect(json_response).to include( + 'active' => true, + 'errors' => {} + ) + end + end + + context 'when update fails with missing password' do + let(:integration_params) { { url: 'http://example.com' } } + + it 'returns JSON response errors' do + expect(response).not_to be_successful + expect(json_response).to include( + 'active' => true, + 'errors' => { + 'password' => ["can't be blank"] + } + ) end end - context 'when update fails' do - let(:integration_params) { { url: '' } } + context 'when update fails with invalid URL' do + let(:integration_params) { { url: '', password: 'password' } } it 'returns JSON response with errors' do expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(json_response).to include( 'active' => true, - 'errors' => { 'url' => ['must be a valid URL', %(can't be blank)] } + 'errors' => { 'url' => ['must be a valid URL', "can't be blank"] } ) end end |