rom-rb / rom-factory

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

Fix building associations #47

Closed psparrow closed 4 years ago

psparrow commented 4 years ago

With the addition of ROM::Factory::UnknownFactoryAttributes, it has become apparent that attributes passed to structs are also passed into their many-to-one associations. This PR addresses the issue and tests that it does not cause errors for one-to-one, one-to-many, or many-to-one 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"
solnic commented 4 years ago

@ianks I just released 0.9.1, thanks for helping with this!