diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc7c9c6..e255068e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Added -- None +- [#1349](https://github.com/paper-trail-gem/paper_trail/pull/1349) - + `if:` and `unless:` work with `touch` events now. ### Fixed diff --git a/lib/paper_trail/model_config.rb b/lib/paper_trail/model_config.rb index 20e6e862..41bbcbca 100644 --- a/lib/paper_trail/model_config.rb +++ b/lib/paper_trail/model_config.rb @@ -91,11 +91,13 @@ def on_update # @api public def on_touch @model_class.after_touch { |r| - r.paper_trail.record_update( - force: RAILS_LT_6_0, - in_after_callback: true, - is_touch: true - ) + if r.paper_trail.save_version? + r.paper_trail.record_update( + force: RAILS_LT_6_0, + in_after_callback: true, + is_touch: true + ) + end } end diff --git a/spec/models/translation_spec.rb b/spec/models/translation_spec.rb index 51413d5d..3f3cf891 100644 --- a/spec/models/translation_spec.rb +++ b/spec/models/translation_spec.rb @@ -24,6 +24,14 @@ expect(PaperTrail::Version.count).to(eq(0)) end end + + context "when after touch" do + it "not change the number of versions" do + translation = described_class.create!(headline: "Headline") + translation.touch + expect(PaperTrail::Version.count).to(eq(0)) + end + end end context "with US translations" do @@ -44,6 +52,15 @@ translation.update(content: "Content") expect(PaperTrail::Version.count).to(eq(0)) end + + it "touch does not change the number of versions" do + translation = described_class.new(headline: "Headline") + translation.language_code = "US" + translation.type = "DRAFT" + translation.save! + translation.touch + expect(PaperTrail::Version.count).to(eq(0)) + end end context "with non-drafts" do @@ -52,14 +69,21 @@ expect(PaperTrail::Version.count).to(eq(1)) end - it "update does not change the number of versions" do + it "update changes the number of versions" do translation = described_class.create!(headline: "Headline", language_code: "US") translation.update(content: "Content") expect(PaperTrail::Version.count).to(eq(2)) expect(translation.versions.size).to(eq(2)) end - it "destroy does not change the number of versions" do + it "touch changes the number of versions" do + translation = described_class.create!(headline: "Headline", language_code: "US") + translation.touch + expect(PaperTrail::Version.count).to(eq(2)) + expect(translation.versions.size).to(eq(2)) + end + + it "destroy changes the number of versions" do translation = described_class.new(headline: "Headline") translation.language_code = "US" translation.save!