Commit 7401c7a5 authored by Eugenia Grieff's avatar Eugenia Grieff

Add specs for BulkUpdateService

parent 51254a44
......@@ -13,6 +13,11 @@ describe Issuable::BulkUpdateService do
let(:epic2) { create(:epic, group: group, labels: [label1]) }
let(:label1) { create(:group_label, group: group) }
before do
group.add_reporter(user)
stub_licensed_features(epics: true)
end
describe 'updating labels' do
let(:label2) { create(:group_label, group: group, title: 'Bug') }
let(:label3) { create(:group_label, group: group, title: 'suggestion') }
......@@ -26,9 +31,21 @@ describe Issuable::BulkUpdateService do
}
end
context 'when epics are enabled' do
it 'updates epic labels' do
result = subject
expect(result[:success]).to be_truthy
expect(result[:count]).to eq(issuables.count)
issuables.each do |issuable|
expect(issuable.reload.labels).to eq([label2, label3])
end
end
end
context 'when epics are disabled' do
before do
group.add_reporter(user)
stub_licensed_features(epics: false)
end
......@@ -39,21 +56,19 @@ describe Issuable::BulkUpdateService do
end
end
context 'when epics are enabled' do
before do
group.add_reporter(user)
stub_licensed_features(epics: true)
end
it 'updates epic labels' do
result = subject
context 'when issuable_ids contain external epics' do
it 'updates epics that belong to the parent group or descendants' do
epic3 = create(:epic, labels: [label1])
epic4 = create(:epic, group: create(:group, parent: group), labels: [label1])
params = { issuable_ids: [epic1.id, epic3.id, epic4.id], add_label_ids: [label3.id] }
result = described_class.new(group, user, params).execute('epic')
expect(result[:success]).to be_truthy
expect(result[:count]).to eq(issuables.count)
expect(result[:count]).to eq(2)
issuables.each do |issuable|
expect(issuable.reload.labels).to eq([label2, label3])
end
expect(epic1.reload.labels).to eq([label1, label3])
expect(epic3.reload.labels).to eq([label1])
expect(epic4.reload.labels).to eq([label1, label3])
end
end
end
......
......@@ -202,33 +202,6 @@ describe Issuable::BulkUpdateService do
expect(project.issues.opened).to be_empty
expect(project.issues.closed).not_to be_empty
end
context 'when issue for a different project is created' do
let(:private_project) { create(:project, :private) }
let(:issue) { create(:issue, project: private_project, author: user) }
context 'when user has access to the project' do
it 'closes all issues passed' do
private_project.add_maintainer(user)
bulk_update(issues + [issue], state_event: 'close')
expect(project.issues.opened).to be_empty
expect(project.issues.closed).not_to be_empty
expect(private_project.issues.closed).not_to be_empty
end
end
context 'when user does not have access to project' do
it 'only closes all issues that the user has access to' do
bulk_update(issues + [issue], state_event: 'close')
expect(project.issues.opened).to be_empty
expect(project.issues.closed).not_to be_empty
expect(private_project.issues.closed).to be_empty
end
end
end
end
describe 'reopen issues' do
......@@ -364,12 +337,30 @@ describe Issuable::BulkUpdateService do
end
end
end
describe 'updating issuables from external project' do
it 'updates issuables that belong to the parent project' do
issue1 = create(:issue, project: project)
issue2 = create(:issue, project: create(:project))
result = bulk_update([issue1, issue2], assignee_ids: [user.id])
expect(result[:success]).to be_truthy
expect(result[:count]).to eq(1)
expect(issue1.reload.assignees).to eq([user])
expect(issue2.reload.assignees).to be_empty
end
end
end
context 'with issuables at a group level' do
let(:group) { create(:group) }
let(:parent) { group }
before do
group.add_reporter(user)
end
describe 'updating milestones' do
let(:milestone) { create(:milestone, group: group) }
let(:project) { create(:project, :repository, group: group) }
......@@ -401,11 +392,24 @@ describe Issuable::BulkUpdateService do
let(:regression) { create(:group_label, group: group) }
let(:merge_requests) { create(:group_label, group: group) }
before do
group.add_reporter(user)
end
it_behaves_like 'updating labels'
end
describe 'updating issuables from external group' do
it 'updates issuables that belong to the parent group or descendants' do
issue1 = create(:issue, project: create(:project, group: group))
issue2 = create(:issue, project: create(:project, group: create(:group)))
issue3 = create(:issue, project: create(:project, group: create(:group, parent: group)))
milestone = create(:milestone, group: group)
result = bulk_update([issue1, issue2, issue3], milestone_id: milestone.id)
expect(result[:success]).to be_truthy
expect(result[:count]).to eq(2)
expect(issue1.reload.milestone).to eq(milestone)
expect(issue2.reload.milestone).to be_nil
expect(issue3.reload.milestone).to eq(milestone)
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