2012-08-27 5 views
6

何が間違っているかを計算するのに2時間かかりましたが、どこでも答えが見つかりませんでした。ユーザモデルのFactoryGirlをDeviseで定義すると失敗する

私の最初のレールアプリケーション(Hartlのチュートリアルを除く)ですので、解決策は簡単かもしれません。私はDeviseを使用してユーザーを管理しています。

FactoryGirl.define do 
    factory :user do 
    email "[email protected]" 
    password "123123" 
    password_confirmation { "123123" } 
    end 
end 

とテストである:

describe User do 
# pending "add some examples to (or delete) #{__FILE__}" 

    @user = FactoryGirl.create(:user) 


    subject(:user) 

    it { should respond_to(:email) } 
    it { should respond_to(:password) } 

    it { should be_valid } 
end 

しかし、最後の行は、(それが{be_validべき})テストに失敗私はこのような工場ユーザ定義モデルをテストしようと

私はuser/@ userの値を印刷しました(両方試しました)、それはnilから出てきました。 編集:これはゼロではありません。その

#<User id: 13, email: "[email protected]", encrypted_password: "$2a$04$.lWs6yadJu/Ya67xi.W1F.fd6sWLGkzc/59.lgTi0sA7...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-08-27 15:48:23", updated_at: "2012-08-27 15:48:23"> 

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

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me 
    # attr_accessible :title, :body 

    validates :email, :presence => true 
    validates :password, :presence => true 
end 

私には見えないものはありますか?

答えて

4

OK、私はついにこの問題を発見しました。 Userモデルに変更を加えたときに "spork"を再起動する必要があることが分かります。

+4

また、http://guides.rubyonrails.org/configuring.htmlの** config/environments/test.rb **のように 'config.cache_classes = false'を設定してみることもできます。変更するたびにスポークします。 – veritas1

関連する問題