Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:parent seems to be ignored for nested factory definitions #280

Closed
beverlycodes opened this issue Jan 22, 2012 · 0 comments
Closed

:parent seems to be ignored for nested factory definitions #280

beverlycodes opened this issue Jan 22, 2012 · 0 comments

Comments

@beverlycodes
Copy link

I had an issue where it appeared that callbacks weren't being inherited on my child factories, but after some investigation the issue appears to be that :parent just gets ignored if a factory is defined within another factory block.

FactoryGirl.define do
  factory :event do
    name "My Event"
    occurs_at Date.today

    factory :structured_event do
      after_create do |e|
        e.add_station 'Sales Booth'
      end
    end

    factory :staffed_event, :parent => :structured_event do
      after_create do |e|
        station = e.stations.find_by_name("Sales Booth")
        e.add_worker(FactoryGirl.create(:worker), station)
      end
    end
  end
end

When running my tests, it appears that :staffed_event inherits from :event instead of :structured_event. At the very least, it seems to be missing the callback from :structured_event.

I probably shouldn't be mixing declaration styles like this, but if I choose to do so anyway, I'd expect :parent to be honored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants