Skip to content

Homogenize effects of synchronize_version_creation_timestamp for create event #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/paper_trail/events/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def data
event: @record.paper_trail_event || "create",
whodunnit: PaperTrail.request.whodunnit
}
if @record.respond_to?(:updated_at)
if @record.respond_to?(:updated_at) &&
@record.paper_trail_options[:synchronize_version_creation_timestamp] != false
data[:created_at] = @record.updated_at
end
if record_object_changes? && changed_notably?
Expand Down
2 changes: 2 additions & 0 deletions spec/models/gizmo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
context "with a persisted record" do
it "does not use the gizmo `updated_at` as the version's `created_at`" do
gizmo = described_class.create(name: "Fred", created_at: 1.day.ago)
expect(gizmo.versions.last.created_at).not_to(eq(gizmo.updated_at))

gizmo.name = "Allen"
gizmo.save(touch: false)
expect(gizmo.versions.last.created_at).not_to(eq(gizmo.updated_at))
Expand Down