Testing reify with belongs_to: false

Closes #841, hopefully
This commit is contained in:
Jared Beck 2017-04-12 11:24:01 -04:00
parent 823d74a919
commit 2d36c33a80
2 changed files with 17 additions and 4 deletions

View File

@ -890,9 +890,6 @@ issues, in order of descending importance.
1. PaperTrail only reifies the first level of associations. 1. PaperTrail only reifies the first level of associations.
1. [#542](https://github.com/airblade/paper_trail/issues/542) - 1. [#542](https://github.com/airblade/paper_trail/issues/542) -
Not compatible with [transactional tests][34], aka. transactional fixtures. 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. 1. Requires database timestamp columns with fractional second precision.
- Sqlite and postgres timestamps have fractional second precision by default. - Sqlite and postgres timestamps have fractional second precision by default.
[MySQL timestamps do not][35]. Furthermore, MySQL 5.5 and earlier do not [MySQL timestamps do not][35]. Furthermore, MySQL 5.5 and earlier do not

View File

@ -829,7 +829,7 @@ class AssociationsTest < ActiveSupport::TestCase
@widget.destroy @widget.destroy
end end
context "when reified" do context "when reified with belongs_to: true" do
setup { @wotsit2 = @wotsit.versions.last.reify(belongs_to: true) } setup { @wotsit2 = @wotsit.versions.last.reify(belongs_to: true) }
should "see the associated as it was at the time" do 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 should "not persist changes to the live association" do
assert_nil @wotsit.reload.widget assert_nil @wotsit.reload.widget
end 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 end
context "and then the model is updated" do context "and then the model is updated" do