Commit 7dbf027c authored by Mario de la Ossa's avatar Mario de la Ossa

Boards - extract `Boards::UsersFinder`

parent 89497f61
......@@ -5,10 +5,7 @@ module Boards
# If board parent is a group it enumerates all members of current group,
# ancestors, and descendants
def index
user_ids = finder_service
.execute(include_descendants: true)
.non_invite
.select(:user_id)
user_ids = user_finder.execute.select(:user_id)
users = User.where(id: user_ids)
......@@ -17,13 +14,8 @@ module Boards
private
def finder_service
@service ||=
if board_parent.is_a?(Group)
GroupMembersFinder.new(board_parent)
else
MembersFinder.new(board_parent, current_user)
end
def user_finder
@user_finder ||= Boards::UsersFinder.new(board, current_user)
end
end
end
module Boards
class UsersFinder
def initialize(board, current_user = nil)
@board = board
@current_user = current_user
end
def execute
finder_service.execute(include_descendants: true).non_invite
end
private
def finder_service
@finder_service ||=
if @board.parent.is_a?(Group)
GroupMembersFinder.new(@board.parent)
else
MembersFinder.new(@board.parent, @current_user)
end
end
end
end
......@@ -24,17 +24,12 @@ module EE
end
def find_user(board)
user_ids = user_finder(board).execute(include_descendants: true).non_invite.select(:user_id)
user_ids = user_finder(board).select(:user_id)
::User.where(id: user_ids).find(params[:assignee_id])
end
def user_finder(board)
@service ||=
if board.parent.is_a?(Group)
GroupMembersFinder.new(board.parent)
else
MembersFinder.new(board.parent, current_user)
end
@user_finder ||= Boards::UsersFinder.new(board, current_user)
end
end
end
......
require 'spec_helper'
describe Boards::UsersFinder do
describe '#execute' do
subject { described_class.new(board) }
context 'when parent is a project' do
let(:project) { create(:project) }
let(:board) { create(:board, project: project) }
it 'finds ProjectMembers with MemberFinder' do
results = subject.execute
expect(subject.instance_variable_get(:@finder_service)).to be_kind_of(MembersFinder)
expect(results.first).to be_kind_of(ProjectMember)
end
end
context 'when parent is a group' do
let(:group) { create(:group) }
let(:board) { create(:board, group: group) }
let(:user) { create(:user) }
before do
group.add_developer(user)
end
it 'finds GroupMembers with GroupMemberFinder' do
results = subject.execute
expect(subject.instance_variable_get(:@finder_service)).to be_kind_of(GroupMembersFinder)
expect(results.first).to be_kind_of(GroupMember)
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