2012-07-29 3 views
1

나는 기능 테스트를 계속 실패하고 있으며 그 이유를 모르겠습니다. 이것은 포럼의 일부이며 테스트는 게시물 작성자가 자신의 게시물을 삭제하도록 허용하는 것입니다.레일 기능 테스트가 파괴되지 않습니다

수동으로 시도 할 때 콘솔과 브라우저에서 게시물을 삭제할 수 있습니다. 무엇이 잘못 될지 파악할 수 없습니다. 여기

one: 
    id: 1 
    body: MyText 
    forum_id: 1 
    topic_id: 1 
    player_id: 2 
two: 
    id: 2 
    body: MyText 
    forum_id: 1 
    topic_id: 1 
    player_id: 2 
three: 
    id: 3 
    body: MyText 
    forum_id: 1 
    topic_id: 2 
    player_id: 3 

실패 유지하는 시험이다 : 여기서
def destroy 
    @post = Post.find(params[:id]) 
    if @post.player_id == current_player || current_player.admin == true # I can't delete anyone else's posts unless I am the administrator. 
if @post.topic.posts_count > 1 # if topic is more than one post, delete just the post 
    @post.destroy 
    flash[:notice] = "Post was successfully destroyed." 
    redirect_to topic_path(@post.topic) 
else # else, if the topic is only one post, delete the whole thing 
    @post.topic.destroy 
    flash[:notice] = "Topic was successfully deleted." 
    redirect_to forum_path(@post.forum) 
    end 
    else # You are not the admin or the topic starter 
    flash[:notice] = "You do not have rights to delete this post." 
    redirect_to topic_path(@post.topic) 
    end 
end 

가 posts.yml 파일이다 : 여기

컨트롤러의 파괴 작용이다

test "should destroy post as author" do 
    sign_in players(:player2) 
    assert_difference('Post.count', -1) do # Line 41 
    delete :destroy, :id => posts(:one) 
    end 
    assert_redirected_to topic_url(assigns(:topic)) 
end 

다음은 내가 받고있는 오류입니다.

1) Failure: test_should_destroy_post_as_author(PostsControllerTest) [../test/functional/posts_controller_test.rb:41]: 
"Post.count" didn't change by -1. 
<2> expected but was <3>. 

이 점에 대해 큰 도움을 주시면 감사하겠습니다. 벽에 머리를 대고있는 것처럼 느껴진다. 대답은 내가 누락 된 단순한 것이라고 확신한다. 미리 감사드립니다.

답변

0

나는 왜 그 특정한 말씨가 작동하지 않는지 잘 모르겠지만 콘솔에있는 것처럼 게시물을 파기 할 때 테스트가 통과되도록 고정했습니다. 대신

: delete :destroy, :id => @post

내가 사용 : 더 이상 컨트롤러에 요청을 전송하기 때문에 Post.destroy(@post)

+1

지금까지 내가 아는 한,이 테스트의 의도를 중단하지 않습니다. – sscirrus

관련 문제