Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/fields/enum/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ By default, the input is a select field for the enum attributes.
end,
f.object.public_send(field.attribute.to_s)
),
{ include_blank: !f.object.class.validators_on(field.attribute.to_s).map(&:class).include?(ActiveRecord::Validations::PresenceValidator) },
{ include_blank: field.include_blank_option || !f.object.class.validators_on(field.attribute.to_s).map(&:class).include?(ActiveRecord::Validations::PresenceValidator) },
field.html_options) %>
</div>
4 changes: 4 additions & 0 deletions lib/administrate/field/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def html_options
options[:html] || {}
end

def include_blank_option
options.fetch(:include_blank, false)
end

class Engine < ::Rails::Engine
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/administrate/field/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
end
end

describe '.include_blank' do
it 'is false by default' do
page = :show

field = Administrate::Field::Enum.new(:status, 'status', page)

expect(field.include_blank_option).to be_falsy
end

it 'can override include_blank_option' do
page = :show

field = Administrate::Field::Enum.with_options(include_blank: true).new(:status, 'status', page)

expect(field.include_blank_option).to be_truthy
end
end

describe '#html_options' do
it 'returns a hash of :html options' do
page = :show
Expand Down