[rspec-users] Controller tests fail to parse route based on resource

Marcelo de Moraes Serpa
2010-04-26T00:14:15Z

Hi Phillip,

The code is actually post :update, I have mistyped there. But that''s
not the
issue.

The problem is when I try to use the Rails-generated resource method: put
user_url(@user). It does generate the URL correctly (
http://test.domain/users/int where int is any integer) but it fails to
actually map this to UsersController#update:

PUT /users/:id should map to controller => ''users'',:action
=> ''update'':

But I get the following error when in the controlle test example (the put
user_url(@user)):

ActionController::
UnknownAction in ''UsersController#update on (snip)
*No action responded to /users/89*. Actions: (snip)

Thanks,

Marcelo.


On Sun, Apr 25, 2010 at 6:01 PM, Phillip Koebbe <phillipkoebbe at
gmail.com>wrote:

>  On 2010-04-25 5:52 PM, Marcelo de Moraes Serpa wrote:
>
>> Hello list,
>>
>> I have a controller example that looks like this:
>>
>>    it ''Should update (PUT /users/:id)'' do
>>      @attributes = @user.attributes
>>      @attributes[:firstname] = "Another one"
>>      lambda {
>>        put user_url(@user), at attributes
>>        User.find(@user.id <http://user.id>).firstname =>>
@attributes[:firstname]
>>
>>        response.should redirect_to(users_path)
>>      }.should_not raise_error
>>    end
>>
>> However, this fails with the following error message
>>
>> ActionController::UnknownAction in ''UsersController#update on
(snip)
>> No action responded to /users/89/edit. Actions: (snip)
>>
>> I''m not sure why it is not routing PUT /users/:id to
>> UsersController#update. Any ideas?
>>
>> The workaround I have as of now is to:
>>
>> post :update, {:id => @user.id <http://user.id>, :user =>
@attributes},
>> which works fine, but not RESTful.
>>
>>
> What happens if you change that to
>
> put :update, ...
>
> ?
>
> Peace,
> Phillip
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20100425/1f1a8abb/attachment.html>