Skip to content

Commit

Permalink
Change compact_show_view to show boolean false
Browse files Browse the repository at this point in the history
Boolean false denotes something turned off, not absense of value. Closes #2416
  • Loading branch information
mshibuya committed May 28, 2019
1 parent 20c8602 commit 18d072c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/views/rails_admin/main/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
- @model_config.show.with(object: @object, view: self, controller: self.controller).visible_groups.each do |fieldset|
- unless (fields = fieldset.with(object: @object, view: self, controller: self.controller).visible_fields).empty?
- if !(values = fields.map{ |f| f.formatted_value.presence }).compact.empty? || !RailsAdmin::config.compact_show_view
- unless (fields = fields.reject{ |f| RailsAdmin::config.compact_show_view && f.formatted_value.nil? || f.formatted_value == '' }).empty?
.fieldset
%h4
= fieldset.label
- if fieldset.help
%p= fieldset.help
%dl
- fields.each_with_index do |field, index|
- unless values[index].nil? && RailsAdmin::config.compact_show_view
%dt
%span.label.label-info{class: "#{field.type_css_class} #{field.css_class}"}
= field.label
%dd.well
= field.pretty_value
%dt
%span.label.label-info{class: "#{field.type_css_class} #{field.css_class}"}
= field.label
%dd.well
= field.pretty_value
17 changes: 16 additions & 1 deletion spec/integration/config/show/rails_admin_config_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ def do_request
end

describe 'compact_show_view' do
it 'hides empty fields in show view by default' do
it 'hides nil fields in show view by default' do
do_request
is_expected.not_to have_css('.logo_url_field')
end

it 'hides blank fields in show view by default' do
team.update logo_url: ''
do_request
is_expected.not_to have_css('.logo_url_field')
end
Expand All @@ -40,6 +46,15 @@ def do_request
do_request
is_expected.to have_css('.logo_url_field')
end

describe 'with boolean field' do
let(:player) { FactoryBot.create :player, retired: false }

it 'does not hide false value' do
visit show_path(model_name: 'player', id: player.id)
is_expected.to have_css('.retired_field')
end
end
end

describe 'bindings' do
Expand Down

0 comments on commit 18d072c

Please sign in to comment.