Add where condition to filter out invalid labels with nil type
This commit is contained in:
parent
245fdf5610
commit
13e7feef08
|
@ -33,7 +33,7 @@ class Label < ApplicationRecord
|
||||||
|
|
||||||
default_scope { order(title: :asc) }
|
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_title, ->(title) { where(title: title) }
|
||||||
scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) }
|
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 }) }
|
scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) }
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix admin labels page when there are invalid records
|
||||||
|
merge_request: 30885
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -193,4 +193,17 @@ describe Label do
|
||||||
expect(described_class.optionally_subscribed_by(nil)).to match_array([label, label2])
|
expect(described_class.optionally_subscribed_by(nil)).to match_array([label, label2])
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue