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

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

    The way I like to test the update method is to just ensure that the updated_at time is greater than it was before. When you do this you can change the contents of the entire instance variable and still check if everything was updated. For instance:

    describe "PUT 'update/:id'" do
      it "allows an article to be updated" do
        prev_updated_at = @article.updated_at
        @attr = { :title => "new title", :content => "new content" }
        put :update, :id => @article.id, :article => @attr
        @article.reload
        @article.updated_at.should != prev_updated_at 
      end
    end
    

提交回复
热议问题