Does not remove board from project when project have only one board

parent ff04bc3f
module Boards
class DestroyService < Boards::BaseService
def execute(board)
return false if project.boards.size == 1
board.destroy
end
end
......
......@@ -239,7 +239,8 @@ describe Projects::BoardsController do
end
describe 'DELETE destroy' do
let!(:board) { create(:board, project: project) }
let!(:boards) { create_pair(:board, project: project) }
let(:board) { project.boards.first }
context 'with valid board id' do
it 'redirects to the issue boards page' do
......
......@@ -2,13 +2,23 @@ require 'spec_helper'
describe Boards::DestroyService, services: true do
describe '#execute' do
it 'removes board from project' do
project = create(:empty_project)
board = create(:board, project: project)
let(:project) { create(:empty_project) }
let!(:board) { create(:board, project: project) }
service = described_class.new(project, double)
subject(:service) { described_class.new(project, double) }
expect { service.execute(board) }.to change(project.boards, :count).by(-1)
context 'when project have more than one board' do
it 'removes board from project' do
create(:board, project: project)
expect { service.execute(board) }.to change(project.boards, :count).by(-1)
end
end
context 'when project have one board' do
it 'does not remove board from project' do
expect { service.execute(board) }.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