Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stub parameters from a controller?

For my tests I need a controller where I can set my own parameters. With parameters I mean the one you get when invoking controller.params

{"action"=>"show",
 "controller"=>"merchants",
 "wine_id"=>"1",
 "id"=>"346343"}

The problem is, I don't know what the proper way for stubbing is here. There are three occurrences:

  • controller.request.env['action_dispatch.request.path_parameters']
  • controller.params
  • controller.url_options[:_recall]

In all three the same information is stored, but what's the interfaced way to set these values?

like image 456
Guarana Joe Avatar asked Dec 12 '13 22:12

Guarana Joe


1 Answers

Usual way of accessing params is by controller.params. So i would advise you to stub params

controller.stub(:params).and_return({:param1 => "value", :param2 => "value"})
like image 151
usha Avatar answered Nov 13 '22 18:11

usha