Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no implicit conversion of nil into Array using permit #495

Closed
shedd opened this issue Apr 16, 2014 · 3 comments
Closed

no implicit conversion of nil into Array using permit #495

shedd opened this issue Apr 16, 2014 · 3 comments
Milestone

Comments

@shedd
Copy link

shedd commented Apr 16, 2014

Seems to be another issue for 2.6.0

Following on from my update to #482

When my strong parameters method is defined as follows (using fetch rather than require):

def order_params
  # use params.fetch rather than params.require to handle cases where params are empty
  params.fetch(:order, {}).permit(:eta, :diner_id)
end

I run into the following failure:

4) Restaurant::OrdersController POST create should permit POST #create to receive parameters :eta and :diner_id
   Failure/Error: it { should permit(:eta, :diner_id).for(:create) }
   TypeError:
     no implicit conversion of nil into Array
   # /usr/local/rvm/gems/ruby-2.1.1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/array.rb:20:in `-'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/array.rb:20:in `call'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/array.rb:20:in `block (2 levels) in <class:Array>'
   # /usr/local/rvm/gems/ruby-2.1.1/bundler/gems/shoulda-matchers-8f933f80647e/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb:83:in `parameters_difference'
   # /usr/local/rvm/gems/ruby-2.1.1/bundler/gems/shoulda-matchers-8f933f80647e/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb:52:in `failure_message'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:30:in `handle_matcher'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/memoized_helpers.rb:68:in `should'
   # ./spec/controllers/restaurant/orders_controller_spec.rb:46:in `block (3 levels) in <top (required)>'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `instance_eval'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `block in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `call'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `call'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:111:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:390:in `block in run_examples'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `map'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `run_examples'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:371:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `map'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block in run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/reporter.rb:58:in `report'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:25:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
   # /usr/local/rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

When I change this back to params.require the test passes, however, I have scenarios where params can be empty.

@mcmire
Copy link
Collaborator

mcmire commented Apr 22, 2014

Fixed in 218293a.

@mcmire mcmire closed this as completed Apr 22, 2014
@mcmire
Copy link
Collaborator

mcmire commented Apr 22, 2014

@shedd I just released 2.6.1.rc1, can you update your Gemfile and re-run your tests and see if they work?

@shedd
Copy link
Author

shedd commented Apr 22, 2014

Thanks! Specs are now passing with one exception, per the comment I just added in #482.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants