2010-12-07 2 views
2

일부 통합 테스트를 수행하여 기사가 업데이트되었는지 확인하려고합니다. 여기Ruby와의 통합 테스트 및 할당 키워드

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 채워집니다 의미합니다.

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

문제는 편집 작업이 GET 아닌 POST 걸린다, 그래서 아마 호출되지 점점 적도 :

답변

2

이 줄을보세요. 시도 :

get edit_article_path, :id => @article.id 

(당신이 컨트롤러 테스트를 실행하는 경우,이 액션 이름에 대한 기호를 사용하는 것이 가장 좋습니다 있습니다.)

+0

을 GET을 사용하여 편집 나는 다음과 같은 오류가 발생합니다 : 1) 오류 : test_update_existing_article (ArticleFlowsTest) : 하면 ArgumentError : 잘못된 인수 (예상 URI 객체 또는 URI 문자열)'test_update_existing_article ' – azamsharp

+0

내가 통합 테스트를 실행하고 /test/integration/adding_article_flows_test.rb:30:in ! – azamsharp

+0

아, 죄송합니다. 위의 내 업데이트를 사용하고': edit'에'edit_article_path'라는 이름을 붙여보십시오. –