bh
bh copied to clipboard
@options.fetch(:errors, {}) can be nil
If the key :errors
exists in @options
then the previous code will return nil
if errors was nil.
Changing it like this ensures we have a hash if errors did not exist or if it was nil.
Coverage remained the same at 100.0% when pulling f0a16f20051c6c5ac6a1942a280cc4c15d671096 on codeodor:codeodor-nil-errors into 88a6398cf62081eea25a36f22ad79801780da4e3 on Fullscreen:master.
This happens again further down in the :show_error_help? method
def show_error_icon?(field_type, errors, suffix = nil)
no_icon = %w(checkbox number_field radio_button select legend)
hide = no_icon.include?(field_type.to_s)
# errors.any? && @options.fetch(:errors, {}).fetch(:icons, true) && !hide && suffix.nil?
errors.any? && (@options.fetch(:errors, {}) || {}).fetch(:icons, true) && !hide && suffix.nil?
end
def show_error_help?
# @options.fetch(:errors, {}).fetch(:messages, :inline).to_s == 'inline'
(@options.fetch(:errors, {}) || {}).fetch(:messages, :inline).to_s == 'inline'
end