Commit 700bd970 authored by Jan Provaznik's avatar Jan Provaznik

Support both integer and string as epic count key

Epic state uses enum for saving state (other issuables use
string), because of this inconsistency we override `count_key`
which should return state as string converted to symbol
(.e.g. :closed). In rails 5 these integer states are automatically
converted to strings by Active Record.

But if subquery is used (to optimize searching), Active Record doesn't
convert state into string automatically (probably it can not deal with
the more complex query).

This means that epic state can be either integer (if subquery is used)
or string (if AR converted state to string automatically), so in
`count_key` we should convert state into string only if it's an integer.
parent 62a9d94a
...@@ -55,7 +55,13 @@ class EpicsFinder < IssuableFinder ...@@ -55,7 +55,13 @@ class EpicsFinder < IssuableFinder
private private
def count_key(value) def count_key(value)
Array(value).last.to_sym last_value = Array(value).last
if last_value.is_a?(Integer)
Epic.states.invert[last_value].to_sym
else
last_value.to_sym
end
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -202,5 +202,22 @@ describe EpicsFinder do ...@@ -202,5 +202,22 @@ describe EpicsFinder do
expect(results).to eq('opened' => 2, 'closed' => 1, 'all' => 3) expect(results).to eq('opened' => 2, 'closed' => 1, 'all' => 3)
end end
context 'when using group cte for search' do
before do
stub_feature_flags(use_subquery_for_group_issues_search: false)
end
it 'returns correct counts when search string is used' do
results = described_class.new(
search_user,
group_id: group.id,
search: 'awesome',
attempt_group_search_optimizations: true
).count_by_state
expect(results).to eq('opened' => 1, 'closed' => 1, 'all' => 2)
end
end
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