I've been trying to get a factory to refer back to an AR relation set by
another created factory. I've asked around and come up short so thought I'd
throw it out to the list.
Trying to test a bit of accounting business logic and setting an employee
with a supervisor (which is a self-referential relation employees are
supervised by another employee) who then makes a request which needs to get
approved by that employee's supervisor (like leave, pd, etc). It may just
be a syntax thing, but keep getting AR:AssociationTypeMismatch errors... to
wit:
factory :pd_request do
association :employee, :factory => :employee_with_supervisor
description { Faker::Lorem.words.join(' ') }
start_date 7.days.from_now
factory :pd_request_approved do |pd_request|
*association :approving_supervisor, :factory => :employee *
association :approving_manager, :factory => :employee
name "Lorem ipsum..."
status "Approved"
end
end
Basically, the current situation is using a *random new* supervisor for
this test, but trying to fix this properly and test the functionality
properly, the approved request should be set to the
employee_with_supervisor's supervisor. So, in the factory
pd_request_approved, whatever the syntactical equivalent of
pd_request.employee.supervisor would be to set that association.
I've run this by two way-better-at-FG-than-I people without luck and after
trying some "this ought to work" thrashing, so think I'm eiher getting into
over-my-head syntax territory or it's out of bounds for FG.
Anyone seen or had a similar issue before?
thanks!
Daryl.
PS> In case you need to know how the employee with supervisor factory is
set...
factory :employee do
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.email }
...
factory :employee_with_supervisor do
association :supervisor, :factory => :employee
end
end
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.