-
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.
Try to create a version record when associated object is touched
Before #1285, a version record was created when associated object is touched. But because of Rails don't track implicit touch mutation[1], now PaperTail don't create a version record was created when associated object is touched. This patch try to keep creating a version record in that case by doing checking an event and changed value. Fixes #1339. [1]: rails/rails@dcb8259
- Loading branch information
Showing
5 changed files
with
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Order < ActiveRecord::Base | ||
belongs_to :customer | ||
belongs_to :customer, touch: :touched_at | ||
has_many :line_items | ||
has_paper_trail | ||
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" | ||
|
||
RSpec.describe Order, type: :model, versioning: true do | ||
context "when the record destroyed" do | ||
it "creates a version record for association" do | ||
customer = Customer.create! | ||
described_class.create!(customer: customer) | ||
described_class.destroy_all | ||
|
||
expect(customer.versions.count).to(eq(3)) | ||
end | ||
end | ||
end |