-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add model option for not synchronizing timestamps (#1416)
* Add model option for not synchronizing timestamps Paper trail automatically synchronizes the version created_at timestamp to be the same as the updated_at timestamp of the record being updated. This pull-requests adds a configurable model-level option to disable this behavior and instead have created_at be populated with the timestamp when the version was inserted into the database. The default remains to synchronize version timestamps * Add test to verify that created_at is not synced
- Loading branch information
Showing
6 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Gizmo < ApplicationRecord | ||
has_paper_trail synchronize_version_creation_timestamp: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "support/performance_helpers" | ||
|
||
RSpec.describe Gizmo, type: :model, versioning: true do | ||
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: Time.current - 1.day) | ||
gizmo.name = "Allen" | ||
gizmo.save(touch: false) | ||
expect(gizmo.versions.last.created_at).not_to(eq(gizmo.updated_at)) | ||
end | ||
end | ||
end |