2011-12-11 2 views
0

제 12 장, 연습 1에서 필자가 테스트 할 때 필자의 테스트가 실패하지 않는 이유를 알아 내는데 어려움을 겪고있다. 아웃 : 의존 => => 의존 :레일 튜토리얼 Ch 12 연습 1 - 꺼낸 후에 테스트가 실패 할 수 없음 : dependent => : destroy

has_many :relationships, 
    :foreign_key => "follower_id" 
has_many :following, :through => :relationships, :source => :followed 
has_many :reverse_relationships, 
    :foreign_key => "followed_id" 
    :class_name => "Relationship" 
has_many :followers, :through => :reverse_relationships, :source => :follower 

아직도

을 통과하는 모든 시험 결과 파괴하지 않고, 사용자 모델

내 테스트

내 모델에서 파괴 6,

답변

0

이 .... 코드의

#1 @followed.destroy 
    #2 @user.followers.should_not include(@followed) 

한 줄 # 1 당신의 테스트 논리에 오류가있는 것 같습니다, 나는 당신이 그것을 파괴 호출 할 때 전무되고, 라인 # 2 @followed 생각 @ user.followers에는 "nil"객체가 없으므로 테스트가 계속 진행되는 이유 일 수 있습니다. 다음 코드를 사용하여 예상대로 작동했습니다.

r1 = @user.follow!(@followed) 
    r2 = @followed.follow!(@user) 
    @user.destroy 
    [r1, r2].each do |relationship| 
    Relationship.find_by_followed_id(relationship.followed_id).should be_nil 
    end 
관련 문제