Commit 89c7abde authored by Patrick Derichs's avatar Patrick Derichs

Support query for multiple states

Supporting multiple states query on todo. Also updating specs.

Simplify method as suggested by @reprazent

Remove method for_states

Revert "Simplify method as suggested by @reprazent"

This reverts commit 011f44d1c1e51120dbc5fefbb70f68116439e6aa.
parent c67264d8
...@@ -188,11 +188,9 @@ class TodosFinder ...@@ -188,11 +188,9 @@ class TodosFinder
end end
def by_state(items) def by_state(items)
if params[:state].to_s == 'done' return items.pending if params[:state].blank?
items.done
else items.with_states(params[:state])
items.pending
end
end end
def by_type(items) def by_type(items)
......
...@@ -140,6 +140,29 @@ describe TodosFinder do ...@@ -140,6 +140,29 @@ describe TodosFinder do
end end
end end
end end
context 'by state' do
let!(:todo1) { create(:todo, user: user, group: group, target: issue, state: :done) }
let!(:todo2) { create(:todo, user: user, group: group, target: issue, state: :pending) }
it 'returns the expected items when no state is provided' do
todos = finder.new(user, {}).execute
expect(todos).to match_array([todo2])
end
it 'returns the expected items when a state is provided' do
todos = finder.new(user, { state: :done }).execute
expect(todos).to match_array([todo1])
end
it 'returns the expected items when multiple states are provided' do
todos = finder.new(user, { state: [:pending, :done] }).execute
expect(todos).to match_array([todo1, todo2])
end
end
end end
context 'external authorization' do context 'external authorization' do
......
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