Project

General

Profile

Actions

Bug #18568

closed

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

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

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
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.

Actions

Also available in: Atom PDF