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

Validate feature availability in the Boards::CreateService

parent ef3eb79a
......@@ -9,7 +9,7 @@ module EE
end
def create
board = ::Boards::CreateService.new(project, current_user, board_params).execute
board = EE::Boards::CreateService.new(project, current_user, board_params).execute
respond_to do |format|
format.json do
......
module Boards
class CreateService < BaseService
def execute
board = project.boards.create(params)
if board.persisted?
board.lists.create(list_type: :backlog)
board.lists.create(list_type: :closed)
if project.boards.empty?
create_board!
else
project.boards.first
end
end
private
def create_board!
board = project.boards.create
board.lists.create(list_type: :backlog)
board.lists.create(list_type: :closed)
board
end
......
module EE
module Boards
class CreateService < BaseService
def execute
return nil unless can_create_board?
board = project.boards.create(params)
if board.persisted?
board.lists.create(list_type: :backlog)
board.lists.create(list_type: :closed)
end
board
end
def can_create_board?
project.feature_available?(:multiple_issue_boards) || project.boards.size < 1
end
end
end
end
......@@ -4,11 +4,11 @@ describe Boards::CreateService, services: true do
describe '#execute' do
let(:project) { create(:empty_project) }
context 'with valid params' do
subject(:service) { described_class.new(project, double, name: 'Backend') }
subject(:service) { described_class.new(project, double) }
it 'creates a new project board' do
expect { service.execute }.to change(project.boards, :count).by(1)
context 'when project does not have a board' do
it 'creates a new board' do
expect { service.execute }.to change(Board, :count).by(1)
end
it 'creates the default lists' do
......@@ -20,32 +20,13 @@ describe Boards::CreateService, services: true do
end
end
context 'with invalid params' do
subject(:service) { described_class.new(project, double, name: nil) }
it 'does not create a new project board' do
expect { service.execute }.not_to change(project.boards, :count)
end
it "does not create board's default lists" do
board = service.execute
expect(board.lists.size).to eq 0
context 'when project has a board' do
before do
create(:board, project: project)
end
end
context 'without params' do
subject(:service) { described_class.new(project, double) }
it 'creates a new project board' do
expect { service.execute }.to change(project.boards, :count).by(1)
end
it "creates board's default lists" do
board = service.execute
expect(board.lists.size).to eq 2
expect(board.lists.last).to be_closed
it 'does not create a new board' do
expect { service.execute }.not_to change(project.boards, :count)
end
end
end
......
require 'spec_helper'
describe EE::Boards::CreateService, services: true do
describe '#execute' do
let(:project) { create(:empty_project) }
context 'With the feature available' do
before do
stub_licensed_features(multiple_issue_boards: true)
end
context 'with valid params' do
subject(:service) { described_class.new(project, double, name: 'Backend') }
it 'creates a new project board' do
expect { service.execute }.to change(project.boards, :count).by(1)
end
it 'creates the default lists' do
board = service.execute
expect(board.lists.size).to eq 2
expect(board.lists.first).to be_backlog
expect(board.lists.last).to be_closed
end
end
context 'with invalid params' do
subject(:service) { described_class.new(project, double, name: nil) }
it 'does not create a new project board' do
expect { service.execute }.not_to change(project.boards, :count)
end
it "does not create board's default lists" do
board = service.execute
expect(board.lists.size).to eq 0
end
end
context 'without params' do
subject(:service) { described_class.new(project, double) }
it 'creates a new project board' do
expect { service.execute }.to change(project.boards, :count).by(1)
end
it "creates board's default lists" do
board = service.execute
expect(board.lists.size).to eq 2
expect(board.lists.last).to be_closed
end
end
end
it 'skips creating a second board when the feature is not available' do
stub_licensed_features(multiple_issue_boards: false)
service = described_class.new(project, double)
expect(service.execute).not_to be_nil
expect { service.execute }.not_to change(project.boards, :count)
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