Project

General

Profile

Actions

Bug #18155

closed

OrganizationsControllerTest empty array test uses invalid data for form encoding

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

Status:
Closed
Priority:
Low
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
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 1 (0 open1 closed)

Related to Foreman - Bug #17343: It is not possible to use empty list as value for optional parameters via APIClosedKavita Gaikwad11/15/2016Actions
Actions #1

Updated by Dominic Cleal over 7 years ago

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

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/4208 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 Dominic Cleal over 7 years ago

  • translation missing: en.field_release set to 209
Actions

Also available in: Atom PDF