diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-08-01 08:58:49 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-01 08:58:49 +0000 |
commit | 6b2b3d7f49db024678775da3a3685bbdd9bbee65 (patch) | |
tree | 2108bf9c394c2e3197ba994ef40e1b02d799bf55 /spec/services/resource_events | |
parent | bd659f70b18be07dac184ca249c7eee17c703e56 (diff) | |
download | gitlab-ce-6b2b3d7f49db024678775da3a3685bbdd9bbee65.tar.gz |
Resource event model
Diffstat (limited to 'spec/services/resource_events')
-rw-r--r-- | spec/services/resource_events/change_labels_service_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/services/resource_events/change_labels_service_spec.rb b/spec/services/resource_events/change_labels_service_spec.rb new file mode 100644 index 00000000000..41b0fb3eea3 --- /dev/null +++ b/spec/services/resource_events/change_labels_service_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ResourceEvents::ChangeLabelsService do + set(:project) { create(:project) } + set(:author) { create(:user) } + let(:resource) { create(:issue, project: project) } + + describe '.change_labels' do + subject { described_class.new(resource, author).execute(added_labels: added, removed_labels: removed) } + + let(:labels) { create_list(:label, 2, project: project) } + + def expect_label_event(event, label, action) + expect(event.user).to eq(author) + expect(event.label).to eq(label) + expect(event.action).to eq(action) + end + + context 'when adding a label' do + let(:added) { [labels[0]] } + let(:removed) { [] } + + it 'creates new label event' do + expect { subject }.to change { resource.resource_label_events.count }.from(0).to(1) + + expect_label_event(resource.resource_label_events.first, labels[0], 'add') + end + end + + context 'when removing a label' do + let(:added) { [] } + let(:removed) { [labels[1]] } + + it 'creates new label event' do + expect { subject }.to change { resource.resource_label_events.count }.from(0).to(1) + + expect_label_event(resource.resource_label_events.first, labels[1], 'remove') + end + end + + context 'when both adding and removing labels' do + let(:added) { [labels[0]] } + let(:removed) { [labels[1]] } + + it 'creates all label events in a single query' do + expect(Gitlab::Database).to receive(:bulk_insert).once.and_call_original + expect { subject }.to change { resource.resource_label_events.count }.from(0).to(2) + end + end + end +end |