Authlogic + Factory Girl: Validation failed: Password is too short (minimum is 4 characters)

549 views Asked by At

I'm trying to build a factory for an "account" model defined with authlogic:

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

This is my factory:

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

My test fails with

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

There are 2 answers

0
Slicedpan On BEST ANSWER

Think this is just a typo, try:

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

Note that the equals sign after password has been removed

1
nesiseka On

Have you tried setting attr_accessible :password in the Account model?