Testing GET in Rail Controller
I have a feeling that I am just doing something syntactically wrong, but Google "GET" is surprisingly difficult, so I was hoping someone here might know the answer to this question.
I am trying to test a Rails controller from an RSpec test. I am following the example I found here: http://www.elevatedrails.com/articles/2007/09/10/testing-controllers-with-rspec/ , but I am obsessed with the actual execution of the method I am testing.
I am making a GET request where like the post above does a POST. I am passing 2 producers and a parameter model.
My url would ideally look like http://mysite.com/Products/index/Manufacturer/ModelName
I can't seem to figure out the syntax for calling the request request otherwise. Right now I have
get :index, :manufacturer=>@manufacturer, :modelName=>@modelName
and i will be back
ArgumentError in 'ProductController. Finding a valid product follows retrieving product 'wrong number of arguments (0 for 2)
Any thoughts?
edit: It should be noted that @manufacturer and @modelName are defined earlier (: each)
a source to share
As I suspected, this was green programming.
I have defined the controller method as
def index(manufacturer, modelName)
When I really needed to use the params hash to access the attributes. Then I had to define a custom route since id is the only parameter that is expected to be passed to the default controller method.
once i did that i changed the spec to read
get :index, {:manufacturer=>@manufacturer, :modelName=>@modelName}
and it worked.
Thanks for the comments everyone.
a source to share