rom-rb / rom-factory

Data generator with support for persistence backends
MIT License
83 stars 42 forks source link

Do not pass attributes when building ManyToOne associations #46

Closed psparrow closed 4 years ago

psparrow commented 4 years ago

With the addition of ROM::Factory::UnknownFactoryAttributes, it has become apparent that attributes provided to structs are being passed into associations. This PR fixes the issue for ManyToOne associations. Here's an example:

factories.define(:task) do |f|
  f.title { 'Foo' }
  f.association(:user)
end

factories.define(:user) do |f|
  f.timestamps
end

Currently, attributes provided to the task struct are being passed into the user association:

factories.structs[:task, title: 'Bar']  #=> ROM::Factory::UnknownFactoryAttributes

This PR makes it possible to build such structs without exceptions:

factories.structs[:task, title: 'Bar'].title  #=> "Bar"
psparrow commented 4 years ago

I'm going to fix similar issues in other association types and re-open this PR. :)