Update Boards::Lists::GenerateService to generate for a specific board

parent 91107463
module Boards
module Lists
class GenerateService < Boards::BaseService
def execute
def execute(board)
return false unless board.lists.movable.empty?
List.transaction do
label_params.each { |params| create_list(params) }
label_params.each { |params| create_list(board, params) }
end
true
......@@ -13,9 +13,9 @@ module Boards
private
def create_list(params)
def create_list(board, params)
label = find_or_create_label(params)
Lists::CreateService.new(project, current_user, label_id: label.id).execute
Lists::CreateService.new(project, current_user, label_id: label.id).execute(board)
end
def find_or_create_label(params)
......
......@@ -2,15 +2,15 @@ require 'spec_helper'
describe Boards::Lists::GenerateService, services: true do
describe '#execute' do
let(:project) { create(:project_with_board) }
let(:board) { project.board }
let(:project) { create(:empty_project) }
let(:board) { create(:board, project: project) }
let(:user) { create(:user) }
subject(:service) { described_class.new(project, user) }
context 'when board lists is empty' do
it 'creates the default lists' do
expect { service.execute }.to change(board.lists, :count).by(2)
expect { service.execute(board) }.to change(board.lists, :count).by(2)
end
end
......@@ -18,13 +18,13 @@ describe Boards::Lists::GenerateService, services: true do
it 'does not creates the default lists' do
create(:list, board: board)
expect { service.execute }.not_to change(board.lists, :count)
expect { service.execute(board) }.not_to change(board.lists, :count)
end
end
context 'when project labels does not contains any list label' do
it 'creates labels' do
expect { service.execute }.to change(project.labels, :count).by(2)
expect { service.execute(board) }.to change(project.labels, :count).by(2)
end
end
......@@ -32,7 +32,7 @@ describe Boards::Lists::GenerateService, services: true do
it 'creates the missing labels' do
create(:label, project: project, name: 'Doing')
expect { service.execute }.to change(project.labels, :count).by(1)
expect { service.execute(board) }.to change(project.labels, :count).by(1)
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