2015-06-25 25 views
0

我試圖建立一個工廠與authlogic定義的「賬戶」的模式:Authlogic +工廠女孩:驗證失敗:密碼太短(最小爲4個字符)

class Account < UuidEnabled 
    acts_as_authentic do |c| 
    c.validate_password_field = true 
    c.require_password_confirmation = true 
    c.ignore_blank_passwords = false 
    c.crypto_provider = Authlogic::CryptoProviders::Sha512 
    end 
end 

這是我廠:

FactoryGirl.define do 
    factory :account do 
    sequence(:email) { |n| "account_#{n}@example.com"} 
    password = "1234" 
    password_confirmation { |a| a.password} # to make things work even if the password is changed 
    end 
end 

我的測試失敗,

ActiveRecord::RecordInvalid: Validation failed: Password is too short (minimum is 4 characters), Password confirmation is too short (minimum is 4 characters) 

回答

1

認爲這僅僅是一個錯字,請嘗試:

FactoryGirl.define do 
    factory :account do 
    sequence(:email) { |n| "account_#{n}@example.com"} 
    password "1234" 
    password_confirmation { |a| a.password} # to make things work even if the password is changed 
    end 
end 

注意,之後password已被刪除

+0

謝謝!刪除'='解決了這個問題 – Nimo

0

您是否嘗試過在賬戶設置莫attr_accessible :password德爾?

+1

沒了等號,這是因爲以前的答案解決我的問題:) – Nimo