debian-mirror-gitlab/spec/finders/todos_finder_spec.rb

76 lines
2.8 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
require 'spec_helper'
describe TodosFinder do
describe '#execute' do
2018-03-27 19:54:05 +05:30
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:finder) { described_class }
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
before do
2018-03-27 19:54:05 +05:30
group.add_developer(user)
2017-09-10 17:25:29 +05:30
end
2016-09-13 17:45:13 +05:30
describe '#sort' do
context 'by date' do
let!(:todo1) { create(:todo, user: user, project: project) }
let!(:todo2) { create(:todo, user: user, project: project) }
let!(:todo3) { create(:todo, user: user, project: project) }
it 'sorts with oldest created first' do
todos = finder.new(user, { sort: 'id_asc' }).execute
expect(todos.first).to eq(todo1)
expect(todos.second).to eq(todo2)
expect(todos.third).to eq(todo3)
end
it 'sorts with newest created first' do
todos = finder.new(user, { sort: 'id_desc' }).execute
expect(todos.first).to eq(todo3)
expect(todos.second).to eq(todo2)
expect(todos.third).to eq(todo1)
end
end
it "sorts by priority" do
2018-03-27 19:54:05 +05:30
project_2 = create(:project)
2016-09-13 17:45:13 +05:30
label_1 = create(:label, title: 'label_1', project: project, priority: 1)
label_2 = create(:label, title: 'label_2', project: project, priority: 2)
label_3 = create(:label, title: 'label_3', project: project, priority: 3)
2018-03-27 19:54:05 +05:30
label_1_2 = create(:label, title: 'label_1', project: project_2, priority: 1)
2016-09-13 17:45:13 +05:30
issue_1 = create(:issue, title: 'issue_1', project: project)
issue_2 = create(:issue, title: 'issue_2', project: project)
issue_3 = create(:issue, title: 'issue_3', project: project)
issue_4 = create(:issue, title: 'issue_4', project: project)
2018-03-27 19:54:05 +05:30
merge_request_1 = create(:merge_request, source_project: project_2)
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
merge_request_1.labels << label_1_2
2016-09-13 17:45:13 +05:30
# Covers the case where Todo has more than one label
issue_3.labels << label_1
issue_3.labels << label_3
issue_2.labels << label_3
issue_1.labels << label_2
todo_1 = create(:todo, user: user, project: project, target: issue_4)
todo_2 = create(:todo, user: user, project: project, target: issue_2)
todo_3 = create(:todo, user: user, project: project, target: issue_3, created_at: 2.hours.ago)
todo_4 = create(:todo, user: user, project: project, target: issue_1)
2018-03-27 19:54:05 +05:30
todo_5 = create(:todo, user: user, project: project_2, target: merge_request_1, created_at: 1.hour.ago)
project_2.add_developer(user)
2016-09-13 17:45:13 +05:30
todos = finder.new(user, { sort: 'priority' }).execute
2018-03-27 19:54:05 +05:30
puts todos.to_sql
expect(todos).to eq([todo_3, todo_5, todo_4, todo_2, todo_1])
2016-09-13 17:45:13 +05:30
end
end
end
end