summaryrefslogtreecommitdiff
path: root/spec/models/concerns/issuable_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/concerns/issuable_spec.rb')
-rw-r--r--spec/models/concerns/issuable_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index cc1bb164c16..24908785320 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -496,6 +496,40 @@ describe Issuable do
end
end
+ describe '.labels_hash' do
+ let(:feature_label) { create(:label, title: 'Feature') }
+ 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
+ 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
+
+ # This tests the workaround for the lack of a NOT NULL constraint in
+ # label_links.label_id:
+ # https://gitlab.com/gitlab-org/gitlab/issues/197307
+ context 'with a NULL label ID in the link' do
+ let(:issue) { create(:labeled_issue, labels: [feature_label, second_label]) }
+
+ before do
+ label_link = issue.label_links.find_by(label_id: second_label.id)
+ label_link.label_id = nil
+ label_link.save(validate: false)
+ end
+
+ it 'filters out bad labels' do
+ expect(Issue.where(id: issue.id).labels_hash[issue.id]).to match_array(['Feature'])
+ end
+ end
+ end
+
describe '#user_notes_count' do
let(:project) { create(:project) }
let(:issue1) { create(:issue, project: project) }