Project

General

Profile

Bug #18155

OrganizationsControllerTest empty array test uses invalid data for form encoding

Added by Dominic Cleal over 5 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

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.


Related issues

Related to Foreman - Bug #17343: It is not possible to use empty list as value for optional parameters via APIClosed2016-11-15

Associated revisions

Revision 1f206274 (diff)
Added by Dominic Cleal over 5 years ago

fixes #18155 - add string to empty form-encoded arrays in test

This test attempts to send an empty `:smart_proxy_ids => []` parameter
emulating the UI to unset smart_proxy_ids on a taxonomy, but Rails 5
filters this empty parameter out when converting it internally to a form
encoded parameter (since it's not possible to specify an empty array in
a form) for the purposes of the test.

Comparing the test to the real UI shows that it really submits
`:smart_proxy_ids => [""]` to pass an empty array, so update the test
data to match.

History

#1 Updated by Dominic Cleal over 5 years ago

  • Related to Bug #17343: It is not possible to use empty list as value for optional parameters via API added

#2 Updated by The Foreman Bot over 5 years ago

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

#3 Updated by Dominic Cleal over 5 years ago

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

#4 Updated by Dominic Cleal over 5 years ago

  • Legacy Backlogs Release (now unused) set to 209

Also available in: Atom PDF