debian-mirror-gitlab/spec/services/resource_events/change_labels_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ResourceEvents::ChangeLabelsService do
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:author) { create(:user) }
2021-09-30 23:02:18 +05:30
2018-11-18 11:00:15 +05:30
let(:resource) { create(:issue, project: project) }
describe '.change_labels' do
subject { described_class.new(resource, author).execute(added_labels: added, removed_labels: removed) }
2021-02-22 17:27:13 +05:30
let_it_be(:labels) { create_list(:label, 2, project: project) }
2018-11-18 11:00:15 +05:30
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
2018-11-20 20:47:30 +05:30
it 'expires resource note etag cache' do
expect_any_instance_of(Gitlab::EtagCaching::Store)
.to receive(:touch)
.with("/#{resource.project.namespace.to_param}/#{resource.project.to_param}/noteable/issue/#{resource.id}/notes")
described_class.new(resource, author).execute(added_labels: [labels[0]])
end
2018-11-18 11:00:15 +05:30
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
2021-12-11 22:18:48 +05:30
expect(ApplicationRecord).to receive(:legacy_bulk_insert).once.and_call_original
2018-11-18 11:00:15 +05:30
expect { subject }.to change { resource.resource_label_events.count }.from(0).to(2)
end
end
2021-02-22 17:27:13 +05:30
describe 'usage data' do
let(:added) { [labels[0]] }
let(:removed) { [labels[1]] }
context 'when resource is an issue' do
it 'tracks changed labels' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_label_changed_action)
subject
end
end
context 'when resource is a merge request' do
let(:resource) { create(:merge_request, source_project: project) }
it 'does not track changed labels' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_label_changed_action)
subject
end
end
end
2018-11-18 11:00:15 +05:30
end
end