summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-09-21 19:02:09 +0200
committerRémy Coutable <remy@rymai.me>2016-09-22 11:21:57 +0200
commitd626b429a7d42609a5e385e0de6d4c09f539e4ff (patch)
treead6d5b8168d85d9f28dde52e016fa6e5000236c3
parent98b3d6ce695a9751f72adc35bc09f82eb2f624a4 (diff)
downloadgitlab-ce-22421-fix-issuable-counter-when-more-than-one-label-is-selected.tar.gz
Hotfix the issuable counters when filtering by multiple labels22421-fix-issuable-counter-when-more-than-one-label-is-selected
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--app/helpers/application_helper.rb15
-rw-r--r--spec/features/issues/filter_by_labels_spec.rb20
2 files changed, 26 insertions, 9 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ed41bf04fc0..2163a437c48 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -286,8 +286,19 @@ module ApplicationHelper
}
state_title = titles[state] || state.to_s.humanize
- count = records.public_send(state).size
- html = content_tag :span, state_title
+ records_with_state = records.public_send(state)
+
+ # When filtering by multiple labels, the result of query.count is a Hash
+ # of the form { issuable_id1 => N, issuable_id2 => N }, where N is the
+ # number of labels selected. The ugly "trick" is to load the issuables
+ # as an array and get the size of the array...
+ # We should probably try to solve this properly in the future.
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/22414
+ label_names = Array(params.fetch(:label_name, []))
+ records_with_state = records_with_state.to_a if label_names.many?
+
+ count = records_with_state.size
+ html = content_tag :span, state_title
if count.present?
html += " "
diff --git a/spec/features/issues/filter_by_labels_spec.rb b/spec/features/issues/filter_by_labels_spec.rb
index 908b18e5339..7e2abd759e1 100644
--- a/spec/features/issues/filter_by_labels_spec.rb
+++ b/spec/features/issues/filter_by_labels_spec.rb
@@ -6,20 +6,19 @@ feature 'Issue filtering by Labels', feature: true do
let(:project) { create(:project, :public) }
let!(:user) { create(:user)}
let!(:label) { create(:label, project: project) }
+ let(:bug) { create(:label, project: project, title: 'bug') }
+ let(:feature) { create(:label, project: project, title: 'feature') }
+ let(:enhancement) { create(:label, project: project, title: 'enhancement') }
+ let(:issue1) { create(:issue, title: "Bugfix1", project: project) }
+ let(:issue2) { create(:issue, title: "Bugfix2", project: project) }
+ let(:issue3) { create(:issue, title: "Feature1", project: project) }
before do
- bug = create(:label, project: project, title: 'bug')
- feature = create(:label, project: project, title: 'feature')
- enhancement = create(:label, project: project, title: 'enhancement')
-
- issue1 = create(:issue, title: "Bugfix1", project: project)
issue1.labels << bug
- issue2 = create(:issue, title: "Bugfix2", project: project)
issue2.labels << bug
issue2.labels << enhancement
- issue3 = create(:issue, title: "Feature1", project: project)
issue3.labels << feature
project.team << [user, :master]
@@ -159,6 +158,13 @@ feature 'Issue filtering by Labels', feature: true do
wait_for_ajax
end
+ it 'shows a correct "Open" counter' do
+ page.within '.issues-state-filters' do
+ expect(page).not_to have_content "{#{issue2.id} => 1}"
+ expect(page).to have_content "Open 1"
+ end
+ end
+
it 'shows issue "Bugfix2" in issues list' do
expect(page).to have_content "Bugfix2"
end