Refactor params hash iteration in Api::CompatibilityChecker#check_create_host_nested
|Triaged:||Fixed in Releases:|
|Bugzilla link:||Found in Releases:|
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 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.
fixes #18982 - replace AC::Params#each using one-arg block
ActionController::Parameters#each works differently in Rails 5.0: it no
longer yields an array of [key, value] entries for hashes, only the
key when given a block with arity of one. This method now iterates over
only the values when passed a hash or AC::Parameters instance.