2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Boards::Lists::CreateService do
|
2016-09-13 17:45:13 +05:30
|
|
|
describe '#execute' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:board) { create(:board, project: project) }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:user) { create(:user) }
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:label) { create(:label, project: project, name: 'in-progress') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
subject(:service) { described_class.new(project, user, label_id: label.id) }
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'creates a new list at beginning of the list' do
|
2016-11-03 12:29:30 +05:30
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(list.position).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when board lists has the done list' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'creates a new list at beginning of the list' do
|
2016-11-03 12:29:30 +05:30
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(list.position).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'when board lists has labels lists' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'creates a new list at end of the lists' do
|
|
|
|
create(:list, board: board, position: 0)
|
|
|
|
create(:list, board: board, position: 1)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(list.position).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when board lists has label and done lists' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'creates a new list at end of the label lists' do
|
|
|
|
list1 = create(:list, board: board, position: 0)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
list2 = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(list1.reload.position).to eq 0
|
|
|
|
expect(list2.reload.position).to eq 1
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
context 'when provided label does not belongs to the project' do
|
|
|
|
it 'raises an error' do
|
|
|
|
label = create(:label, name: 'in-development')
|
|
|
|
service = described_class.new(project, user, label_id: label.id)
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect { service.execute(board) }.to raise_error(ActiveRecord::RecordNotFound)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|