How to write an RSpec test for a simple PUT update?

前端 未结 4 1839
长情又很酷
长情又很酷 2020-12-08 19:36

I\'m trying to solidify my understanding of rails and the BDD workflow, so I wanted to start small by creating one of those mini-blogs, but with rspec. Right now I have an A

4条回答
  •  甜味超标
    2020-12-08 20:29

    FactoryGirl.define :article do
      title "a title"
      content "hello world"
    end
    
    before(:each) do
      @article = Factory(:article)
    end
    
    it "should re-render edit template on failed update" do
      @attr = { :title => "", :content => "new content" }
      put :update, :id => @article.id, :article => @attr
    
      flash[:notice].should be_nil
      response.should render_template('edit')
    end
    
    it "should redirect to index with a notice on successful update" do
      @attr = { :title => "new title", :content => "new content" }
      put :update, :id => @article.id, :article => @attr
    
      assigns[:article].should_not be_new_record
      flash[:notice].should_not be_nil
      response.should redirect_to(:action => 'index')
    end
    

提交回复
热议问题