summaryrefslogtreecommitdiff
path: root/spec/models/project_services/alerts_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_services/alerts_service_spec.rb')
-rw-r--r--spec/models/project_services/alerts_service_spec.rb110
1 files changed, 20 insertions, 90 deletions
diff --git a/spec/models/project_services/alerts_service_spec.rb b/spec/models/project_services/alerts_service_spec.rb
index db25885c76a..75b91c29914 100644
--- a/spec/models/project_services/alerts_service_spec.rb
+++ b/spec/models/project_services/alerts_service_spec.rb
@@ -2,108 +2,38 @@
require 'spec_helper'
+# AlertsService is stripped down to only required methods
+# to avoid errors loading integration-related pages if
+# records are present.
RSpec.describe AlertsService do
let_it_be(:project) { create(:project) }
- let(:service_params) { { project: project, active: active } }
- let(:active) { true }
- let(:service) { described_class.new(service_params) }
+ subject(:service) { described_class.new(project: project) }
- shared_context 'when active' do
- let(:active) { true }
- end
-
- shared_context 'when inactive' do
- let(:active) { false }
- end
-
- shared_context 'when persisted' do
- before do
- service.save!
- service.reload
- end
- end
-
- describe '#url' do
- include Gitlab::Routing
-
- subject { service.url }
+ it { is_expected.to be_valid }
- it { is_expected.to eq(project_alerts_notify_url(project, format: :json)) }
- end
-
- describe '#json_fields' do
- subject { service.json_fields }
+ describe '#to_param' do
+ subject { service.to_param }
- it { is_expected.to eq(%w(active token)) }
+ it { is_expected.to eq('alerts') }
end
- describe '#as_json' do
- subject { service.as_json(only: service.json_fields) }
+ describe '#supported_events' do
+ subject { service.supported_events }
- it { is_expected.to eq('active' => true, 'token' => nil) }
+ it { is_expected.to be_empty }
end
- describe '#token' do
- shared_context 'reset token' do
- before do
- service.token = ''
- service.valid?
- end
- end
-
- shared_context 'assign token' do |token|
- before do
- service.token = token
- service.valid?
- end
- end
-
- shared_examples 'valid token' do
- it { is_expected.to match(/\A\h{32}\z/) }
- end
-
- shared_examples 'no token' do
- it { is_expected.to be_blank }
- end
-
- subject { service.token }
-
- context 'when active' do
- include_context 'when active'
-
- context 'when resetting' do
- let!(:previous_token) { service.token }
-
- include_context 'reset token'
-
- it_behaves_like 'valid token'
-
- it { is_expected.not_to eq(previous_token) }
- end
-
- context 'when assigning' do
- include_context 'assign token', 'random token'
-
- it_behaves_like 'valid token'
- end
- end
-
- context 'when inactive' do
- include_context 'when inactive'
-
- context 'when resetting' do
- let!(:previous_token) { service.token }
-
- include_context 'reset token'
-
- it_behaves_like 'no token'
- end
- end
+ describe '#save' do
+ it 'prevents records from being created or updated' do
+ expect(Gitlab::ProjectServiceLogger).to receive(:error).with(
+ hash_including(message: 'Prevented attempt to save or update deprecated AlertsService')
+ )
- context 'when persisted' do
- include_context 'when persisted'
+ expect(service.save).to be_falsey
- it_behaves_like 'valid token'
+ expect(service.errors.full_messages).to include(
+ 'Alerts endpoint is deprecated and should not be created or modified. Use HTTP Integrations instead.'
+ )
end
end
end