2011-08-11 10 views
0

RSpec 및 팩토리 걸을 사용하여 작성 될 때 after_create에 'hours'레코드가 자동으로 생성 된 레코드가 생성됩니다.팩토리 걸 공장에서 레코드 업데이트

하지만 기본 시간 이외의 시간 (공장의 소녀 공장에서 정의한 시간)으로 테스트하고 싶습니다. 다음은 내가하고 싶은 생각입니다.

before (:all) do 
    @business = Factory(:business_one) 
    # when that business is saved, a set of default hours is automatically saved as well 
    # how would I now update the hours with fixtures? 
    # so, ideally something like: 
    @business.hours[0] << Factory(:day_one) 
    @business.hours[1] << Factory(:day_two) 
    ...etc... 
    end 

어떻게 든이 행마가 있습니까? 아니면 다르게 접근해야합니까?

대체 공장을 만들 이유

답변

0

이것은 당신이 무엇을 할 수있다 .

2

: 그들은 여전히 ​​삽입하고 새 연결에 밀어 순서대로 저장됩니다

@business = Factory(:business_one) 

# clear associations so it's in a known state 
@business.hours.clear 

@business.hours << Factory(:day_one) 
@business.hours << Factory(:day_two) 

:

Factory.define :business_with_altnernate_hours, :parent => :business_one do 
    after_create do |business| 
    business.hours.clear 
    Factory.create(:day_one, :business => business) 
    Factory.create(:day_two, :business => business) 
    end 
end 
관련 문제