Commit 24b5589c authored by Sean Arnold's avatar Sean Arnold

Fix some tests

parent b1044aeb
...@@ -27,6 +27,7 @@ module AlertManagement ...@@ -27,6 +27,7 @@ module AlertManagement
has_many :notes, as: :noteable, inverse_of: :noteable, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_many :notes, as: :noteable, inverse_of: :noteable, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :ordered_notes, -> { fresh }, as: :noteable, class_name: 'Note' has_many :ordered_notes, -> { fresh }, as: :noteable, class_name: 'Note'
has_many :user_mentions, class_name: 'AlertManagement::AlertUserMention', foreign_key: :alert_management_alert_id has_many :user_mentions, class_name: 'AlertManagement::AlertUserMention', foreign_key: :alert_management_alert_id
has_many :metric_images, class_name: '::AlertManagement::MetricImage'
has_internal_id :iid, scope: :project has_internal_id :iid, scope: :project
......
...@@ -9,7 +9,6 @@ module EE ...@@ -9,7 +9,6 @@ module EE
include AfterCommitQueue include AfterCommitQueue
has_many :pending_escalations, class_name: 'IncidentManagement::PendingEscalations::Alert', foreign_key: :alert_id, inverse_of: :alert has_many :pending_escalations, class_name: 'IncidentManagement::PendingEscalations::Alert', foreign_key: :alert_id, inverse_of: :alert
has_many :metric_images, class_name: '::AlertManagement::MetricImage'
after_create do |alert| after_create do |alert|
run_after_commit { alert.trigger_auto_rollback } run_after_commit { alert.trigger_auto_rollback }
......
...@@ -12,6 +12,7 @@ module Gitlab ...@@ -12,6 +12,7 @@ module Gitlab
file file
import_export import_export
issuable_metric_image issuable_metric_image
metric_image
namespace_file namespace_file
personal_file personal_file
].freeze ].freeze
......
...@@ -19,6 +19,8 @@ RSpec.describe AlertManagement::MetricImage do ...@@ -19,6 +19,8 @@ RSpec.describe AlertManagement::MetricImage do
describe '.available_for?' do describe '.available_for?' do
subject { described_class.available_for?(issue.project) } subject { described_class.available_for?(issue.project) }
let_it_be_with_refind(:issue) { create(:issue) }
it { is_expected.to eq(true) } it { is_expected.to eq(true) }
end end
end end
...@@ -44,43 +44,35 @@ RSpec.describe AlertManagement::MetricImages::UploadService do ...@@ -44,43 +44,35 @@ RSpec.describe AlertManagement::MetricImages::UploadService do
project.add_developer(current_user) project.add_developer(current_user)
end end
it_behaves_like 'no metric saved, an error given', 'You are not authorized to upload metric images' it_behaves_like 'uploads the metric'
context 'with license' do context 'no url given' do
before do let(:params) do
stub_licensed_features(alert_metric_upload: true) {
file: fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg')
}
end end
it_behaves_like 'uploads the metric' it_behaves_like 'uploads the metric'
end
context 'no url given' do context 'record invalid' do
let(:params) do let(:params) do
{ {
file: fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') file: fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain'),
} url: 'https://www.gitlab.com'
end }
it_behaves_like 'uploads the metric'
end end
context 'record invalid' do it_behaves_like 'no metric saved, an error given', /File does not have a supported extension. Only png, jpg, jpeg, gif, bmp, tiff, ico, and webp are supported/ # rubocop: disable Layout/LineLength
let(:params) do end
{
file: fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain'),
url: 'https://www.gitlab.com'
}
end
it_behaves_like 'no metric saved, an error given', /File does not have a supported extension. Only png, jpg, jpeg, gif, bmp, tiff, ico, and webp are supported/ context 'user is guest' do
before_all do
project.add_guest(current_user)
end end
context 'user is guest' do it_behaves_like 'no metric saved, an error given', 'You are not authorized to upload metric images'
before_all do
project.add_guest(current_user)
end
it_behaves_like 'no metric saved, an error given', 'You are not authorized to upload metric images'
end
end end
end end
end end
......
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