bh icon indicating copy to clipboard operation
bh copied to clipboard

@options.fetch(:errors, {}) can be nil

Open codeodor opened this issue 8 years ago • 2 comments

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.

codeodor avatar Apr 28 '16 15:04 codeodor

Coverage Status

Coverage remained the same at 100.0% when pulling f0a16f20051c6c5ac6a1942a280cc4c15d671096 on codeodor:codeodor-nil-errors into 88a6398cf62081eea25a36f22ad79801780da4e3 on Fullscreen:master.

coveralls avatar Apr 28 '16 15:04 coveralls

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

Manifold0 avatar Nov 15 '16 21:11 Manifold0