Skip to content

Commit

Permalink
Fix rails 6.1 errors is now array warnings
Browse files Browse the repository at this point in the history
Fixes this warning in several places in the test suite:
```
  In Rails 6.1, `errors` is an array of Error objects,
  therefore it should be accessed by a block with a single block
  parameter like this:

  person.errors.each do |error|
    attribute = error.attribute
    message = error.message
  end

  You are passing a block expecting two parameters,
  so the old hash behavior is simulated. As this is deprecated,
  this will result in an ArgumentError in Rails 7.0.
```
  • Loading branch information
jrafanie committed Aug 11, 2022
1 parent f146171 commit b80f0c1
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions app/controllers/application_controller/advanced_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def adv_search_button_saveid
@edit[@expkey][:exp_token] = nil
true
else
s.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
s.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
false
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ def ab_button_add
ab_get_node_info(x_node) if x_active_tree == :ab_tree
replace_right_cell(:nodetype => x_node, :replace_trees => x_active_tree == :ab_tree ? [:ab] : [:sandt])
else
@custom_button.errors.each do |field, msg|
@custom_button.errors.each do |error|
add_flash(_("Error during 'add': %{error_message}") %
{:error_message => @custom_button.errors.full_message(field, msg)}, :error)
{:error_message => @custom_button.errors.full_message(error.attribute, error.message)}, :error)
end
@lastaction = "automate_button"
@layout = "miq_ae_automate_button"
Expand Down Expand Up @@ -508,9 +508,9 @@ def ab_button_save
build_filter_exp_table
replace_right_cell(:nodetype => x_node, :replace_trees => x_active_tree == :ab_tree ? [:ab] : [:sandt])
else
@custom_button.errors.each do |field, msg|
@custom_button.errors.each do |error|
add_flash(_("Error during 'edit': %{field_name} %{error_message}") %
{:field_name => field.to_s.capitalize, :error_message => msg}, :error)
{:field_name => error.attribute.to_s.capitalize, :error_message => error.message}, :error)
end
@breadcrumbs = []
drop_breadcrumb(:name => "Edit of Button", :url => "/miq_ae_customization/button_edit")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def process_element_destroy(element, klass, name)
AuditEvent.success(audit)
add_flash(_("%{model} \"%{name}\": Delete successful") % {:model => model_name, :name => record_name})
else
error_msg = element.errors.collect { |_attr, msg| msg }.join(';')
error_msg = element.errors.collect { |error| error.message }.join(';')
add_flash(_("%{model} \"%{name}\": Error during delete: %{error_msg}") %
{:model => model_name, :name => record_name, :error_msg => error_msg}, :error)
end
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def st_edit
@edit = session[:edit] = @record = nil
replace_right_cell(:replace_trees => trees_to_replace(%i[sandt svccat stcat]))
else
@st.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@st.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@changed = session[:changed] = (@edit[:new] != @edit[:current])
javascript_flash
Expand Down Expand Up @@ -1005,8 +1005,8 @@ def atomic_req_submit
if @edit[:wf] && need_prov_dialogs?(@edit[:new][:st_prov_type])
request = @edit[:wf].make_request(@edit[:req_id], @edit[:new])
if request && request&.errors.present?
request.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
request.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
else
validate_fields
Expand Down Expand Up @@ -1058,8 +1058,8 @@ def atomic_req_submit
@edit = session[:edit] = @record = nil
replace_right_cell(:replace_trees => trees_to_replace(%i[sandt svccat stcat]))
else
st.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
st.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@changed = session[:changed] = (@edit[:new] != @edit[:current])
javascript_flash
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/chargeback_rate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def rate_save_add
session[:changed] = @changed = false
javascript_redirect(:action => @lastaction, :id => @rate[:id], :flash_msg => flash_msg)
else
@rate.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@rate.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@rate_details.each do |detail|
display_detail_errors(detail, detail.errors)
Expand Down Expand Up @@ -407,7 +407,7 @@ def new_rate_edit?
end

def display_detail_errors(detail, errors)
errors.each { |field, msg| add_flash("'#{detail.chargeable_field.description}' #{field.to_s.humanize.downcase} #{msg}", :error) }
errors.each { |error| add_flash("'#{detail.chargeable_field.description}' #{error.attribute.to_s.humanize.downcase} #{error.message}", :error) }
end

def add_row(i, pos, code_currency)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/condition_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def condition_edit
session[:changed] = @changed = false
javascript_redirect(:action => params[:button] == "add" ? "show_list" : @lastaction, :id => params[:id], :flash_msg => flash_msg)
else
condition.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
condition.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
javascript_flash
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/host_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def update
nil
else
@errors.each { |msg| add_flash(msg, :error) }
@host.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@host.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
drop_breadcrumb(:name => _("Edit Host '%{name}'") % {:name => @host.name}, :url => "/host/edit/#{@host.id}")
@in_a_form = true
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/miq_ae_class_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,8 @@ def create_namespace
add_active_node_to_open_nodes
replace_right_cell(:replace_trees => [:ae])
else
add_ae_ns.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
add_ae_ns.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
javascript_flash(:spinner_off => true)
end
Expand Down Expand Up @@ -2855,8 +2855,8 @@ def get_session_data
end

def flash_validation_errors(am_obj)
am_obj.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
am_obj.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def old_dialogs_update_create
begin
dialog.save!
rescue StandardError
dialog.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
dialog.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@changed = true
javascript_flash
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/miq_alert_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def alert_edit_save_add
alert_set_record_vars(alert)

unless alert_valid_record?(alert) && alert.valid? && !@flash_array && alert.save
alert.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
alert.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
javascript_flash
return
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/miq_policy_controller/policies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def policy_edit_save
policy.expression = @edit[:new][:expression]["???"] ? nil : MiqExpression.new(@edit[:new][:expression])

if !policy.valid? || @flash_array || !policy.save
policy.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
policy.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
javascript_flash
return
Expand Down Expand Up @@ -204,8 +204,8 @@ def miq_policy_edit_conditions
@policy.conditions.collect { |pc| pc }.each { |c| @policy.conditions.delete(c) unless mems.key?(c.id) } # Remove any conditions no longer in members
mems.each_key { |m| @policy.conditions.push(Condition.find(m)) unless @policy.conditions.collect(&:id).include?(m) } # Add any new conditions
if !@policy.valid? || @flash_array || !@policy.save
@policy.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@policy.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
javascript_flash
return
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/mixins/manager_controller_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def save_provider
end
javascript_redirect(:action => @lastaction, :id => params[:id])
else
@provider.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@provider.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
render_flash
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def rbac_group_seq_edit
if group.save
AuditEvent.success(build_saved_audit(group, params[:button] == "add"))
else
group.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
group.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
err = true
end
Expand Down Expand Up @@ -732,7 +732,7 @@ def rbac_edit_save_or_add(what, rbac_suffix = what)
end

@changed = session[:changed] = (@edit[:new] != @edit[:current])
record.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
record.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }

render_flash
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/ops_controller/settings/analysis_profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ def ap_edit
get_node_info(x_node)
replace_right_cell(:nodetype => x_node, :replace_trees => [:settings])
else
scanitemset.errors.each do |field, msg|
add_flash("#{_(field.to_s.capitalize)} #{msg}", :error)
scanitemset.errors.each do |error|
add_flash("#{_(error.attribute.to_s.capitalize)} #{error.message}", :error)
end
@edit[:new] = ap_sort_array(@edit[:new])
@edit[:current] = ap_sort_array(@edit[:current])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/ops_controller/settings/label_tag_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def label_tag_mapping_delete
page.replace_html('settings_label_tag_mapping', :partial => 'settings_label_tag_mapping_tab')
end
else
mapping.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
category.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
mapping.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
category.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
javascript_flash
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/ops_controller/settings/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def category_delete
page.replace_html('settings_co_categories', :partial => 'settings_co_categories_tab')
end
else
category.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
category.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
javascript_flash
end
end
Expand Down Expand Up @@ -95,8 +95,8 @@ def category_edit
begin
update_category.save!
rescue
update_category.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
update_category.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@in_a_form = true
session[:changed] = @changed
Expand Down Expand Up @@ -208,7 +208,7 @@ def ce_accept
end
end
unless entry.errors.empty?
entry.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
entry.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
javascript_flash(:focus => 'entry_name')
return
end
Expand Down Expand Up @@ -247,7 +247,7 @@ def ce_delete
page.replace(:tab_div, :partial => "settings_co_tags_tab")
end
else
entry.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
entry.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
javascript_flash(:focus => 'entry_name')
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/settings/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def upload_csv
rescue => bang
add_flash(_("Error during 'upload': %{message}") % {:message => bang.message}, :error)
else
imp.errors.each { |_field, msg| add_flash(msg, :error) }
imp.errors.each { |error| add_flash(error.message, :error) }
add_flash(_("Import validation complete: %{good_record}, %{bad_record}") % {
:good_record => n_("%{num} good record", "%{num} good records", imp.stats[:good]) % {:num => imp.stats[:good]},
:bad_record => n_("%{num} bad record", "%{num} bad records", imp.stats[:bad]) % {:num => imp.stats[:bad]}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/settings/zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def zone_delete
zone.destroy
rescue => bang
add_flash(bang.to_s, :error)
zone.errors.each { |field, msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) }
zone.errors.each { |error| add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error) }
self.x_node = "z-#{zone.id}"
get_node_info(x_node)
else
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/pxe_controller/pxe_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def pxe_image_edit
get_node_info(x_node)
replace_right_cell(:nodetype => x_node, :replace_trees => refresh_trees)
else
update_img.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
update_img.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@in_a_form = true
@changed = true
Expand Down Expand Up @@ -143,8 +143,8 @@ def pxe_wimg_edit
get_node_info(x_node)
replace_right_cell(:nodetype => x_node)
else
update_wimg.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
update_wimg.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@in_a_form = true
@changed = true
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/report_controller/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def db_seq_edit
if g.save
AuditEvent.success(build_saved_audit(g, @edit))
else
g.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
g.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
err = true
end
Expand Down Expand Up @@ -152,8 +152,8 @@ def db_edit
@edit = session[:edit] = nil # clean out the saved info
replace_right_cell(:replace_trees => [:db])
else
@dashboard.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
@dashboard.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@changed = session[:changed] = (@edit[:new] != @edit[:current])
javascript_flash
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/report_controller/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def menu_update
@in_a_form = false
replace_right_cell(:replace_trees => [:reports])
else
rec.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
rec.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@in_a_form = true
session[:changed] = @changed
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def miq_report_edit
end
replace_right_cell(:replace_trees => [:reports])
else
rpt.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
rpt.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@in_a_form = true
session[:changed] = !!@changed
Expand Down Expand Up @@ -1641,8 +1641,8 @@ def valid_report?(rpt)
end

unless rpt.valid? # Check the model for errors
rpt.errors.each do |field, message|
add_flash("#{field.to_s.capitalize} #{message}", :error)
rpt.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
end
@sb[:miq_tab] = active_tab if flash_errors?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/report_controller/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def schedule_edit
self.x_node = "msc-#{schedule.id}"
replace_right_cell(:replace_trees => [:schedules])
else
schedule.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
schedule.errors.each do |error|
add_flash("#{error.attribute.to_s.capitalize} #{error.message}", :error)
end
@changed = session[:changed] = (@edit[:new] != @edit[:current])
drop_breadcrumb(:name => "Edit Schedule", :url => "/miq_schedule/edit")
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/report_controller/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def widget_edit
# @schedule = nil
replace_right_cell(:replace_trees => [:widgets])
else
@widget.errors.each do |field, msg|
add_flash("#{_(field.to_s.capitalize)} #{msg}", :error)
@widget.errors.each do |error|
add_flash("#{_(error.attribute.to_s.capitalize)} #{error.message}", :error)
end
@changed = session[:changed] = (@edit[:new] != @edit[:current])
javascript_flash
Expand Down

0 comments on commit b80f0c1

Please sign in to comment.