2011-05-02 1 views
1

이 확인 방법을 감안할 때 :이 확인 속성을 전환하지만, 심지어 컨트롤러하지만, 모든 것 같으면토글 스펙의 컨트롤러에서 작업하지만 : 레일 3 + RSpec에

if (@bucket.confirmation_code == @code) 
     puts "OLAAA" 
     @bucket.toggle!(:confirmation) 
     @bucket.save 
     flash[:success] = "Successfully confirmed bucket." 
     redirect_to bucket_url(@bucket) 
    else 
     flash[:fail] = "Error confirming bucket." 
     redirect_to bucket_url(@bucket) 
    end 

나는 사양 테스트가를 (confirmation == true), 테스트가 실패했습니다 (true 대신 confirmation == false).

테스트는 다음과 같습니다

it "should have a confirmation URL" do 
     @attr3 = {:email => "[email protected]", :confirmation_code => "ola123"} 
     post :create, :bucket => @attr3 
     @bucket = Bucket.last 
     post :confirm, :id => @bucket.id, :code => "ola123" 
     @bucket.save 
     @bucket.confirmation.should == true 
     end 

답변

1

대신 컨트롤러 방법은 이미이 작업을 수행하기 때문에 불필요한 @bucket.save, 이후에 변경된 현재 값에 대한 데이터베이스를 (쿼리 다시 것 @bucket.reload을 수행 먼저 @bucket = Bucket.last을 할당했습니다. 그런 다음 confirmation 값은 true을 반환해야합니다.