0
Ruby on Rails 3.1.0, rspec-rails 2
및 Factory
보석을 사용하고 있습니다. Account
클래스의 Factory 객체를 선언 할 때 유효성 검사 프로세스와 관련된 몇 가지 문제가 있습니다. 모델 파일에서 팩토리 객체 초기화시 문제가 발생했습니다
class Account < ActiveRecord::Base
belongs_to :user
attr_accessible :name, ..., :password
validates :name,
:presence => true
...
validates :password,
:presence => true
end
내가 가진 :
FactoryGirl.define do
factory :account, do
sequence(:name) { |n| "Foo #{n}"}
...
password 'psw_secret'
association :user
end
factory :user do
auth 'registered'
end
end
사양 파일에 나는 예상대로 작동 let!(:account) { Factory(:account) }
을 명시하지만 사용할 때 다음과 같은 경우 :
let!(:user) { Factory(:user, :account => Factory(:account)) }
는이 오류를 얻을 :
,536,
Failure/Error: let!(:user) { Factory(:user, :account => Factory(:account)) }
ActiveRecord::RecordInvalid:
Validation failed: Account password can not be blank, Account is invalid
왜 그 오류가 발생합니까? 문제를 어떻게 해결할 수 있습니까?
': user' 팩토리로 업데이트 할 수 있습니까? – nowk
@kwon - 질문을 업데이트했습니다. – user12882