administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Fix 'found unpermitted parameter: :orders' dynamically

Open jondkinney opened this issue 7 years ago • 7 comments

Hard coding :orders here gets the tests to pass, but is naive. Unless the intention is to override the sanitized_order_params for each app in the admin/application_controller.rb file and manually specify every new resource that is added?

Instead, what is working for me is a dynamic list of any possible has_many resource names in the system as shown in this PR. Lack of specifying these permitted params will result in the following error messages.

ActionController::UnpermittedParameters in Admin::Customers#show

found unpermitted parameter: :orders

jondkinney avatar Jul 04 '17 04:07 jondkinney

This looks good! Do you think there's a way we can write a spec for this?

nickcharlton avatar Jul 04 '17 12:07 nickcharlton

There are existing tests that check whether or not the :orders param is allowed. If you remove this code some specs will fail. Are you looking for something that more directly tests this implementation?

jondkinney avatar Jul 04 '17 12:07 jondkinney

Yeah, I'd like to see something which fails without us providing resources like is done here.

nickcharlton avatar Jul 04 '17 14:07 nickcharlton

@nickcharlton a tests already exists that will fail. Without :orders hard coded, and without the splatting of the resources the following failure occurs

rspec ./spec/features/show_page_spec.rb:26

     ActionView::Template::Error:
       found unpermitted parameter: :orders

With the dynamically provided splatted resource names, it's all green. So I think we're good? Thanks!

jondkinney avatar Jul 04 '17 18:07 jondkinney

I think that we should test the implementation in some form of unit test and not rely on the feature spec to catch it.

There's already an existing helper spec in: spec/helpers/administrate/application_helper_spec.rb, which would be a great place to start in.

nickcharlton avatar Jul 06 '17 11:07 nickcharlton

@nickcharlton I'll be revisiting this soon. I have a few PRs that I'll get tidy'd up either this weekend or next week.

jondkinney avatar Jul 12 '17 15:07 jondkinney

@jondkinney, is this something you'd be able to look at again?

nickcharlton avatar Oct 05 '20 18:10 nickcharlton

Closed due to lack of activity.

pablobm avatar Apr 17 '23 13:04 pablobm