diff --git a/app/models/label.rb b/app/models/label.rb index 180afecef..7e693c2b9 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -72,6 +72,10 @@ def to_h }.compact end + def to_s + name + end + def self.ransackable_attributes(_auth_object = nil) %w[name] end diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 8b2166cae..fb120ddbd 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -6,4 +6,13 @@ describe 'validations' do it { is_expected.to validate_presence_of(:name) } end + + describe '#to_s' do + let(:label_name) { 'Test Label' } + let(:label) { described_class.new(name: label_name) } + + it 'returns the label name' do + expect(label.to_s).to eq label_name + end + end end