Project

General

Profile

Bug #18568

KeepParam helper returns Hash (WIA) instead of AC::Parameters on Rails 5

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

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

Description

Under Rails 5, the KeepParam controller concern isn't functioning correctly, causing test failures such as:

Error:
ComputeAttributesControllerTest#test_0004_should update compute_attribute:
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a ActionController::Parameters. -- <ActionController::Parameters {"flavor_id"=>"t2.medium"} permitted: true>
    app/controllers/compute_attributes_controller.rb:24:in `update'
    app/controllers/concerns/application_shared.rb:14:in `set_timezone'
    app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
    test/controllers/compute_attributes_controller_test.rb:37:in `block in <class:ComputeAttributesControllerTest>'

The return value of the keep_param method has changed to a HWIA from AC::Parameters, as can be seen by extending its unit test:

Failure:
KeepParamParametersTest#test_0001_retains parameter within top-level hash [/home/dcleal/code/foreman/foreman/test/unit/concerns/parameters/keep_param_test.rb:9]:
Expected {"login"=>"foo"} to be a kind of ActionController::Parameters, not ActiveSupport::HashWithIndifferentAccess.

The root cause is a bug in Rails 5.0 (caused by https://github.com/rails/rails/commit/14a3bd5) where AC::Parameters#update now returns a HWIA instead of an AC::Parameters instance.

Since #update is deprecated in 5.0 (being a Hash method), refactoring this to use the #[]= setter will fix both the bug and future deprecation.

Associated revisions

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

fixes #18568 - replace deprecated AC::Parameters#update

The #update method in Rails 5 is returning a HWIA rather than the
ActionController::Parameters instance, causing keep_param to return the
wrong object type. It is also deprecated in 5.0, so replace it with a
simpler and supported assignment through #[]=.

History

#1 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/4307 added

#2 Updated by Dominic Cleal over 5 years ago

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

#3 Updated by Dominic Cleal over 5 years ago

  • Legacy Backlogs Release (now unused) set to 209

Also available in: Atom PDF