The intention of require
is for working with Rails form_for
objects, whereby the params hash will include the name of the object you're wrapping a form around. So like this:
ActionController::Parameters.new(person: { name: 'Francesco' }).require(:person)
In this case, the form_for
would have been wrapped around a Person
object. So the .require(:person)
will then wrap the resulting hash ({ name: 'Francesco' }
) up into an ActionController::Parameters
object which can respond to .permit
. So your test just wasn't mimicking the expected params use-case.
Also, it makes sense that require
would only accept one argument since you'd want to setup a unique <attribute>_params
method per object type since, again, these are meant to be wrappers around a specific object. But, normally you'd only have 1 root object being sent into a form submit, and sub objects within that.