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

Trait and dependent attributes conflicting #70

Open
Rogwzrd opened this issue Sep 8, 2021 · 0 comments
Open

Trait and dependent attributes conflicting #70

Rogwzrd opened this issue Sep 8, 2021 · 0 comments

Comments

@Rogwzrd
Copy link

Rogwzrd commented Sep 8, 2021

Describe the bug

When using the dependent attribute feature of factories there is an unforeseen result. If the method that is being defined is created as a part of the trait and another method uses the dependent attribute feature to access that value the result of said method corresponds with the parent factory object and not the trait. This can be fixed by defining the method value directly in the creation of the factory object. But should also work in the previous statement.

To Reproduce

Factory.define(:store) do |f|
  f.name { fake(:company, :name) }
  f.location_name { |name| "#{name} west" }
end

 f.trait :new_store do |t|
    t.name { 'New Store' }
  end


create :store
result = { name: 'Random Store Name, location_name: 'Random Store Name West'} #Correct

create :store, :new_store
result = { name: 'New Store', location_name: 'Random Store Name West'} # Incorrect

HOWEVER

create :store, :new_store, name: 'Explicit Store Name'
result = { name: 'Explicit Store Name', location_name: 'Explicit Store Name West'} #Correct

Expected behavior

Factory.define(:store) do |f|
  f.name { fake(:company, :name) }
  f.location_name { |name| "#{name} west" }
end

 f.trait :new_store do |t|
    t.name { 'New Store' }
  end


create :store
result = { name: 'Random Store Name, location_name: 'Random Store Name West'}

create :store, :new_store
result = { name: 'New Store', location_name: 'New Store West'}

My environment

  • Affects my production application: YES
  • Ruby version:2.7.4
  • OS: Mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant