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

前端 未结 4 1838
长情又很酷
长情又很酷 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:28

    When you are doing a PUT :update remember that you are editing an existing model, which you need to call in the put. Just pass your @article and update the attributes as follows.

    describe "PUT 'update/:id'" do
      it "allows an article to be updated" do
        put :update, :id => @article.id, :article => @article.attributes = { :title => "new title", :content => "new content" }
        response.should be_successful
      end
    end
    

提交回复
热议问题