Commit baed3cc4 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'jej/fix-csv-export-filter-by-multiple-labels' into 'master'

Fix Issuable#labels_hash when filtered by multiple labels for CSV export

Closes gitlab-ce#34217

See merge request !2852
parents 069eee02 4d334f76
...@@ -205,9 +205,12 @@ module Issuable ...@@ -205,9 +205,12 @@ module Issuable
def labels_hash def labels_hash
issue_labels = Hash.new { |h, k| h[k] = [] } issue_labels = Hash.new { |h, k| h[k] = [] }
eager_load(:labels).pluck(:id, 'labels.title').each do |issue_id, label|
relation = unscoped.where(id: self.select(:id)).eager_load(:labels)
relation.pluck(:id, 'labels.title').each do |issue_id, label|
issue_labels[issue_id] << label issue_labels[issue_id] << label
end end
issue_labels issue_labels
end end
......
---
title: Fix CSV export when filtering issues by multiple labels
merge_request: 2852
author:
type: fixed
...@@ -328,11 +328,18 @@ describe Issuable do ...@@ -328,11 +328,18 @@ describe Issuable do
describe '.labels_hash' do describe '.labels_hash' do
let(:feature_label) { create(:label, title: 'Feature') } let(:feature_label) { create(:label, title: 'Feature') }
let!(:issues) { create_list(:labeled_issue, 3, labels: [feature_label]) } let(:second_label) { create(:label, title: 'Second Label') }
let!(:issues) { create_list(:labeled_issue, 3, labels: [feature_label, second_label]) }
let(:issue_id) { issues.first.id }
it 'maps issue ids to labels titles' do it 'maps issue ids to labels titles' do
issue_id = issues.first.id expect(Issue.labels_hash[issue_id]).to include('Feature')
expect(Issue.labels_hash[issue_id]).to eq ['Feature'] end
it 'works on relations filtered by multiple labels' do
relation = Issue.with_label(['Feature', 'Second Label'])
expect(relation.labels_hash[issue_id]).to include('Feature', 'Second Label')
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