diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
commit | 983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch) | |
tree | b153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/models/concerns/issuable_spec.rb | |
parent | a2bddee2cdb38673df0e004d5b32d9f77797de64 (diff) |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/models/concerns/issuable_spec.rb')
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 34 |
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) } |