activeadmin / inherited_resources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails generated controller test "test_should_get_new" would fail on strong parameters

chengguangnan opened this issue · comments

I have "snapshots_params" in my InheritedResources Controller.

class SnapshotsController < InheritedResources::Base
  def snapshot_params
     params.require(:snapshot).permit(:html, :location)
  end

However, InheritedResources will invoke "snapshot_params" even for the REST "new" action which caused the default test case to fail. See below.

SnapshotsControllerTest#test_should_get_new:
ActionController::ParameterMissing: param is missing or the value is empty: snapshot
    app/controllers/snapshots_controller.rb:4:in `permitted_params'
    test/controllers/snapshots_controller_test.rb:15:in `block in <class:SnapshotsControllerTest>'

I think this is an error, because params can be empty here, no need to validate it here.

If you don't need to validate the params don't call require