Allow user to create a board list based on a group label

This commit is contained in:
Douglas Barbosa Alexandre 2016-09-19 17:34:27 -03:00
parent 398ab263fd
commit bf9d928b45
4 changed files with 17 additions and 2 deletions

View file

@ -25,7 +25,10 @@ class Projects::IssuesController < Projects::ApplicationController
def index
@issues = issues_collection
@issues = @issues.page(params[:page])
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute if params[:label_name].presence
if params[:label_name].presence
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute
end
respond_to do |format|
format.html

View file

@ -3,7 +3,7 @@ module Boards
class CreateService < BaseService
def execute(board)
List.transaction do
label = project.labels.find(params[:label_id])
label = available_labels.find(params[:label_id])
position = next_position(board)
create_list(board, label, position)
@ -12,6 +12,10 @@ module Boards
private
def available_labels
LabelsFinder.new(current_user, project_id: project.id).execute
end
def next_position(board)
max_position = board.lists.movable.maximum(:position)
max_position.nil? ? 0 : max_position.succ

View file

@ -9,6 +9,10 @@ describe Boards::Lists::CreateService, services: true do
subject(:service) { described_class.new(project, user, label_id: label.id) }
before do
project.team << [user, :developer]
end
context 'when board lists is empty' do
it 'creates a new list at beginning of the list' do
list = service.execute(board)

View file

@ -8,6 +8,10 @@ describe Boards::Lists::GenerateService, services: true do
subject(:service) { described_class.new(project, user) }
before do
project.team << [user, :developer]
end
context 'when board lists is empty' do
it 'creates the default lists' do
expect { service.execute(board) }.to change(board.lists, :count).by(2)