Skip to content

Commit

Permalink
Merge pull request #952 from airblade/test_reify_belongs_to_false
Browse files Browse the repository at this point in the history
Testing reify with belongs_to: false
  • Loading branch information
jaredbeck authored Apr 12, 2017
2 parents 823d74a + 2d36c33 commit 65f62bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion test/unit/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 65f62bc

Please sign in to comment.