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 ...@@ -9,7 +9,7 @@ module EE
end end
def create 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| respond_to do |format|
format.json do format.json do
......
module Boards module Boards
class CreateService < BaseService class CreateService < BaseService
def execute def execute
board = project.boards.create(params) if project.boards.empty?
create_board!
if board.persisted? else
board.lists.create(list_type: :backlog) project.boards.first
board.lists.create(list_type: :closed)
end end
end
private
def create_board!
board = project.boards.create
board.lists.create(list_type: :backlog)
board.lists.create(list_type: :closed)
board board
end 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 ...@@ -4,11 +4,11 @@ describe Boards::CreateService, services: true do
describe '#execute' do describe '#execute' do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
context 'with valid params' do subject(:service) { described_class.new(project, double) }
subject(:service) { described_class.new(project, double, name: 'Backend') }
it 'creates a new project board' do context 'when project does not have a board' do
expect { service.execute }.to change(project.boards, :count).by(1) it 'creates a new board' do
expect { service.execute }.to change(Board, :count).by(1)
end end
it 'creates the default lists' do it 'creates the default lists' do
...@@ -20,32 +20,13 @@ describe Boards::CreateService, services: true do ...@@ -20,32 +20,13 @@ describe Boards::CreateService, services: true do
end end
end end
context 'with invalid params' do context 'when project has a board' do
subject(:service) { described_class.new(project, double, name: nil) } before do
create(:board, project: project)
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
end
context 'without params' do
subject(:service) { described_class.new(project, double) }
it 'creates a new project board' do it 'does not create a new board' do
expect { service.execute }.to change(project.boards, :count).by(1) expect { service.execute }.not_to change(project.boards, :count)
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 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