On Mon, Aug 22, 2011 at 12:14 AM, ct9a <anexi...@gmail.com> wrote:

> Hi, guys,
>
>  After reading the rspec book (dec 2010 edition), I went on to write
> controller specs for an application I'm porting over from rails 2.3.x
> to rails 3.
>
>
> 1) I ran 'rake routes' and got the following:
>
>    parts GET    /parts(.:format)
> {:action=>"index", :controller=>"parts"}
>          POST   /parts(.:format)
> {:action=>"create", :controller=>"parts"}
>  new_part GET    /parts/new(.:format)
> {:action=>"new", :controller=>"parts"}
> edit_part GET    /parts/:id/edit(.:format)
> {:action=>"edit", :controller=>"parts"}
>     part GET    /parts/:id(.:format)
> {:action=>"show", :controller=>"parts"}
>          PUT    /parts/:id(.:format)
>

The :id means you need to pass an "id" to the route helper method.


> {:action=>"update", :controller=>"parts"}
>          DELETE /parts/:id(.:format)
> {:action=>"destroy", :controller=>"parts"}
>
> 2) I ran 'rake spec:controllers' and got the error below.
>
> Pending:
>  PartsController the new part object's updates are saved successfully
> saves updates to a new part
>    # Not Yet Implemented
>    # ./spec/controllers/parts_controller_spec.rb:59
>
> Failures:
>
>  1) PartsController saves updates to an existing part object
> successfully
>     Failure/Error: put :update#, :part => { 'title' => 'Grimspeed' }
>     ActionController::RoutingError:
>       No route matches {:controller=>"parts", :action=>"update"}
>     # ./spec/controllers/parts_controller_spec.rb:55
>
> 3) Here's what the spec reads:
>
>    it 'saves updates to an existing part object successfully' do
>        Part.should_receive(:update).
>            with( 'title' => 'Brake pads' ).
>            and_return(part)
>        put :update#, :part => { 'title' => 'Brake pads' }
>    end
>

So you need to "find" the part first:

part = double('part')
Part.should_receive(:find).with(1).and_return(part)
Part.should_receive(:update).with('title' => 'Brake pads').and_return(part)
put :update, :id => 1, :part => {'title' => 'Brake pads'}



>
>
>
>
> What I do not understand is that
> the :controller=>"parts", :action=>"update" route actually exists
> (when I ran "rake routes") but the tests does not acknowledge the
> existence of the 'update' method in the controller with PUT request.
>

You need to pass in the :id for Rails to recognize the route.


>
>
>
>
>
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to