Commit 13e7feef authored by Patrick Derichs's avatar Patrick Derichs

Add where condition to filter out invalid labels with nil type

parent 245fdf56
...@@ -33,7 +33,7 @@ class Label < ApplicationRecord ...@@ -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 }) }
......
---
title: Fix admin labels page when there are invalid records
merge_request: 30885
author:
type: fixed
...@@ -193,4 +193,17 @@ describe Label do ...@@ -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
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