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

can't use inherited associations in Cucumber steps #292

Closed
eostrom opened this issue Feb 7, 2012 · 1 comment
Closed

can't use inherited associations in Cucumber steps #292

eostrom opened this issue Feb 7, 2012 · 1 comment

Comments

@eostrom
Copy link
Contributor

eostrom commented Feb 7, 2012

This broke somewhere between factory_girl 2.1.0 and 2.5.1.

Given a simplified set of factories (for illustration; I haven't built an executable test case):

class User < ActiveRecord::Base
end

class Profile < ActiveRecord::Base
  belongs_to :user
end

FactoryGirl.define do
  factory :user do
    email ''
  end

  factory :profile do
    user
  end

  factory :published_profile, :parent => :profile do
    published true
  end
end

A step like this used to work:

Given the following published profile exists:
    | User                    |
    | email: user@example.com |

Now it raises an exception: User(#2193859180) expected, got String(#2151988680) (ActiveRecord::AssociationTypeMismatch)

I've tracked the problem as far as lib/factory_girl/step_definitions.rb:

        attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations)

factory.associations returns an empty array. If we define the user association directly in the :published_profile factory, the step succeeds - but I'd rather inherit it from :profile.

I'd be happy to work on a patch, but I'm not sure what the expected behavior should be. Should factory.associations include inherited associations? Should the step definition be calling a different method?

@joshuaclayton
Copy link
Contributor

@eostrom IIRC factory#associations is only used by the step definitions, so it should be fine to change it there. I think it makes sense for the factory to calculate associations based on its inherited factories

connorchris831 pushed a commit to connorchris831/factory_bot that referenced this issue Dec 13, 2022
By making Factory#associations include the parent's associations.

thoughtbot/factory_bot#292
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

Successfully merging a pull request may close this issue.

2 participants