2010-12-07 2 views
2

いくつかの統合テストを実行して、記事が更新されるかどうかを確認しようとしています。ここに私の統合テストは、次のとおりです。Rubyとのインテグレーションテストとassignsキーワード

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 

そして、ここでは私のarticles_controller実装です:

def edit 

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

    respond_to do |format| 
     format.html 
     format.xml { render :xml => @article } 
    end 

    end 

割り当てについてのテストの最後の行に障害が発生しました。私の理解から、assigns(:article)は、変数@articleが移入されることを意味します。

答えて

2

は、この行を見てみましょう:

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

問題は、editアクションはPOSTない、GETをとり、それはおそらく、呼び出されることはありませんばかりだということです。試してみてください。

get edit_article_path, :id => @article.id 

(あなたは、コントローラのテストを実行している場合、それは、アクション名に記号を使用するのが最適だということに注意してください。)

+0

GETを使用して編集私は次のエラーを取得する:1)エラー: test_update_existing_article(ArticleFlowsTest): と、ArgumentError:悪い引数は(URIオブジェクトまたはURI文字列を期待) – azamsharp

+0

「test_update_existing_article '/test/integration/adding_article_flows_test.rb:30:in私は統合テストを実行しています! – azamsharp

+0

ああ、申し訳ありません!上記の私の更新を使ってみて、 ':edit'に' edit_article_path'を下書きしてみてください。 –

関連する問題