[rspec-users] Route is valid but not found :(

Gordon Yeong anexiole at gmail.com
Tue Aug 23 08:11:51 EDT 2011


>
>
>  Do you have a before filter somewhere that is preventing the
> :update_attributes message from being received?
>
> I have checked my application's controllers
(app/controllers/application_controller.rb and
 app/controllers/parts_controller.rb) and controller spec
(spec/controllers/parts_controller_spec.rb) and found no before filter that
is preventing the :update_attributes message from being received by Parts.

Below is what my spec/controllers/parts_controller_spec.rb looks like:

------- Source code, spec/controllers/parts_controller_spec.rb starts
-----------------------

require 'spec_helper'

describe PartsController do
    let(:part){
        mock_model('Part').as_null_object
    }

    before do
        Part.stub(:new).and_return(part)
    end

    it "creates a new part" do
        Part.should_receive(:new).
            with('title' => 'HKS boost controller').
            and_return(part)
        post :create, :part => { 'title' => 'HKS boost controller' }
    end

    context "saves the new part object successfully" do
        it "sets the flash with a success message" do
            post :create
            flash[:notice].should eq('Part was successfully created.')
        end

        it "redirects the user back to the Parts index page" do
            post :create
            response.should redirect_to( :action => 'index' )
        end
    end

    context "the new part object fails to save" do
        before do
            # sabotage and make the save fail
            part.stub(:save).and_return(false)
            # call the create method which will have save in its process
            post :create
        end

        it "assigns @part with the data from db (or a blank one if it's the
first time" do
            assigns[:part].should eq(part)
        end

        it "renders the 'new' template again" do
            # test that the template, 'new' is rendered. Of course, for this
            # work, the part's attribute variable values must be passed to
the
            # view for rails to successfully render the template
            response.should render_template('new')
        end
    end

    context 'saves updates to an existing part object successfully' do
        it 'does its job in saving the update' do
            Part.should_receive(:find).with(1).and_return(part)
            Part.should_receive(:update_attributes).with('title' => 'Brake
pads').and_return(part)
            put :update, :id => 1, :part => {'title' => 'Brake pads'}
            flash[:notice].should eq('Part was successfully updated.')
        end
    end

end

------- Source code, spec/controllers/parts_controller_spec.rb ends
-----------------------

Do you have any good tutorials which illustrate the update message which I
could refer to?
I've been digging but can't find anything helpful :(

thanks for your help :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110823/4d16843f/attachment.html>


More information about the rspec-users mailing list