2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe PendingTodosFinder do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:user) { create(:user) }
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:users) { [user, user2] }
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'returns only pending todos' do
|
|
|
|
create(:todo, :done, user: user)
|
|
|
|
|
|
|
|
todo = create(:todo, :pending, user: user)
|
2021-04-29 21:17:54 +05:30
|
|
|
todos = described_class.new(users).execute
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(todos).to eq([todo])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports retrieving of todos for a specific project' do
|
|
|
|
project1 = create(:project)
|
|
|
|
project2 = create(:project)
|
|
|
|
|
|
|
|
create(:todo, :pending, user: user, project: project2)
|
|
|
|
|
|
|
|
todo = create(:todo, :pending, user: user, project: project1)
|
2021-04-29 21:17:54 +05:30
|
|
|
todos = described_class.new(users, project_id: project1.id).execute
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(todos).to eq([todo])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports retrieving of todos for a specific todo target' do
|
|
|
|
issue = create(:issue)
|
|
|
|
note = create(:note)
|
|
|
|
todo = create(:todo, :pending, user: user, target: issue)
|
|
|
|
|
|
|
|
create(:todo, :pending, user: user, target: note)
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
todos = described_class.new(users, target_id: issue.id).execute
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(todos).to eq([todo])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports retrieving of todos for a specific target type' do
|
|
|
|
issue = create(:issue)
|
|
|
|
note = create(:note)
|
|
|
|
todo = create(:todo, :pending, user: user, target: issue)
|
|
|
|
|
|
|
|
create(:todo, :pending, user: user, target: note)
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
todos = described_class.new(users, target_type: issue.class.name).execute
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(todos).to eq([todo])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports retrieving of todos for a specific commit ID' do
|
|
|
|
create(:todo, :pending, user: user, commit_id: '456')
|
|
|
|
|
|
|
|
todo = create(:todo, :pending, user: user, commit_id: '123')
|
2021-04-29 21:17:54 +05:30
|
|
|
todos = described_class.new(users, commit_id: '123').execute
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(todos).to eq([todo])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|