summaryrefslogtreecommitdiff
path: root/spec/services/todo_service_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-04-29 12:29:59 +0000
committerStan Hu <stanhu@gmail.com>2017-04-29 12:29:59 +0000
commit303504df4788fead8ab200dd5490658489ba5385 (patch)
tree1b913d761b84fe3251e216713c67e640967d1522 /spec/services/todo_service_spec.rb
parent3717d21db1b17b2e18e6843d41a2c23d006918e9 (diff)
downloadgitlab-ce-303504df4788fead8ab200dd5490658489ba5385.tar.gz
Revert "Merge branch 'tc-no-todo-service-select' into 'master'"revert-c3c465ac
This reverts merge request !10845
Diffstat (limited to 'spec/services/todo_service_spec.rb')
-rw-r--r--spec/services/todo_service_spec.rb48
1 files changed, 17 insertions, 31 deletions
diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb
index 801657d6c0c..89b3b6aad10 100644
--- a/spec/services/todo_service_spec.rb
+++ b/spec/services/todo_service_spec.rb
@@ -336,7 +336,7 @@ describe TodoService, services: true do
describe '#mark_todos_as_done' do
it_behaves_like 'updating todos state', :mark_todos_as_done, :pending, :done do
- let(:collection) { Todo.all }
+ let(:collection) { [first_todo, second_todo] }
end
end
@@ -348,7 +348,7 @@ describe TodoService, services: true do
describe '#mark_todos_as_pending' do
it_behaves_like 'updating todos state', :mark_todos_as_pending, :done, :pending do
- let(:collection) { Todo.all }
+ let(:collection) { [first_todo, second_todo] }
end
end
@@ -873,15 +873,21 @@ describe TodoService, services: true do
create(:todo, :mentioned, user: john_doe, target: issue, project: project)
todos = TodosFinder.new(john_doe, {}).execute
- expect { service.mark_todos_as_done(todos, john_doe) }
+ expect { TodoService.new.mark_todos_as_done(todos, john_doe) }
.to change { john_doe.todos.done.count }.from(0).to(1)
end
+ it 'marks an array of todos as done' do
+ todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
+
+ expect { TodoService.new.mark_todos_as_done([todo], john_doe) }
+ .to change { todo.reload.state }.from('pending').to('done')
+ end
+
it 'returns the ids of updated todos' do # Needed on API
todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
- todos = TodosFinder.new(john_doe, {}).execute
- expect(service.mark_todos_as_done(todos, john_doe)).to eq([todo.id])
+ expect(TodoService.new.mark_todos_as_done([todo], john_doe)).to eq([todo.id])
end
context 'when some of the todos are done already' do
@@ -889,43 +895,23 @@ describe TodoService, services: true do
let!(:second_todo) { create(:todo, :mentioned, user: john_doe, target: another_issue, project: project) }
it 'returns the ids of those still pending' do
- service.mark_pending_todos_as_done(issue, john_doe)
+ TodoService.new.mark_pending_todos_as_done(issue, john_doe)
- expect(service.mark_todos_as_done(Todo.all, john_doe)).to eq([second_todo.id])
+ expect(TodoService.new.mark_todos_as_done(Todo.all, john_doe)).to eq([second_todo.id])
end
it 'returns an empty array if all are done' do
- service.mark_pending_todos_as_done(issue, john_doe)
- service.mark_pending_todos_as_done(another_issue, john_doe)
+ TodoService.new.mark_pending_todos_as_done(issue, john_doe)
+ TodoService.new.mark_pending_todos_as_done(another_issue, john_doe)
- expect(service.mark_todos_as_done(Todo.all, john_doe)).to eq([])
+ expect(TodoService.new.mark_todos_as_done(Todo.all, john_doe)).to eq([])
end
end
- end
-
- describe '#mark_todos_as_done_by_ids' do
- let(:issue) { create(:issue, project: project, author: author, assignee: john_doe) }
- let(:another_issue) { create(:issue, project: project, author: author, assignee: john_doe) }
-
- it 'marks an array of todo ids as done' do
- todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
- another_todo = create(:todo, :mentioned, user: john_doe, target: another_issue, project: project)
-
- expect { service.mark_todos_as_done_by_ids([todo.id, another_todo.id], john_doe) }
- .to change { john_doe.todos.done.count }.from(0).to(2)
- end
-
- it 'marks a single todo id as done' do
- todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
-
- expect { service.mark_todos_as_done_by_ids(todo.id, john_doe) }
- .to change { todo.reload.state }.from('pending').to('done')
- end
it 'caches the number of todos of a user', :caching do
create(:todo, :mentioned, user: john_doe, target: issue, project: project)
todo = create(:todo, :mentioned, user: john_doe, target: issue, project: project)
- service.mark_todos_as_done_by_ids(todo, john_doe)
+ TodoService.new.mark_todos_as_done([todo], john_doe)
expect_any_instance_of(TodosFinder).not_to receive(:execute)