factory_bot icon indicating copy to clipboard operation
factory_bot copied to clipboard

Fix build_stubbed timestamps being different

Open kimesf opened this issue 1 year ago • 0 comments

Description

Ensures build_stubbed generates a record with equal created_at and updated_at.

Current behavior

Calling .build_stubbed on factories with entities that have created_at and updated_at assigns a slightly different time for each one of then because the code calls Time.current twice.

Expected behavior

I think the expected behavior should be for them to be exact the same.

Concerns

There are two concerns with the current solution:

  1. We would be calling Time.current even if created_at and updated_at don't exist on the entity;
  2. ~~It might be a problem that we're assigning the same object to both timestamps, should we dup updated_at?~~ (edit: dates are immutable, never mind :grimacing: :face_with_peeking_eye:).

I preferred to ask if these are valid concerns before investigating how to solve them.

kimesf avatar May 22 '24 19:05 kimesf