Add where condition to filter out invalid labels with nil type

This commit is contained in:
Patrick Derichs 2019-07-24 08:53:29 +02:00
parent 245fdf5610
commit 13e7feef08
3 changed files with 19 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class Label < ApplicationRecord
default_scope { order(title: :asc) }
scope :templates, -> { where(template: true) }
scope :templates, -> { where(template: true, type: [Label.name, nil]) }
scope :with_title, ->(title) { where(title: title) }
scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) }
scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) }

View File

@ -0,0 +1,5 @@
---
title: Fix admin labels page when there are invalid records
merge_request: 30885
author:
type: fixed

View File

@ -193,4 +193,17 @@ describe Label do
expect(described_class.optionally_subscribed_by(nil)).to match_array([label, label2])
end
end
describe '#templates' do
context 'with invalid template labels' do
it 'returns only valid template labels' do
create(:label)
# Project labels should not have template set to true
create(:label, template: true)
valid_template_label = described_class.create!(title: 'test', template: true, type: nil)
expect(described_class.templates).to eq([valid_template_label])
end
end
end
end