Commit ffdb498c authored by Michael Kozono's avatar Michael Kozono

Merge branch '31914-support-multiple-query-on-todos-finder-action-pd' into 'master'

Add TodosFinder support for filtering by multiple actions

See merge request gitlab-org/gitlab!18490
parents ce9a7342 978e839c
......@@ -65,9 +65,21 @@ class TodosFinder
params[:action_id]
end
def action_array_provided?
params[:action].is_a?(Array)
end
def map_actions_to_ids
params[:action].map { |item| Todo::ACTION_NAMES.key(item.to_sym) }
end
def to_action_id
if action_array_provided?
map_actions_to_ids
else
Todo::ACTION_NAMES.key(action.to_sym)
end
end
def action?
action.present? && to_action_id
......@@ -133,9 +145,19 @@ class TodosFinder
end
end
def action_id_array_provided?
params[:action_id].is_a?(Array) && params[:action_id].any?
end
def by_action_ids(items)
items.for_action(action_id)
end
def by_action_id(items)
return by_action_ids(items) if action_id_array_provided?
if action_id?
items.for_action(action_id)
by_action_ids(items)
else
items
end
......
......@@ -36,6 +36,43 @@ describe TodosFinder do
expect(todos).to match_array([todo1])
end
context 'when filtering for actions' do
let!(:todo1) { create(:todo, user: user, project: project, target: issue, action: Todo::ASSIGNED) }
let!(:todo2) { create(:todo, user: user, group: group, target: merge_request, action: Todo::DIRECTLY_ADDRESSED) }
context 'by action ids' do
it 'returns the expected todos' do
todos = finder.new(user, { action_id: Todo::DIRECTLY_ADDRESSED }).execute
expect(todos).to match_array([todo2])
end
context 'multiple actions' do
it 'returns the expected todos' do
todos = finder.new(user, { action_id: [Todo::DIRECTLY_ADDRESSED, Todo::ASSIGNED] }).execute
expect(todos).to match_array([todo2, todo1])
end
end
end
context 'by action names' do
it 'returns the expected todos' do
todos = finder.new(user, { action: :directly_addressed }).execute
expect(todos).to match_array([todo2])
end
context 'multiple actions' do
it 'returns the expected todos' do
todos = finder.new(user, { action: [:directly_addressed, :assigned] }).execute
expect(todos).to match_array([todo2, todo1])
end
end
end
end
context 'with subgroups' do
let(:subgroup) { create(:group, parent: group) }
let!(:todo3) { create(:todo, user: user, group: subgroup, target: issue) }
......
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