Commit 4d334f76 authored by James Edwards-Jones's avatar James Edwards-Jones

Issuable#labels_hash works with with_label([]) to fix CSV export

parent f60f6872
......@@ -205,9 +205,12 @@ module Issuable
def labels_hash
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
end
issue_labels
end
......
---
title: Fix CSV export when filtering issues by multiple labels
merge_request: 2852
author:
type: fixed
......@@ -328,11 +328,18 @@ describe Issuable do
describe '.labels_hash' do
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
issue_id = issues.first.id
expect(Issue.labels_hash[issue_id]).to eq ['Feature']
expect(Issue.labels_hash[issue_id]).to include('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
......
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