thoughtbot / factory_bot

A library for setting up Ruby objects as test data.
https://thoughtbot.com
MIT License
7.89k stars 2.6k forks source link

Fix build_stubbed timestamps being different #1653

Open kimesf opened 1 month ago

kimesf commented 1 month ago

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.