Add service to create a board list

parent a77aee93
module Boards
module Lists
class CreateService
def initialize(project, params = {})
@board = project.board
@params = params.dup
end
def execute
board.lists.create(params.merge(position: position))
end
private
attr_reader :board, :params
def position
board.lists.size
end
end
end
end
FactoryGirl.define do
factory :board do
project factory: :empty_project
end
end
FactoryGirl.define do
factory :list do
board
label
sequence(:position)
end
end
require 'spec_helper'
describe Boards::Lists::CreateService, services: true do
describe '#execute' do
let(:project) { create(:project_with_board) }
let(:board) { project.board }
let(:label) { create(:label, name: 'in-progress') }
it 'creates a new list for board' do
service = described_class.new(project, label_id: label.id)
expect { service.execute }.to change(board.lists, :count).by(1)
end
it 'inserts the list to the end of lists' do
create_list(:list, 2, board: board)
service = described_class.new(project, label_id: label.id)
list = service.execute
expect(list.position).to eq 2
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment