Commit 261679ed authored by Michael Kozono's avatar Michael Kozono

Merge branch '335384-rename-integration-can_test-method' into 'master'

Rename Integration#can_test? to #testable?

See merge request gitlab-org/gitlab!65691
parents a7aafeee 9710349c
...@@ -46,7 +46,7 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -46,7 +46,7 @@ class Projects::ServicesController < Projects::ApplicationController
end end
def test def test
if integration.can_test? if integration.testable?
render json: service_test_response, status: :ok render json: service_test_response, status: :ok
else else
render json: {}, status: :not_found render json: {}, status: :not_found
......
...@@ -84,7 +84,7 @@ module IntegrationsHelper ...@@ -84,7 +84,7 @@ module IntegrationsHelper
integration_level: integration_level(integration), integration_level: integration_level(integration),
editable: integration.editable?.to_s, editable: integration.editable?.to_s,
cancel_path: scoped_integrations_path, cancel_path: scoped_integrations_path,
can_test: integration.can_test?.to_s, can_test: integration.testable?.to_s,
test_path: scoped_test_integration_path(integration), test_path: scoped_test_integration_path(integration),
reset_path: scoped_reset_integration_path(integration, group: group) reset_path: scoped_reset_integration_path(integration, group: group)
} }
......
...@@ -447,7 +447,7 @@ class Integration < ApplicationRecord ...@@ -447,7 +447,7 @@ class Integration < ApplicationRecord
# Disable test for instance-level and group-level integrations. # Disable test for instance-level and group-level integrations.
# https://gitlab.com/gitlab-org/gitlab/-/issues/213138 # https://gitlab.com/gitlab-org/gitlab/-/issues/213138
def can_test? def testable?
project_level? project_level?
end end
......
...@@ -20,7 +20,7 @@ module Integrations ...@@ -20,7 +20,7 @@ module Integrations
%w() %w()
end end
def can_test? def testable?
false false
end end
......
...@@ -58,7 +58,7 @@ module Integrations ...@@ -58,7 +58,7 @@ module Integrations
] ]
end end
def can_test? def testable?
false false
end end
......
...@@ -27,7 +27,7 @@ module Integrations ...@@ -27,7 +27,7 @@ module Integrations
'ewm' 'ewm'
end end
def can_test? def testable?
false false
end end
......
...@@ -537,7 +537,7 @@ module Integrations ...@@ -537,7 +537,7 @@ module Integrations
def update_deployment_type? def update_deployment_type?
(api_url_changed? || url_changed? || username_changed? || password_changed?) && (api_url_changed? || url_changed? || username_changed? || password_changed?) &&
can_test? testable?
end end
def update_deployment_type def update_deployment_type
......
...@@ -6,7 +6,7 @@ module Integrations ...@@ -6,7 +6,7 @@ module Integrations
prop_accessor :token prop_accessor :token
def can_test? def testable?
false false
end end
......
...@@ -83,7 +83,7 @@ module Integrations ...@@ -83,7 +83,7 @@ module Integrations
end end
end end
def can_test? def testable?
false false
end end
end end
......
...@@ -18,7 +18,7 @@ module Integrations ...@@ -18,7 +18,7 @@ module Integrations
Gitlab::Json.parse(File.read(Rails.root + 'spec/fixtures/metrics.json')) Gitlab::Json.parse(File.read(Rails.root + 'spec/fixtures/metrics.json'))
end end
def can_test? def testable?
false false
end end
end end
......
...@@ -57,7 +57,7 @@ module Integrations ...@@ -57,7 +57,7 @@ module Integrations
PipelineNotificationWorker.new.perform(pipeline_id, recipients: all_recipients) PipelineNotificationWorker.new.perform(pipeline_id, recipients: all_recipients)
end end
def can_test? def testable?
project&.ci_pipelines&.any? project&.ci_pipelines&.any?
end end
......
...@@ -68,7 +68,7 @@ module Integrations ...@@ -68,7 +68,7 @@ module Integrations
%w(pipeline) %w(pipeline)
end end
def can_test? def testable?
project&.ci_pipelines&.any? project&.ci_pipelines&.any?
end end
......
...@@ -22,7 +22,7 @@ module Integrations ...@@ -22,7 +22,7 @@ module Integrations
update(active: !!slack_integration) update(active: !!slack_integration)
end end
def can_test? def testable?
false false
end end
......
...@@ -285,17 +285,17 @@ RSpec.describe Integrations::Github do ...@@ -285,17 +285,17 @@ RSpec.describe Integrations::Github do
end end
end end
describe '#can_test?' do describe '#testable?' do
it 'is false if there are no pipelines' do it 'is false if there are no pipelines' do
project.ci_pipelines.delete_all project.ci_pipelines.delete_all
expect(subject.can_test?).to eq false expect(subject).not_to be_testable
end end
it 'is true if the project has a pipeline' do it 'is true if the project has a pipeline' do
pipeline pipeline
expect(subject.can_test?).to eq true expect(subject).to be_testable
end end
end end
......
...@@ -6,9 +6,10 @@ RSpec.describe Projects::ServicesController do ...@@ -6,9 +6,10 @@ RSpec.describe Projects::ServicesController do
include JiraServiceHelper include JiraServiceHelper
include AfterNextHelpers include AfterNextHelpers
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:service) { create(:jira_integration, project: project) } let_it_be(:service) { create(:jira_integration, project: project) }
let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } } let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
before do before do
...@@ -17,9 +18,9 @@ RSpec.describe Projects::ServicesController do ...@@ -17,9 +18,9 @@ RSpec.describe Projects::ServicesController do
end end
describe '#test' do describe '#test' do
context 'when can_test? returns false' do context 'when the integration is not testable' do
it 'renders 404' do it 'renders 404' do
allow_any_instance_of(Integration).to receive(:can_test?).and_return(false) allow_any_instance_of(Integration).to receive(:testable?).and_return(false)
put :test, params: project_params put :test, params: project_params
...@@ -41,10 +42,10 @@ RSpec.describe Projects::ServicesController do ...@@ -41,10 +42,10 @@ RSpec.describe Projects::ServicesController do
context 'success' do context 'success' do
context 'with empty project' do context 'with empty project' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
context 'with chat notification service' do context 'with chat notification service' do
let(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') } let_it_be(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
it 'returns success' do it 'returns success' do
allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true)
...@@ -131,8 +132,7 @@ RSpec.describe Projects::ServicesController do ...@@ -131,8 +132,7 @@ RSpec.describe Projects::ServicesController do
context 'with the Slack integration' do context 'with the Slack integration' do
let_it_be(:integration) { build(:integrations_slack) } let_it_be(:integration) { build(:integrations_slack) }
let_it_be(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
let(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
it 'returns an error response when the URL is blocked' do it 'returns an error response when the URL is blocked' do
put :test, params: project_params(service: { webhook: 'http://127.0.0.1' }) put :test, params: project_params(service: { webhook: 'http://127.0.0.1' })
...@@ -259,7 +259,8 @@ RSpec.describe Projects::ServicesController do ...@@ -259,7 +259,8 @@ RSpec.describe Projects::ServicesController do
end end
context 'Prometheus integration' do context 'Prometheus integration' do
let!(:service) { create(:prometheus_integration, project: project) } let_it_be(:service) { create(:prometheus_integration, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } } let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do context 'feature flag :settings_operations_prometheus_service is enabled' do
......
...@@ -139,19 +139,17 @@ RSpec.describe Integration do ...@@ -139,19 +139,17 @@ RSpec.describe Integration do
end end
end end
describe '#can_test?' do describe '#testable?' do
subject { integration.can_test? }
context 'when integration is project-level' do context 'when integration is project-level' do
let(:integration) { build(:service, project: project) } subject { build(:service, project: project) }
it { is_expected.to be true } it { is_expected.to be_testable }
end end
context 'when integration is not project-level' do context 'when integration is not project-level' do
let(:integration) { build(:service, project: nil) } subject { build(:service, project: nil) }
it { is_expected.to be false } it { is_expected.not_to be_testable }
end end
end end
......
...@@ -15,24 +15,6 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -15,24 +15,6 @@ RSpec.describe Integrations::BaseChatNotification do
it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]).allow_blank } it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]).allow_blank }
end end
describe '#can_test?' do
context 'with empty repository' do
it 'returns true' do
subject.project = create(:project, :empty_repo)
expect(subject.can_test?).to be true
end
end
context 'with repository' do
it 'returns true' do
subject.project = create(:project, :repository)
expect(subject.can_test?).to be true
end
end
end
describe '#execute' do describe '#execute' do
subject(:chat_integration) { described_class.new } subject(:chat_integration) { described_class.new }
......
...@@ -341,7 +341,7 @@ RSpec.describe Integrations::Jira do ...@@ -341,7 +341,7 @@ RSpec.describe Integrations::Jira do
context 'when not allowed to test an instance or group' do context 'when not allowed to test an instance or group' do
it 'does not update deployment type' do it 'does not update deployment type' do
allow(integration).to receive(:can_test?).and_return(false) allow(integration).to receive(:testable?).and_return(false)
integration.update!(url: 'http://first.url') integration.update!(url: 'http://first.url')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment