Add service to create a new board for a project

parent 6e8d06a5
module Boards
class CreateService
def initialize(project)
@project = project
end
def execute
if project.board.present?
project.board
else
project.create_board
end
end
private
attr_reader :project
end
end
......@@ -83,4 +83,10 @@ FactoryGirl.define do
)
end
end
factory :project_with_board, parent: :empty_project do
after(:create) do |project|
project.create_board
end
end
end
require 'spec_helper'
describe Boards::CreateService, services: true do
describe '#execute' do
it 'creates a new board when project does not has one' do
project = create(:empty_project, board: nil)
service = described_class.new(project)
expect { service.execute }.to change(Board, :count).by(1)
end
it 'returns project board when project has one' do
project = create(:project_with_board)
service = described_class.new(project)
expect(service.execute).to eq project.board
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