To demonstrate the issue, just make a small change to an existing test case.
Add line expect(widget0.reload.wotsit).not_to be_nil to the first test case in file has_one_spec.rb
describe "widget, reified from a version prior to creation of wotsit" do
it "has a nil wotsit" do
widget = Widget.create(name: "widget_0")
widget.update(name: "widget_1")
widget.create_wotsit(name: "wotsit_0")
widget0 = widget.versions.last.reify(has_one: true)
expect(widget0.wotsit).to be_nil
expect(widget0.reload.wotsit).not_to be_nil
end
end
Run the test, it should still pass, which is correct.
Add dependent: :destroy to has_one :wotsit in class Widget (spec/dummy_app/app/models/widget.rb)
1) PaperTrail widget, reified from a version prior to creation of wotsit has a nil wotsit
Failure/Error: expect(widget0.reload.wotsit).not_to be_nil
expected: not nil
got: nil
# ./spec/paper_trail/associations/has_one_spec.rb:17:in `block (3 levels) in <top (required)>'
Is this a known issue?
On top of my head, I thought of a simple fix by modifying method create_event in reifiers/has_one.rb , but not sure if it is a proper/complete one:
if options[:mark_for_destruction]
model.send(assoc.name).mark_for_destruction if model.send(assoc.name, true)
else
- model.paper_trail.appear_as_new_record do
- model.send "#{assoc.name}=", nil
- end
+ model.association(assoc.name).target = nil
end
end
To demonstrate the issue, just make a small change to an existing test case.
expect(widget0.reload.wotsit).not_to be_nil
to the first test case in filehas_one_spec.rb
Run the test, it should still pass, which is correct.
Add
dependent: :destroy
tohas_one :wotsit
in class Widget (spec/dummy_app/app/models/widget.rb)Is this a known issue?
On top of my head, I thought of a simple fix by modifying method
create_event
inreifiers/has_one.rb
, but not sure if it is a proper/complete one: