BigW Consortium Gitlab

Add Boards::ListService service to list project boards

parent 8b15e328
module Boards
class ListService < Boards::BaseService
def execute
create_board! if project.boards.empty?
project.boards
end
private
def create_board!
Boards::CreateService.new(project, current_user).execute
end
end
end
require 'spec_helper'
describe Boards::ListService, services: true do
describe '#execute' do
let(:project) { create(:empty_project) }
subject(:service) { described_class.new(project, double) }
context 'when project does not have a board' do
it 'creates a new project board' do
expect { service.execute }.to change(project.boards, :count).by(1)
end
it 'delegates the project board creation to Boards::CreateService' do
expect_any_instance_of(Boards::CreateService).to receive(:execute).once
service.execute
end
end
context 'when project has a board' do
before do
create(:board, project: project)
end
it 'does not create a new board' do
expect { service.execute }.not_to change(project.boards, :count)
end
end
it 'returns project boards' do
board = create(:board, project: project)
expect(service.execute).to match_array [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