I am having troubles with an RSPec test. The test does a PUT with some objects in the request. The controller which receives the PUT seems to be not getting the correct values
For example, ‘put :update, :id => @channel.id, :channel => @channel, :tags => @tag’ Then, in the Controller, when I try to use params[:tags] there is an integer in that location. A Gist with the Spec and the controller method is at https://gist.github.com/3715021
This started happening when I upgraded from Rails 3.0.13 to 3.1.8
Any idea what might be happening here and how to resolve it?
I’m assuming that
@tagis an object from your Tags model. When you give Rails an object likeor in a url helper (e.g.,
foo_path(foo)),Rails will turn your object into a parameter suitable for use in a url via the
#to_parammethod. You’re probably getting an integer becauseTag#to_paramreturns the id of the tag in your db.It looks like your update action, by contrast, expects
params[:tags]to be a hash, presumably generated from a form that includes fields for values liketags[:name].I can’t help much more without knowing more about the relevant code. But I’m guessing what you want to do is change your test to read
or something like that, mimicking the params you’d get by actually submitting the form that PUTs to your update action.