2012-01-30 4 views
0

나는 레일 3.1 응용 프로그램이 레일 나는이 간단한 사용자 사양종속 : 작동하지 않는 파괴, 3.1

require 'spec_helper' 

describe User do 
    describe "deleting user" do 
    let(:user) { FactoryGirl.create(:user) } 
    context "that has accounts" do 
     it "deletes the user an all its accounts" do 
     FactoryGirl.create(:account, name: 'Santander', user: user) 
     FactoryGirl.create(:account, name: 'BCI', user: user) 
     user.accounts.length.should == 2 
     user.delete 
     user_accounts = Account.where(user_id: user.id) 
     user_accounts.should be_nil 
     end 
    end 
    end 
end 

을 가지고 모델은

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    attr_accessible :email, :password, :password_confirmation, :remember_me 

    has_many :accounts, dependent: :destroy 
    has_many :categories, dependent: :destroy 
end 

class Account < ActiveRecord::Base 
    belongs_to :user 
end 
있는 곳

다음 오류가 발생합니다.

1) User deleting user that has accounts deletes the user an all its accounts 
    Failure/Error: user_accounts.should be_nil 
     expected: nil 
      got: [#<Account id: 400, name: "BCI", start_balance: 0, atype: "checking_account", user_id: 1692, current_balance: 0, interest_rate: nil, billing_day: nil, created_at: "2012-01-30 00:42:51", updated_at: "2012-01-30 00:42:51">, #<Account id: 399, name: "Santander", start_balance: 0, atype: "checking_account", user_id: 1692, current_balance: 0, interest_rate: nil, billing_day: nil, created_at: "2012-01-30 00:42:51", updated_at: "2012-01-30 00:42:51">] 
    # ./spec/models/user_spec.rb:13:in `block (4 levels) in <top (required)>' 

아무 일도 일어나지 않을 것입니다. 문제가 무엇인가요? 나는 개발 환경에서 레일 콘솔에서이 수동으로 시도하고 잘 모르겠어요 너무

답변

0

작동하지만이 시도하지 않았다

describe User do 
    describe "deleting user" do 
    let(:user) { FactoryGirl.create(:user) } 
    context "that has accounts" do 
     it "deletes the user an all its accounts" do 
     FactoryGirl.create(:account, name: 'Santander', user: user) 
     FactoryGirl.create(:account, name: 'BCI', user: user) 
     user.accounts.length.should == 2 
     user.delete :destroy 
     user_accounts = Account.where(user_id: user.id) 
     user_accounts.should be_nil 
     end 
    end 
    end 
end 

편집 : 내가 구체적으로는 약, 조금 수정 한 delete 행. 쐈어.

+0

변경 사항이 잘못되었습니다 ... 사용자 ID 이전에 ':'가 누락되었지만 작동하지 않았습니다 ... 테스트 문제가 아닙니다. 코드 문제입니다. 개발 레일에서 테스트를 복제하기 때문입니다. 콘솔 ... 그리고 작동하지 않았다 – fespinozacast

+0

@fespinozacast 코드를 수정했습니다 제안합니다. –