summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-15 16:13:52 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-20 12:10:26 -0200
commit422a01fc853a93e8946c69dc2ad0ad1dea261653 (patch)
treebd50032c0cc5df5b2cb2a70f1202cbf4ad9c583d /spec
parent1e0053f2dca63fdba18811a2194a36f828d45486 (diff)
downloadgitlab-ce-422a01fc853a93e8946c69dc2ad0ad1dea261653.tar.gz
Create a pending task when an issue is assigned to someone
Diffstat (limited to 'spec')
-rw-r--r--spec/services/issues/create_service_spec.rb22
-rw-r--r--spec/services/issues/update_service_spec.rb13
-rw-r--r--spec/services/task_service_spec.rb59
3 files changed, 92 insertions, 2 deletions
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb
index 2148d091a57..f3b66779987 100644
--- a/spec/services/issues/create_service_spec.rb
+++ b/spec/services/issues/create_service_spec.rb
@@ -3,14 +3,18 @@ require 'spec_helper'
describe Issues::CreateService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
+ let(:assignee) { create(:user) }
describe :execute do
- context "valid params" do
+ context 'valid params' do
before do
project.team << [user, :master]
+ project.team << [assignee, :master]
+
opts = {
title: 'Awesome issue',
- description: 'please fix'
+ description: 'please fix',
+ assignee: assignee
}
@issue = Issues::CreateService.new(project, user, opts).execute
@@ -18,6 +22,20 @@ describe Issues::CreateService, services: true do
it { expect(@issue).to be_valid }
it { expect(@issue.title).to eq('Awesome issue') }
+ it { expect(@issue.assignee).to eq assignee }
+
+ it 'creates a pending task for new assignee' do
+ attributes = {
+ project: project,
+ author: user,
+ user: assignee,
+ target: @issue,
+ action: Task::ASSIGNED,
+ state: :pending
+ }
+
+ expect(Task.where(attributes).count).to eq 1
+ end
end
end
end
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 87da0e9618b..8f654517bce 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -78,6 +78,19 @@ describe Issues::UpdateService, services: true do
expect(note).not_to be_nil
expect(note.note).to eq 'Title changed from **Old title** to **New title**'
end
+
+ it 'creates a pending task if being reassigned' do
+ attributes = {
+ project: project,
+ author: user,
+ user: user2,
+ target: issue,
+ action: Task::ASSIGNED,
+ state: :pending
+ }
+
+ expect(Task.where(attributes).count).to eq 1
+ end
end
context 'when Issue has tasks' do
diff --git a/spec/services/task_service_spec.rb b/spec/services/task_service_spec.rb
new file mode 100644
index 00000000000..ee3c4f8f95d
--- /dev/null
+++ b/spec/services/task_service_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+describe TaskService, services: true do
+ let(:service) { described_class.new }
+
+ describe 'Issues' do
+ let(:author) { create(:user) }
+ let(:john_doe) { create(:user) }
+ let(:project) { create(:empty_project, :public) }
+ let(:assigned_issue) { create(:issue, project: project, assignee: john_doe) }
+ let(:unassigned_issue) { create(:issue, project: project, assignee: nil) }
+
+ before do
+ project.team << [author, :developer]
+ project.team << [john_doe, :developer]
+ end
+
+ describe '#new_issue' do
+ it 'creates a pending task if assigned' do
+ service.new_issue(assigned_issue, author)
+
+ is_expected_to_create_pending_task(user: john_doe, target: assigned_issue, action: Task::ASSIGNED)
+ end
+
+ it 'does not create a task if unassigned' do
+ is_expected_to_not_create_task { service.new_issue(unassigned_issue, author) }
+ end
+ end
+
+ describe '#reassigned_issue' do
+ it 'creates a pending task for new assignee' do
+ unassigned_issue.update_attribute(:assignee, john_doe)
+ service.reassigned_issue(unassigned_issue, author)
+
+ is_expected_to_create_pending_task(user: john_doe, target: unassigned_issue, action: Task::ASSIGNED)
+ end
+
+ it 'does not create a task if unassigned' do
+ assigned_issue.update_attribute(:assignee, nil)
+
+ is_expected_to_not_create_task { service.reassigned_issue(assigned_issue, author) }
+ end
+ end
+ end
+
+ def is_expected_to_create_pending_task(attributes = {})
+ attributes.reverse_merge!(
+ project: project,
+ author: author,
+ state: :pending
+ )
+
+ expect(Task.where(attributes).count).to eq 1
+ end
+
+ def is_expected_to_not_create_task
+ expect { yield }.not_to change(Task, :count)
+ end
+end