Skip to content

Commit

Permalink
Support Mongoid's Storage Field Names
Browse files Browse the repository at this point in the history
Closes #1745
  • Loading branch information
mshibuya committed Jan 16, 2022
1 parent 9cd7541 commit cefa23c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rails_admin/adapters/mongoid/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def initialize(property, model)
end

def name
property.name.to_sym
(property.options[:as] || property.name).to_sym
end

def pretty_name
property.name.to_s.tr('_', ' ').capitalize
(property.options[:as] || property.name).to_s.tr('_', ' ').capitalize
end

def type
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/app/mongoid/field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FieldTest
field :open, type: Boolean
field :restricted_field, type: String
field :protected_field, type: String
field :al, as: :aliased_field, type: String
has_mongoid_attached_file :paperclip_asset, styles: {thumb: '100x100>'}

field :shrine_asset_data, type: String
Expand Down
9 changes: 9 additions & 0 deletions spec/rails_admin/adapters/mongoid/property_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@
end
end

describe 'aliased field' do
let(:field) { :aliased_field }

it 'has correct values' do
expect(subject.name).to eq :aliased_field
expect(subject.pretty_name).to eq 'Aliased field'
end
end

describe '#length_validation_lookup' do
it 'detects validation length properly' do
class LengthValiated
Expand Down

0 comments on commit cefa23c

Please sign in to comment.