Skip to content

Inconsistent behaviour of Factory.structs between v0.11 and v0.12 #88

@ishando

Description

@ishando

Describe the bug

IDs are not created for associations in v0.12 as they were in v0.11

To Reproduce

with Factories:

Factory.define(:operator) do |f|
  f.id { SecureRandom.uuid }
  f.name 'Some Operator'
  f.created_at { Date.today.prev_month }
  ...
end

Factory.define(:membership) do |f|
  f.id { SecureRandom.uuid }
  f.customer_id { SecureRandom.uuid }
  f.created_at { Date.today.prev_month }
  f.status 'active'
  f.association(:operator)
  ...
end

def build(name, **args)
  Factory.structs[name, **args]
end

and called in rspec tests with

  let(:membership) { build(:membership) }

Expected behavior

in v0.11 it returned:

membership: #<ROM::Struct::Membership
  id="8e2225df-a2bb-4305-b949-67587bd4c949"
  customer_id="f2e10f3c-52cc-43fe-9958-6a17255208fb"
  created_at=#<Date: 2024-03-05 ((2460375j,0s,0n),+0s,2299161j)>
  status="active"
  operator_id="93f53cca-603f-41b3-bb67-e2f3fa8b6fc3"
  operator=#<ROM::Struct::Operator
    id="93f53cca-603f-41b3-bb67-e2f3fa8b6fc3"
    name="Some Operator"
    created_at=#<Date: 2024-03-05 ((2460375j,0s,0n),+0s,2299161j)>
    ...
  >
  ...
>

in v0.12 it returns:

membership: #<ROM::Struct::Membership
  id="8e2225df-a2bb-4305-b949-67587bd4c949"
  customer_id="f2e10f3c-52cc-43fe-9958-6a17255208fb"
  created_at=#<Date: 2024-03-05 ((2460375j,0s,0n),+0s,2299161j)>
  status="active"
  operator_id=nil
  operator=#<ROM::Struct::Operator
    id=nil
    name="Some Operator"
    created_at=#<Date: 2024-03-05 ((2460375j,0s,0n),+0s,2299161j)>
    ...
  >
  ...

I would have expected the same result as in v0.11

My environment

  • Affects my production application: NO, currently only using factory for tests
  • Ruby version: 2.7.7, and 3.2.2
  • OS: linux/alpine

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions