Commit c478202e authored by Bob Van Landuyt's avatar Bob Van Landuyt

This makes the `Boards::CreateService` more reusable for EE

parent de2d5ce6
module Boards module Boards
class CreateService < BaseService class CreateService < BaseService
def execute def execute
if project.boards.empty? create_board! if can_create_board?
create_board!
else
project.boards.first
end
end end
private private
def can_create_board?
project.boards.size == 0
end
def create_board! def create_board!
board = project.boards.create board = project.boards.create(params)
if board.persisted?
board.lists.create(list_type: :backlog) board.lists.create(list_type: :backlog)
board.lists.create(list_type: :closed) board.lists.create(list_type: :closed)
end
board board
end end
......
...@@ -26,6 +26,8 @@ describe Boards::CreateService, services: true do ...@@ -26,6 +26,8 @@ describe Boards::CreateService, services: true do
end end
it 'does not create a new board' do it 'does not create a new board' do
expect(service).to receive(:can_create_board?) { false }
expect { service.execute }.not_to change(project.boards, :count) expect { service.execute }.not_to change(project.boards, :count)
end 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