diff --git a/app/controllers/concerns/integrations_actions.rb b/app/controllers/concerns/integrations_actions.rb index f5a3ec913c2a6089c1d0c7aa29169745a03edf22..fc8d4064b6521e979f937e2e5f06386ff11312f0 100644 --- a/app/controllers/concerns/integrations_actions.rb +++ b/app/controllers/concerns/integrations_actions.rb @@ -48,9 +48,12 @@ def reset private + # rubocop:disable Gitlab/ModuleWithInstanceVariables def integration @integration ||= find_or_initialize_non_project_specific_integration(params[:id]) + @service ||= @integration # TODO: remove references to @service https://gitlab.com/gitlab-org/gitlab/-/issues/329759 end + # rubocop:enable Gitlab/ModuleWithInstanceVariables def success_message if integration.active? diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index 74145a70b952b106e1624e16b10f1bf989b97fc4..e72055c3d0f6971fa2a4d9b26d3bc36c0183cbc7 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -85,7 +85,7 @@ def success_message def integration @integration ||= @project.find_or_initialize_service(params[:id]) - @service ||= @integration # TODO: remove references to @service + @service ||= @integration # TODO: remove references to @service https://gitlab.com/gitlab-org/gitlab/-/issues/329759 end alias_method :service, :integration diff --git a/changelogs/unreleased/331262-bugfix-services-variable.yml b/changelogs/unreleased/331262-bugfix-services-variable.yml new file mode 100644 index 0000000000000000000000000000000000000000..1702f676740f0ae24441f0c8fe0ee4ebeb2aa320 --- /dev/null +++ b/changelogs/unreleased/331262-bugfix-services-variable.yml @@ -0,0 +1,5 @@ +--- +title: Fix errors in instance and group-level integration pages for some integrations +merge_request: 62054 +author: +type: fixed diff --git a/spec/features/admin/integrations/user_activates_mattermost_slash_command_spec.rb b/spec/features/admin/integrations/user_activates_mattermost_slash_command_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..6f091d3799503161ea23a2a610be1265f2eab2dc --- /dev/null +++ b/spec/features/admin/integrations/user_activates_mattermost_slash_command_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User activates the instance-level Mattermost Slash Command integration', :js do + include_context 'instance integration activation' + + before do + stub_mattermost_setting(enabled: true) + visit_instance_integration('Mattermost slash commands') + end + + let(:edit_path) { edit_admin_application_settings_integration_path(:mattermost_slash_commands) } + + include_examples 'user activates the Mattermost Slash Command integration' +end diff --git a/spec/features/groups/integrations/user_activates_mattermost_slash_command_spec.rb b/spec/features/groups/integrations/user_activates_mattermost_slash_command_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..7703268af3944e599fdb9417d9690659c5e232b7 --- /dev/null +++ b/spec/features/groups/integrations/user_activates_mattermost_slash_command_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User activates the group-level Mattermost Slash Command integration', :js do + include_context 'group integration activation' + + before do + stub_mattermost_setting(enabled: true) + visit_group_integration('Mattermost slash commands') + end + + let(:edit_path) { edit_group_settings_integration_path(group, :mattermost_slash_commands) } + + include_examples 'user activates the Mattermost Slash Command integration' +end diff --git a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb index 54a501e89a2f46ea11351737c9b711fe1810a7c5..84c9b8c6b54e8017780a5af01ad948327f44c878 100644 --- a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb +++ b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb @@ -14,35 +14,10 @@ context 'mattermost service is enabled' do let(:mattermost_enabled) { true } - it 'shows a help message' do - expect(page).to have_content("Use this service to perform common") - end - - it 'shows a token placeholder' do - token_placeholder = find_field('service_token')['placeholder'] - - expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx') - end - - it 'redirects to the integrations page after saving but not activating' do - token = ('a'..'z').to_a.join - - fill_in 'service_token', with: token - click_active_checkbox - click_save_integration - - expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands)) - expect(page).to have_content('Mattermost slash commands settings saved, but not active.') - end - - it 'redirects to the integrations page after activating' do - token = ('a'..'z').to_a.join - - fill_in 'service_token', with: token - click_save_integration + describe 'activation' do + let(:edit_path) { edit_project_service_path(project, :mattermost_slash_commands) } - expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands)) - expect(page).to have_content('Mattermost slash commands settings saved and active.') + include_examples 'user activates the Mattermost Slash Command integration' end it 'shows the add to mattermost button' do diff --git a/spec/support/shared_contexts/features/integrations/group_integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/group_integrations_shared_context.rb new file mode 100644 index 0000000000000000000000000000000000000000..5996fcc6593fa113a0b2ae92940edd43ca3ddb81 --- /dev/null +++ b/spec/support/shared_contexts/features/integrations/group_integrations_shared_context.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +RSpec.shared_context 'group integration activation' do + include_context 'instance and group integration activation' + + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + + before_all do + group.add_owner(user) + end + + before do + sign_in(user) + end + + def visit_group_integrations + visit group_settings_integrations_path(group) + end + + def visit_group_integration(name) + visit_group_integrations + + within('#content-body') do + click_link(name) + end + end +end diff --git a/spec/support/shared_contexts/features/integrations/instance_and_group_integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/instance_and_group_integrations_shared_context.rb new file mode 100644 index 0000000000000000000000000000000000000000..58ee341f71f3a2647265b63dbbbb5658ebb97cb7 --- /dev/null +++ b/spec/support/shared_contexts/features/integrations/instance_and_group_integrations_shared_context.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +RSpec.shared_context 'instance and group integration activation' do + include_context 'integration activation' + + def click_save_integration + click_save_changes_button + click_save_settings_modal + end + + def click_save_changes_button + click_button('Save changes') + end + + def click_save_settings_modal + click_button('Save') + end +end diff --git a/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb new file mode 100644 index 0000000000000000000000000000000000000000..3b02db994a3d643e1a6606400b2a31a95389ad31 --- /dev/null +++ b/spec/support/shared_contexts/features/integrations/instance_integrations_shared_context.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +RSpec.shared_context 'instance integration activation' do + include_context 'instance and group integration activation' + + let_it_be(:user) { create(:user, :admin) } + + before do + sign_in(user) + gitlab_enable_admin_mode_sign_in(user) + end + + def visit_instance_integrations + visit integrations_admin_application_settings_path + end + + def visit_instance_integration(name) + visit_instance_integrations + + within('#content-body') do + click_link(name) + end + end +end diff --git a/spec/support/shared_contexts/services_shared_context.rb b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb similarity index 95% rename from spec/support/shared_contexts/services_shared_context.rb rename to spec/support/shared_contexts/features/integrations/integrations_shared_context.rb index 34c92367efa0d14cb173983a04490c21949f1893..07c58114b30c37b9566095fa883cafde5346f5f9 100644 --- a/spec/support/shared_contexts/services_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb @@ -70,3 +70,9 @@ def enable_license_for_service(service) end end end + +RSpec.shared_context 'integration activation' do + def click_active_checkbox + find('label', text: 'Active').click + end +end diff --git a/spec/support/shared_contexts/project_service_jira_context.rb b/spec/support/shared_contexts/features/integrations/project_integrations_jira_context.rb similarity index 100% rename from spec/support/shared_contexts/project_service_jira_context.rb rename to spec/support/shared_contexts/features/integrations/project_integrations_jira_context.rb diff --git a/spec/support/shared_contexts/project_service_shared_context.rb b/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb similarity index 92% rename from spec/support/shared_contexts/project_service_shared_context.rb rename to spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb index 0e3540a3e156d663a7011ccf892809c3df089bfd..b10844320d06c97862d2e6dc3c9d303ebc5c0e0a 100644 --- a/spec/support/shared_contexts/project_service_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.shared_context 'project service activation' do + include_context 'integration activation' + let(:project) { create(:project) } let(:user) { create(:user) } @@ -21,10 +23,6 @@ def visit_project_integration(name) end end - def click_active_checkbox - find('label', text: 'Active').click - end - def click_save_integration click_button('Save changes') end diff --git a/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb b/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb new file mode 100644 index 0000000000000000000000000000000000000000..cfa043322db56069299b492f957efa34c77c356e --- /dev/null +++ b/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'user activates the Mattermost Slash Command integration' do + it 'shows a help message' do + expect(page).to have_content('Use this service to perform common') + end + + it 'shows a token placeholder' do + token_placeholder = find_field('service_token')['placeholder'] + + expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx') + end + + it 'redirects to the integrations page after saving but not activating' do + token = ('a'..'z').to_a.join + + fill_in 'service_token', with: token + click_active_checkbox + click_save_integration + + expect(current_path).to eq(edit_path) + expect(page).to have_content('Mattermost slash commands settings saved, but not active.') + end + + it 'redirects to the integrations page after activating' do + token = ('a'..'z').to_a.join + + fill_in 'service_token', with: token + click_save_integration + + expect(current_path).to eq(edit_path) + expect(page).to have_content('Mattermost slash commands settings saved and active.') + end +end