blob: 168229d6ed91d7d5b079c05478b98b855b6280ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::AbuseReportLabels::CreateService, feature_category: :insider_threat do
describe '#execute' do
let(:color) { 'red' }
let(:color_in_hex) { ::Gitlab::Color.of(color) }
let(:params) { { title: 'FancyLabel', color: color } }
subject(:execute) { described_class.new(params).execute }
shared_examples 'creates a label with the correct values' do
it 'creates a label with the correct values', :aggregate_failures do
expect { execute }.to change { Admin::AbuseReportLabel.count }.from(0).to(1)
label = Admin::AbuseReportLabel.last
expect(label.title).to eq params[:title]
expect(label.color).to eq color_in_hex
end
it 'returns the persisted label' do
result = execute
expect(result).to be_an_instance_of(Admin::AbuseReportLabel)
expect(result.persisted?).to eq true
end
end
it_behaves_like 'creates a label with the correct values'
context 'without color param' do
let(:params) { { title: 'FancyLabel' } }
let(:color_in_hex) { ::Gitlab::Color.of(Label::DEFAULT_COLOR) }
it_behaves_like 'creates a label with the correct values'
end
context 'with errors' do
let!(:existing_label) { create(:abuse_report_label, title: params[:title]) }
it 'does not create the label' do
expect { execute }.not_to change { Admin::AbuseReportLabel.count }
end
it 'returns the label with errors' do
label = execute
expect(label.errors.messages).to include({ title: ["has already been taken"] })
end
end
end
end
|