Versioned models should have their version association getter updated upon destruction when applicable
This commit is contained in:
parent
5d9b6b7d3c
commit
c8c37561be
|
@ -6,6 +6,8 @@
|
||||||
for return values from `current_user` method.
|
for return values from `current_user` method.
|
||||||
- `PaperTrail::Cleaner.clean_versions!` should group versions by `PaperTrail.timestamp_field` when deciding which ones to
|
- `PaperTrail::Cleaner.clean_versions!` should group versions by `PaperTrail.timestamp_field` when deciding which ones to
|
||||||
keep / destroy, instead of always grouping by the `created_at` field.
|
keep / destroy, instead of always grouping by the `created_at` field.
|
||||||
|
- If `destroy` actions are tracked for a versioned model, invoking `destroy` on the model will cause the corresponding version that
|
||||||
|
gets generated to be assigned into the `model_instance#version_association_name` accessor (usally `model_instance#version`).
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ module PaperTrail
|
||||||
:object => self.class.paper_trail_version_class.object_col_is_json? ? object_attrs : PaperTrail.serializer.dump(object_attrs),
|
:object => self.class.paper_trail_version_class.object_col_is_json? ? object_attrs : PaperTrail.serializer.dump(object_attrs),
|
||||||
:whodunnit => PaperTrail.whodunnit
|
:whodunnit => PaperTrail.whodunnit
|
||||||
}
|
}
|
||||||
self.class.paper_trail_version_class.create merge_metadata(data)
|
send("#{self.class.version_association_name}=", self.class.paper_trail_version_class.create(merge_metadata(data)))
|
||||||
send(self.class.versions_association_name).send :load_target
|
send(self.class.versions_association_name).send :load_target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,21 @@ describe Widget do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Callbacks", :versioning => true do
|
||||||
|
describe :after_destroy do
|
||||||
|
it "should create a version for that event" do
|
||||||
|
expect { widget.destroy }.to change(widget.versions, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should assign the version into the `versions_association_name`" do
|
||||||
|
widget.version.should be_nil
|
||||||
|
widget.destroy
|
||||||
|
widget.version.should_not be_nil
|
||||||
|
widget.version.should == widget.versions.last
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "Methods" do
|
describe "Methods" do
|
||||||
describe "Instance", :versioning => true do
|
describe "Instance", :versioning => true do
|
||||||
describe :whodunnit do
|
describe :whodunnit do
|
||||||
|
|
Loading…
Reference in New Issue