Skip to content

Commit

Permalink
Add test to verify that created_at is not synced
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRollen committed Jan 19, 2023
1 parent 7ae987b commit c098f51
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/dummy_app/app/models/gizmo.rb
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Starting with AR 5.1, we must specify which version of AR we are using.
# I tried using `const_get` but I got a `NameError`, then I learned about
# `::ActiveRecord::Migration::Current`.
class SetUpTestTables < ::ActiveRecord::Migration::Current
class SetUpTestTables < ActiveRecord::Migration::Current
MYSQL_ADAPTERS = [
"ActiveRecord::ConnectionAdapters::MysqlAdapter",
"ActiveRecord::ConnectionAdapters::Mysql2Adapter"
Expand Down Expand Up @@ -48,6 +48,11 @@ def up
t.timestamps null: true, limit: 6
end

create_table :gizmos, force: true do |t|
t.string :name
t.timestamps null: true, limit: 6
end

create_table :widgets, force: true do |t|
t.string :name
t.text :a_text
Expand Down
15 changes: 15 additions & 0 deletions spec/models/gizmo_spec.rb
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

0 comments on commit c098f51

Please sign in to comment.