From 2d36c33a80237a58235f519eacf12dcd0f0802d2 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Wed, 12 Apr 2017 11:24:01 -0400 Subject: [PATCH] Testing reify with belongs_to: false Closes #841, hopefully --- README.md | 3 --- test/unit/associations_test.rb | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8e5bb111..f40b3d90 100644 --- a/README.md +++ b/README.md @@ -890,9 +890,6 @@ issues, in order of descending importance. 1. PaperTrail only reifies the first level of associations. 1. [#542](https://github.com/airblade/paper_trail/issues/542) - Not compatible with [transactional tests][34], aka. transactional fixtures. -1. [#841](https://github.com/airblade/paper_trail/issues/841) - - Without a workaround, reified records cannot be persisted if their associated - records have been deleted. 1. Requires database timestamp columns with fractional second precision. - Sqlite and postgres timestamps have fractional second precision by default. [MySQL timestamps do not][35]. Furthermore, MySQL 5.5 and earlier do not diff --git a/test/unit/associations_test.rb b/test/unit/associations_test.rb index ae472642..4b368998 100644 --- a/test/unit/associations_test.rb +++ b/test/unit/associations_test.rb @@ -829,7 +829,7 @@ class AssociationsTest < ActiveSupport::TestCase @widget.destroy end - context "when reified" do + context "when reified with belongs_to: true" do setup { @wotsit2 = @wotsit.versions.last.reify(belongs_to: true) } should "see the associated as it was at the time" do @@ -839,6 +839,22 @@ class AssociationsTest < ActiveSupport::TestCase should "not persist changes to the live association" do assert_nil @wotsit.reload.widget end + + should "be able to persist the reified record" do + assert_nothing_raised { @wotsit2.save! } + end + end + + context "when reified with belongs_to: false" do + setup do + @wotsit2 = @wotsit.versions.last.reify(belongs_to: false) + end + + should "save should not re-create the widget record" do + # Save succeeds because Wotsit does not validate presence of widget + @wotsit2.save! + assert_nil ::Widget.find_by(id: @widget.id) + end end context "and then the model is updated" do