diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-16 14:38:43 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 12:58:59 -0300 |
commit | 50ac488c739718902ba897bc5ad8791d35914324 (patch) | |
tree | cc3e5cb1b9da7401a5068c510f06e36cdee51f13 | |
parent | c6511235e4253d11447b40c2ea42ecb02c99687e (diff) | |
download | gitlab-ce-50ac488c739718902ba897bc5ad8791d35914324.tar.gz |
Add a movable scope and a movable? method to List model
-rw-r--r-- | app/controllers/projects/boards/lists_controller.rb | 4 | ||||
-rw-r--r-- | app/models/list.rb | 5 | ||||
-rw-r--r-- | app/services/boards/issues/list_service.rb | 6 | ||||
-rw-r--r-- | app/services/boards/issues/move_service.rb | 4 | ||||
-rw-r--r-- | app/services/boards/lists/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/lists/destroy_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/lists/generate_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/lists/move_service.rb | 16 | ||||
-rw-r--r-- | spec/models/list_spec.rb | 20 |
9 files changed, 43 insertions, 18 deletions
diff --git a/app/controllers/projects/boards/lists_controller.rb b/app/controllers/projects/boards/lists_controller.rb index 6555ae6ae37..b995f586737 100644 --- a/app/controllers/projects/boards/lists_controller.rb +++ b/app/controllers/projects/boards/lists_controller.rb @@ -19,7 +19,7 @@ module Projects end def update - list = project.board.lists.find(params[:id]) + list = project.board.lists.movable.find(params[:id]) service = ::Boards::Lists::MoveService.new(project, current_user, move_params) if service.execute(list) @@ -44,7 +44,7 @@ module Projects service = ::Boards::Lists::GenerateService.new(project, current_user) if service.execute - render json: serialize_as_json(project.board.lists.label) + render json: serialize_as_json(project.board.lists.movable) else head :unprocessable_entity end diff --git a/app/models/list.rb b/app/models/list.rb index 634c012e543..eb87decdbc8 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -12,11 +12,16 @@ class List < ActiveRecord::Base before_destroy :can_be_destroyed scope :destroyable, -> { where(list_type: list_types[:label]) } + scope :movable, -> { where(list_type: list_types[:label]) } def destroyable? label? end + def movable? + label? + end + def title label? ? label.name : list_type.humanize end diff --git a/app/services/boards/issues/list_service.rb b/app/services/boards/issues/list_service.rb index 060982f01f0..c2130273c0c 100644 --- a/app/services/boards/issues/list_service.rb +++ b/app/services/boards/issues/list_service.rb @@ -3,8 +3,8 @@ module Boards class ListService < Boards::BaseService def execute issues = IssuesFinder.new(user, filter_params).execute - issues = without_board_labels(issues) unless list.label? - issues = with_list_label(issues) if list.label? + issues = without_board_labels(issues) unless list.movable? + issues = with_list_label(issues) if list.movable? issues end @@ -40,7 +40,7 @@ module Boards end def board_label_ids - @board_label_ids ||= board.lists.label.pluck(:label_id) + @board_label_ids ||= board.lists.movable.pluck(:label_id) end def without_board_labels(issues) diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb index 6c6f60e1496..71f463bad30 100644 --- a/app/services/boards/issues/move_service.rb +++ b/app/services/boards/issues/move_service.rb @@ -45,10 +45,10 @@ module Boards def remove_label_ids label_ids = - if moving_to_list.label? + if moving_to_list.movable? moving_from_list.label_id else - board.lists.label.pluck(:label_id) + board.lists.movable.pluck(:label_id) end Array(label_ids).compact diff --git a/app/services/boards/lists/create_service.rb b/app/services/boards/lists/create_service.rb index 704e0254217..5cb408b9d20 100644 --- a/app/services/boards/lists/create_service.rb +++ b/app/services/boards/lists/create_service.rb @@ -10,7 +10,7 @@ module Boards private def next_position - max_position = board.lists.label.maximum(:position) + max_position = board.lists.movable.maximum(:position) max_position.nil? ? 0 : max_position.succ end diff --git a/app/services/boards/lists/destroy_service.rb b/app/services/boards/lists/destroy_service.rb index 5c8719f193a..25da3bfb56d 100644 --- a/app/services/boards/lists/destroy_service.rb +++ b/app/services/boards/lists/destroy_service.rb @@ -13,7 +13,7 @@ module Boards private def decrement_higher_lists(list) - board.lists.label.where('position > ?', list.position) + board.lists.movable.where('position > ?', list.position) .update_all('position = position - 1') end diff --git a/app/services/boards/lists/generate_service.rb b/app/services/boards/lists/generate_service.rb index 9107b1fb9e7..86f0aa99c61 100644 --- a/app/services/boards/lists/generate_service.rb +++ b/app/services/boards/lists/generate_service.rb @@ -2,7 +2,7 @@ module Boards module Lists class GenerateService < Boards::BaseService def execute - return false unless board.lists.label.empty? + return false unless board.lists.movable.empty? List.transaction do label_params.each { |params| create_list(params) } diff --git a/app/services/boards/lists/move_service.rb b/app/services/boards/lists/move_service.rb index 2b2b5c3943a..020ff69f4a7 100644 --- a/app/services/boards/lists/move_service.rb +++ b/app/services/boards/lists/move_service.rb @@ -5,7 +5,7 @@ module Boards @old_position = list.position @new_position = params[:position] - return false unless list.label? + return false unless list.movable? return false unless valid_move? list.with_lock do @@ -20,7 +20,7 @@ module Boards def valid_move? new_position.present? && new_position != old_position && - new_position >= 0 && new_position < board.lists.label.size + new_position >= 0 && new_position < board.lists.movable.size end def reorder_intermediate_lists @@ -32,15 +32,15 @@ module Boards end def decrement_intermediate_lists - board.lists.label.where('position > ?', old_position) - .where('position <= ?', new_position) - .update_all('position = position - 1') + board.lists.movable.where('position > ?', old_position) + .where('position <= ?', new_position) + .update_all('position = position - 1') end def increment_intermediate_lists - board.lists.label.where('position >= ?', new_position) - .where('position < ?', old_position) - .update_all('position = position + 1') + board.lists.movable.where('position >= ?', new_position) + .where('position < ?', old_position) + .update_all('position = position + 1') end def update_list_position(list) diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb index d5c60f65043..9e1a52011c3 100644 --- a/spec/models/list_spec.rb +++ b/spec/models/list_spec.rb @@ -74,6 +74,26 @@ describe List do end end + describe '#movable?' do + it 'retruns true when list_type is set to label' do + subject.list_type = :label + + expect(subject).to be_movable + end + + it 'retruns false when list_type is set to backlog' do + subject.list_type = :backlog + + expect(subject).not_to be_movable + end + + it 'retruns false when list_type is set to done' do + subject.list_type = :done + + expect(subject).not_to be_movable + end + end + describe '#title' do it 'returns label name when list_type is set to label' do subject.list_type = :label |