开发者

Integration Testing with Ruby and the assigns keyword

开发者 https://www.devze.com 2023-01-29 12:19 出处:网络
I am trying to perform some integration testing to see if the article gets updated. Here is my integration test:

I am trying to perform some integration testing to see if the article gets updated. Here is my integration test:

test "update existing article" do 

    # create an article 
    @article = Article.new 
    @article.title = "title"
    @article.abstract = "abstract"
    @article.description = "description" 

    if @article.save 

      post "/articles/edit", :id => @article.id

      assert assigns(:article)

    end

  end

And here is my articles_controller implementation:

def edit

    @article = Article.find(params[:id])

    respond_to do |format|
      format.html 
      f开发者_开发百科ormat.xml { render :xml => @article }
    end

  end

The last line in test about assigns fails. From my understanding assigns(:article) means that the variable @article will be populated.


Take a look at this line:

post "/articles/edit", :id => @article.id

The problem is that the edit action takes a GET, not a POST, so it's probably never getting called. try:

get edit_article_path, :id => @article.id

(note that if you're running a controller test, it's best to use a symbol for the action name.)

0

精彩评论

暂无评论...
验证码 换一张
取 消