Skip to content

Commit

Permalink
Merge pull request #2109 from quainjn/blank-object-labels
Browse files Browse the repository at this point in the history
Use default label if object label would be blank
  • Loading branch information
mshibuya committed Nov 14, 2014
2 parents 176f5ba + 4a2a13b commit cabe767
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rails_admin/config/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def excluded?
end

def object_label
bindings[:object].send object_label_method
bindings[:object].send(object_label_method).presence ||
bindings[:object].send(:rails_admin_default_object_label_method)
end

# The display for a model instance (i.e. a single database record).
Expand Down
7 changes: 7 additions & 0 deletions spec/rails_admin/config/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
c = Comment.new(content: 'test')
expect(RailsAdmin.config(Comment).with(object: c).object_label).to eq('test')
end

context 'when the object_label_method is blank' do
it 'uses the rails admin default' do
c = Comment.create(content: '', id: '1')
expect(RailsAdmin.config(Comment).with(object: c).object_label).to eq('Comment #1')
end
end
end

describe '#object_label_method' do
Expand Down

0 comments on commit cabe767

Please sign in to comment.