Bug #18155
closedOrganizationsControllerTest empty array test uses invalid data for form encoding
Description
The test "OrganizationsControllerTest#test_0022_should allow empty array as param value of array field while updating organization" (and its LocationControllerTest equivalent) added in #17343 attempts to pass an empty array of smart_proxy_ids to the UI controller:
put :update, { :id => location.id, :location => {:organization_ids => []}}, set_session_user
In Rails 4.2.7.1 this is passed through:
[1] pry(#<OrganizationsController>)> params
=> {"organization"=>{"smart_proxy_ids"=>[]}, "id"=>"61304186", "controller"=>"organizations", "action"=>"update", "locale"=>nil}
But in Rails 5.0.1 it is missing, and causes the test for updating with an empty array to fail:
[1] pry(#<OrganizationsController>)> params
=> <ActionController::Parameters {"id"=>"61304186", "controller"=>"organizations", "action"=>"update", "locale"=>nil} permitted: false>
The test data isn't valid, as an empty array can't be represented in form encoded data.
When compared to the input generated by the Foreman UI, the multiselects generate an empty "" entry in the array to correctly pass an "empty" array through in the form data. This would generate an entry in the form data of smart_proxy_ids[]=
2017-01-19T14:12:33 709cf7eb [app] [I] Processing by OrganizationsController#update as HTML
2017-01-19T14:12:33 709cf7eb [app] [I] Parameters: {"utf8"=>"✓", "authenticity_token"=>"[..]", "organization"=>{"parent_id"=>"", "name"=>"munge", "description"=>"", "ignore_types"=>["0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], "user_ids"=>[""], "smart_proxy_ids"=>["", "6"], "subnet_ids"=>[""], "compute_resource_ids"=>[""], "medium_ids"=>[""], "provisioning_template_ids"=>["", "60"], "ptable_ids"=>["", "102"], "domain_ids"=>[""], "realm_ids"=>[""], "environment_ids"=>[""], "hostgroup_ids"=>[""]}, "commit"=>"Submit", "id"=>"35-munge"}
The Rails 5 test framework that generates the request objects is filtering out invalid parameters when converting them internally from the hash in the test case to the form encoded version. The test data should be updated to pass an empty string as well, like the form in the real UI.
Updated by Dominic Cleal almost 8 years ago
- Related to Bug #17343: It is not possible to use empty list as value for optional parameters via API added
Updated by The Foreman Bot almost 8 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/4208 added
Updated by Dominic Cleal almost 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 1f206274f4e996da2fe8dc934a199b2491320eef.
Updated by Dominic Cleal almost 8 years ago
- Translation missing: en.field_release set to 209