Project

General

Profile

Actions

Refactor #18982

closed

Refactor params hash iteration in Api::CompatibilityChecker#check_create_host_nested

Added by Dominic Cleal over 7 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Api::CompatibilityChecker#check_create_host_nested iterates over nested attributes in a params hash and should work for both arrays and hash styles of nested attrs, but it does so using a single each call yielding a single argument.

This works on Rails 4 where ActionController::Parameters inherits each from a Hash, as an array of [key, value] would be yielded instead, which the block checks for (attribute[1] if attribute.is_a?(Array)).

In Rails 5.0, AC::Parameters has its own each implementation that only yields to two arguments. Using each do |attribute| will instead be yielded only the key name. This causes:

Api::V2::HostsControllerTest#test_0010_should create host with host_parameters_attributes sent in a hash [test/controllers/api/v2/hosts_controller_test.rb:186]:
"Host.count" didn't change by 1.
Expected: 2
  Actual: 1

The iteration should be handled differently for arrays and AC::Parameters/hashes.


Related issues 1 (0 open1 closed)

Blocks Foreman - Feature #19050: Add support for running under Ruby on Rails 5.0ClosedDominic Cleal03/28/2017Actions
Actions #1

Updated by The Foreman Bot over 7 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4399 added
Actions #2

Updated by Dominic Cleal over 7 years ago

  • Blocks Feature #19050: Add support for running under Ruby on Rails 5.0 added
Actions #3

Updated by Dominic Cleal over 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions #4

Updated by Marek Hulán almost 7 years ago

  • Translation missing: en.field_release set to 240
Actions

Also available in: Atom PDF