summaryrefslogtreecommitdiff
path: root/spec/services/boards/issues
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/boards/issues')
-rw-r--r--spec/services/boards/issues/list_service_spec.rb157
-rw-r--r--spec/services/boards/issues/move_service_spec.rb119
2 files changed, 113 insertions, 163 deletions
diff --git a/spec/services/boards/issues/list_service_spec.rb b/spec/services/boards/issues/list_service_spec.rb
index ff5733b7064..b4efa3e44b6 100644
--- a/spec/services/boards/issues/list_service_spec.rb
+++ b/spec/services/boards/issues/list_service_spec.rb
@@ -2,98 +2,103 @@ require 'spec_helper'
describe Boards::Issues::ListService do
describe '#execute' do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:board) { create(:board, project: project) }
-
- let(:bug) { create(:label, project: project, name: 'Bug') }
- let(:development) { create(:label, project: project, name: 'Development') }
- let(:testing) { create(:label, project: project, name: 'Testing') }
- let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
- let(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
- let(:p3) { create(:label, title: 'P3', project: project, priority: 3) }
-
- let!(:backlog) { create(:backlog_list, board: board) }
- let!(:list1) { create(:list, board: board, label: development, position: 0) }
- let!(:list2) { create(:list, board: board, label: testing, position: 1) }
- let!(:closed) { create(:closed_list, board: board) }
-
- let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) }
- let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) }
- let!(:reopened_issue1) { create(:issue, :opened, project: project) }
-
- let!(:list1_issue1) { create(:labeled_issue, project: project, labels: [p2, development]) }
- let!(:list1_issue2) { create(:labeled_issue, project: project, labels: [development]) }
- let!(:list1_issue3) { create(:labeled_issue, project: project, labels: [development, p1]) }
- let!(:list2_issue1) { create(:labeled_issue, project: project, labels: [testing]) }
-
- let!(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
- let!(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3]) }
- let!(:closed_issue3) { create(:issue, :closed, project: project) }
- let!(:closed_issue4) { create(:labeled_issue, :closed, project: project, labels: [p1]) }
- let!(:closed_issue5) { create(:labeled_issue, :closed, project: project, labels: [development]) }
-
- before do
- project.add_developer(user)
- end
-
- it 'delegates search to IssuesFinder' do
- params = { board_id: board.id, id: list1.id }
-
- expect_any_instance_of(IssuesFinder).to receive(:execute).once.and_call_original
+ context 'when parent is a project' do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+ let(:board) { create(:board, project: project) }
+
+ let(:m1) { create(:milestone, project: project) }
+ let(:m2) { create(:milestone, project: project) }
+
+ let(:bug) { create(:label, project: project, name: 'Bug') }
+ let(:development) { create(:label, project: project, name: 'Development') }
+ let(:testing) { create(:label, project: project, name: 'Testing') }
+ let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
+ let(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
+ let(:p3) { create(:label, title: 'P3', project: project, priority: 3) }
+
+ let!(:backlog) { create(:backlog_list, board: board) }
+ let!(:list1) { create(:list, board: board, label: development, position: 0) }
+ let!(:list2) { create(:list, board: board, label: testing, position: 1) }
+ let!(:closed) { create(:closed_list, board: board) }
+
+ let!(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) }
+ let!(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2]) }
+ let!(:reopened_issue1) { create(:issue, :opened, project: project, title: 'Issue 3' ) }
+
+ let!(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, development]) }
+ let!(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) }
+ let!(:list1_issue3) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1]) }
+ let!(:list2_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [testing]) }
+
+ let!(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
+ let!(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3]) }
+ let!(:closed_issue3) { create(:issue, :closed, project: project) }
+ let!(:closed_issue4) { create(:labeled_issue, :closed, project: project, labels: [p1]) }
+ let!(:closed_issue5) { create(:labeled_issue, :closed, project: project, labels: [development]) }
+
+ let(:parent) { project }
+
+ before do
+ project.add_developer(user)
+ end
- described_class.new(project, user, params).execute
+ it_behaves_like 'issues list service'
end
- context 'issues are ordered by priority' do
- it 'returns opened issues when list_id is missing' do
- params = { board_id: board.id }
-
- issues = described_class.new(project, user, params).execute
-
- expect(issues).to eq [opened_issue2, reopened_issue1, opened_issue1]
- end
+ context 'when parent is a group' do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:project) { create(:project, :empty_repo, namespace: group) }
+ let(:project1) { create(:project, :empty_repo, namespace: group) }
+ let(:board) { create(:board, group: group) }
- it 'returns opened issues when listing issues from Backlog' do
- params = { board_id: board.id, id: backlog.id }
+ let(:m1) { create(:milestone, group: group) }
+ let(:m2) { create(:milestone, group: group) }
- issues = described_class.new(project, user, params).execute
+ let(:bug) { create(:group_label, group: group, name: 'Bug') }
+ let(:development) { create(:group_label, group: group, name: 'Development') }
+ let(:testing) { create(:group_label, group: group, name: 'Testing') }
- expect(issues).to eq [opened_issue2, reopened_issue1, opened_issue1]
- end
+ let(:p1) { create(:group_label, title: 'P1', group: group) }
+ let(:p2) { create(:group_label, title: 'P2', group: group) }
+ let(:p3) { create(:group_label, title: 'P3', group: group) }
- it 'returns closed issues when listing issues from Closed' do
- params = { board_id: board.id, id: closed.id }
+ let(:p1_project) { create(:label, title: 'P1_project', project: project, priority: 1) }
+ let(:p2_project) { create(:label, title: 'P2_project', project: project, priority: 2) }
+ let(:p3_project) { create(:label, title: 'P3_project', project: project, priority: 3) }
- issues = described_class.new(project, user, params).execute
+ let(:p1_project1) { create(:label, title: 'P1_project1', project: project1, priority: 1) }
+ let(:p2_project1) { create(:label, title: 'P2_project1', project: project1, priority: 2) }
+ let(:p3_project1) { create(:label, title: 'P3_project1', project: project1, priority: 3) }
- expect(issues).to eq [closed_issue4, closed_issue2, closed_issue5, closed_issue3, closed_issue1]
- end
+ let!(:backlog) { create(:backlog_list, board: board) }
+ let!(:list1) { create(:list, board: board, label: development, position: 0) }
+ let!(:list2) { create(:list, board: board, label: testing, position: 1) }
+ let!(:closed) { create(:closed_list, board: board) }
- it 'returns opened issues that have label list applied when listing issues from a label list' do
- params = { board_id: board.id, id: list1.id }
+ let!(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) }
+ let!(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2, p2_project]) }
+ let!(:reopened_issue1) { create(:issue, state: 'opened', project: project, title: 'Issue 3', closed_at: Time.now ) }
- issues = described_class.new(project, user, params).execute
+ let!(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, p2_project, development]) }
+ let!(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) }
+ let!(:list1_issue3) { create(:labeled_issue, project: project1, milestone: m1, labels: [development, p1, p1_project1]) }
+ let!(:list2_issue1) { create(:labeled_issue, project: project1, milestone: m1, labels: [testing]) }
- expect(issues).to eq [list1_issue3, list1_issue1, list1_issue2]
- end
- end
+ let!(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
+ let!(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3, p3_project]) }
+ let!(:closed_issue3) { create(:issue, :closed, project: project1) }
+ let!(:closed_issue4) { create(:labeled_issue, :closed, project: project1, labels: [p1, p1_project1]) }
+ let!(:closed_issue5) { create(:labeled_issue, :closed, project: project1, labels: [development]) }
- context 'with list that does not belong to the board' do
- it 'raises an error' do
- list = create(:list)
- service = described_class.new(project, user, board_id: board.id, id: list.id)
+ let(:parent) { group }
- expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
+ before do
+ group.add_developer(user)
end
- end
-
- context 'with invalid list id' do
- it 'raises an error' do
- service = described_class.new(project, user, board_id: board.id, id: nil)
- expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
- end
+ it_behaves_like 'issues list service'
end
end
end
diff --git a/spec/services/boards/issues/move_service_spec.rb b/spec/services/boards/issues/move_service_spec.rb
index 280e411683e..0a6b6d880d3 100644
--- a/spec/services/boards/issues/move_service_spec.rb
+++ b/spec/services/boards/issues/move_service_spec.rb
@@ -2,108 +2,53 @@ require 'spec_helper'
describe Boards::Issues::MoveService do
describe '#execute' do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:board1) { create(:board, project: project) }
-
- let(:bug) { create(:label, project: project, name: 'Bug') }
- let(:development) { create(:label, project: project, name: 'Development') }
- let(:testing) { create(:label, project: project, name: 'Testing') }
-
- let!(:list1) { create(:list, board: board1, label: development, position: 0) }
- let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
- let!(:closed) { create(:closed_list, board: board1) }
-
- before do
- project.add_developer(user)
- end
-
- context 'when moving an issue between lists' do
- let(:issue) { create(:labeled_issue, project: project, labels: [bug, development]) }
- let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list2.id } }
-
- it 'delegates the label changes to Issues::UpdateService' do
- expect_any_instance_of(Issues::UpdateService).to receive(:execute).with(issue).once
-
- described_class.new(project, user, params).execute(issue)
- end
-
- it 'removes the label from the list it came from and adds the label of the list it goes to' do
- described_class.new(project, user, params).execute(issue)
-
- expect(issue.reload.labels).to contain_exactly(bug, testing)
- end
- end
-
- context 'when moving to closed' do
+ context 'when parent is a project' do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+ let(:board1) { create(:board, project: project) }
let(:board2) { create(:board, project: project) }
+
+ let(:bug) { create(:label, project: project, name: 'Bug') }
+ let(:development) { create(:label, project: project, name: 'Development') }
+ let(:testing) { create(:label, project: project, name: 'Testing') }
let(:regression) { create(:label, project: project, name: 'Regression') }
- let!(:list3) { create(:list, board: board2, label: regression, position: 1) }
- let(:issue) { create(:labeled_issue, project: project, labels: [bug, development, testing, regression]) }
- let(:params) { { board_id: board1.id, from_list_id: list2.id, to_list_id: closed.id } }
+ let!(:list1) { create(:list, board: board1, label: development, position: 0) }
+ let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
+ let!(:closed) { create(:closed_list, board: board1) }
- it 'delegates the close proceedings to Issues::CloseService' do
- expect_any_instance_of(Issues::CloseService).to receive(:execute).with(issue).once
+ let(:parent) { project }
- described_class.new(project, user, params).execute(issue)
+ before do
+ parent.add_developer(user)
end
- it 'removes all list-labels from project boards and close the issue' do
- described_class.new(project, user, params).execute(issue)
- issue.reload
-
- expect(issue.labels).to contain_exactly(bug)
- expect(issue).to be_closed
- end
+ it_behaves_like 'issues move service'
end
- context 'when moving from closed' do
- let(:issue) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
- let(:params) { { board_id: board1.id, from_list_id: closed.id, to_list_id: list2.id } }
-
- it 'delegates the re-open proceedings to Issues::ReopenService' do
- expect_any_instance_of(Issues::ReopenService).to receive(:execute).with(issue).once
-
- described_class.new(project, user, params).execute(issue)
- end
-
- it 'adds the label of the list it goes to and reopen the issue' do
- described_class.new(project, user, params).execute(issue)
- issue.reload
-
- expect(issue.labels).to contain_exactly(bug, testing)
- expect(issue).to be_opened
- end
- end
+ context 'when parent is a group' do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:project) { create(:project, namespace: group) }
+ let(:board1) { create(:board, group: group) }
+ let(:board2) { create(:board, group: group) }
- context 'when moving to same list' do
- let(:issue) { create(:labeled_issue, project: project, labels: [bug, development]) }
- let(:issue1) { create(:labeled_issue, project: project, labels: [bug, development]) }
- let(:issue2) { create(:labeled_issue, project: project, labels: [bug, development]) }
- let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list1.id } }
+ let(:bug) { create(:group_label, group: group, name: 'Bug') }
+ let(:development) { create(:group_label, group: group, name: 'Development') }
+ let(:testing) { create(:group_label, group: group, name: 'Testing') }
+ let(:regression) { create(:group_label, group: group, name: 'Regression') }
- it 'returns false' do
- expect(described_class.new(project, user, params).execute(issue)).to eq false
- end
+ let!(:list1) { create(:list, board: board1, label: development, position: 0) }
+ let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
+ let!(:closed) { create(:closed_list, board: board1) }
- it 'keeps issues labels' do
- described_class.new(project, user, params).execute(issue)
+ let(:parent) { group }
- expect(issue.reload.labels).to contain_exactly(bug, development)
+ before do
+ parent.add_developer(user)
end
- it 'sorts issues' do
- [issue, issue1, issue2].each do |issue|
- issue.move_to_end && issue.save!
- end
-
- params.merge!(move_after_id: issue1.id, move_before_id: issue2.id)
-
- described_class.new(project, user, params).execute(issue)
-
- expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position)
- end
+ it_behaves_like 'issues move service'
end
end
end