Hi folks,

I've just spent a day trying to write up a basic update spec for a
nested resource - all without avail. I'm quite new to RSpec & not sure
what I'm doing wrong. I can't seem to get a stub that recognises the
required association to the parent object. I've tried factories and
outright database calls, none of which seem to catch the
should_receive. If anyone could offer a basic example of the nested
equivalent of something like the following, I'd be very appreciative.

        it "updates the requested post" do
          Post.stub(:find).with("14") { mock_post }
          mock_post.should_receive(:update_attributes).with({'these'
=> 'params'})
          put :update, :id => "14", :post => {'these' => 'params'}
        end

Controller action here:

  def update
    @comment = Comment.find(params[:id])
    respond_to do |format|
      if @comment.update_attributes(params[:comment])
        flash[:notice] = 'Post successfully updated'
        format.html { redirect_to(@comment.post) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @comment.errors, :status
=> :unprocessable_entity }
      end
    end

  end

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

Reply via email to