2013-06-14 4 views
0

모의 order을 생성하는 Factory이 있습니다. 공장에서 order을 만들 때 after_create 콜백에 필요한 3 가지 모델을 만들기 위해 공장에서 before_create이 있습니다. 다음 공장 코드 (I이 조금 지저분 실현,하지만 내가 현재 가지고 내 문제를 해결하기 위해 시도) 다음과 같습니다rspec에서 테스트에서 생성 된 팩터를 찾을 수 없습니다.

FactoryGirl.define do 
     factory :order, :class => Spree::Order do 
    # associations: 
    association(:user, :factory => :user) 
    association(:bill_address, :factory => :address) 
    association(:ship_address, :factory => :address) 
    completed_at nil 
    bill_address_id nil 
    ship_address_id nil 
    email '[email protected]' 

    before(:create) do |order| 
     country = Spree::Country.find_by_id(214).blank? ? create(:country, :id => 214) : Spree::Country.find_by_id(214) 
     state = create(:state, :country => country, :country_id => country.id) 
     country.states = [state] 
     FactoryGirl.create(:address, :id => 1072978592,:state => state, :country => country) if Spree::Address.find_by_id(1072978592).blank? 
    end 
    end 
    end 

을하지만, 난 내 테스트를 실행할 때, 내가 점점 계속 다음과 같은 오류가 발생했습니다.

1) Spree::Calculator::DefaultTax#compute when given an order when no line items match the tax category should be 0 
Failure/Error: let!(:order) { create(:order) } 
ActiveRecord::RecordInvalid: 
    Validation failed: Country can't be blank 
# ./spec/models/calculator/default_tax_spec.rb:8:in `block (2 levels) in <top (required)>' 

국가를 비워 둘 수없는 유효성 검사 오류가 발생했습니다. 내가 뭘 잘못하고 있는지 모르겠다. 저는 주소와 주에서 국가를 적절하게 할당하려고합니다.

rspec 2.13.0, 
factory_girl_rails 4.2.1 (factory _girl 4.2.0), 
ruby 1.9.3, 
rails 3.2.13 
spree 1.2.4 
+0

'let (: order) {Spree :: Order.create}'가 느리게로드되어서 문제가 아닌지 확인하기 위해 let let (: order) {Spree :: Order.create }. 또한 이것이 작동하지 않으면 전체 spec 파일과 주소 팩토리를 게시 할 수 있습니다. – fontno

+0

느낌표를 추가하려고 시도했지만 아무 것도하지 않았습니다. – Zyren

+0

네, 죄송합니다. 테스트 환경에서 rails 콘솔을 사용하여 연결을 수동으로 수행하고 재생할 수 있습니다. 어쩌면 당신은 잘못 된 것을 찾을 수 있습니다. 'rails console test' – fontno

답변

0

FactoryGirl 구문의 업데이트로 인해 콜백이 실행되지 않을 수 있습니다. http://robots.thoughtbot.com/post/23039827914/get-your-callbacks-on-with-factory-girl-3-3

보십시오 : 대신

after(:create) 

는 :

after_create 

또한 3.3 전에 뭔가 FactoryGirl의 버전을 다운 그레이드 시도 할 수 있습니다.

+0

늦게 답장을 드려 죄송합니다. 구문이 잘못되었지만 오류가 수정되지 않았습니다. 이후로 몇 가지 업데이트를 수행했으며 현재 다른 오류가 발생하고 있습니다. 현재의 오류를 반영하도록 원래 질문을 업데이트했습니다. – Zyren

관련 문제