2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Boards::Lists::CreateService do
|
2016-09-13 17:45:13 +05:30
|
|
|
describe '#execute' do
|
2018-03-27 19:54:05 +05:30
|
|
|
shared_examples 'creating board lists' do
|
|
|
|
let(:user) { create(:user) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
subject(:service) { described_class.new(parent, user, label_id: label.id) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
before do
|
|
|
|
parent.add_developer(user)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists is empty' do
|
|
|
|
it 'creates a new list at beginning of the list' do
|
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(list.position).to eq 0
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has the done list' do
|
|
|
|
it 'creates a new list at beginning of the list' do
|
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(list.position).to eq 0
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has labels lists' do
|
|
|
|
it 'creates a new list at end of the lists' do
|
|
|
|
create(:list, board: board, position: 0)
|
|
|
|
create(:list, board: board, position: 1)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
list = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(list.position).to eq 2
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when board lists has label and done lists' do
|
|
|
|
it 'creates a new list at end of the label lists' do
|
|
|
|
list1 = create(:list, board: board, position: 0)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
list2 = service.execute(board)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(list1.reload.position).to eq 0
|
|
|
|
expect(list2.reload.position).to eq 1
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when provided label does not belongs to the parent' do
|
|
|
|
it 'raises an error' do
|
|
|
|
label = create(:label, name: 'in-development')
|
|
|
|
service = described_class.new(parent, user, label_id: label.id)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect { service.execute(board) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
context 'when backlog param is sent' do
|
|
|
|
it 'creates one and only one backlog list' do
|
|
|
|
service = described_class.new(parent, user, 'backlog' => true)
|
|
|
|
list = service.execute(board)
|
|
|
|
|
|
|
|
expect(list.list_type).to eq('backlog')
|
|
|
|
expect(list.position).to be_nil
|
|
|
|
expect(list).to be_valid
|
|
|
|
|
|
|
|
another_backlog = service.execute(board)
|
|
|
|
|
|
|
|
expect(another_backlog).to eq list
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
context 'when board parent is a project' do
|
|
|
|
let(:parent) { create(:project) }
|
|
|
|
let(:board) { create(:board, project: parent) }
|
|
|
|
let(:label) { create(:label, project: parent, name: 'in-progress') }
|
|
|
|
|
|
|
|
it_behaves_like 'creating board lists'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when board parent is a group' do
|
|
|
|
let(:parent) { create(:group) }
|
|
|
|
let(:board) { create(:board, group: parent) }
|
|
|
|
let(:label) { create(:group_label, group: parent, name: 'in-progress') }
|
|
|
|
|
|
|
|
it_behaves_like 'creating board lists'
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|