kadoudal
unread,May 15, 2012, 12:52:31 PM5/15/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to factory_girl
I have the following models
class Partner < ActiveRecord::Base
has_many :payment_terms, :dependent => :destroy, :as => :term able
class PaymentTerm < ActiveRecord::Base
belongs_to :termable, :polymorphic => true
I defined the payment_term factory like that :
FactoryGirl.define do
factory :partner_payment_term, :class => PaymentTerm do |ppt|
ppt.sequence(:position) { |n| n }
ppt.label { Faker::Lorem.words(rand(2..4), true).join(' ') }
ppt.term_code {rand(3)}
after_build do |partner_payment_term|
partner_payment_term.termable = Factory(:independent_partner,
area: nil)
end
end
end
and the partner factory like that
FactoryGirl.define do
factory :partner do
...
trait :independent do
area
....
end
factory :independent_partner, traits: [:independent]
end
running : ppt = FactoryGirl.build(:partner_payment_term)
I get the error :
NoMethodError: undefined method `find' for
#<FactoryGirl::Declaration::Implicit:0x007f8f13d894c0>
it's linked to the after_build block, because if I comment it , then I
can build the ppt
ppt = FactoryGirl.build(:partner_payment_term )
=>
#<PaymentTerm id: nil, termable_id: nil, termable_type: nil, position:
1, label: "creator caute spero infit", rate: #<BigDecimal:
7f9322883648,'0.2E2',9(18)>, term_at: nil, term_code: 0, created_at:
nil, updated_at: nil>
what could be wrong with my after_build block ?
thansk for feedback