Skip to content

Commit

Permalink
Overwrite Label#to_s to ease debugging
Browse files Browse the repository at this point in the history
Since a label is considered "unique" based on its name, overwriting `to_s` makes sense to aid debugging.
  • Loading branch information
MrSerth committed Oct 7, 2024
1 parent 99a2e8d commit 815c20a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def to_h
}.compact
end

def to_s
name
end

def self.ransackable_attributes(_auth_object = nil)
%w[name]
end
Expand Down
9 changes: 9 additions & 0 deletions spec/models/label_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 815c20a

Please sign in to comment.