Skip to content

Commit

Permalink
Remove load_target for PaperTrail::Model#record_destroy
Browse files Browse the repository at this point in the history
With this line, when object destroyed and version was createdPaper Trail load associated version. It's bring
useless query to DB.
  • Loading branch information
sedx committed May 18, 2016
1 parent a184c37 commit 2dd4ce8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ def record_destroy
end
version = self.class.paper_trail_version_class.create(merge_metadata(data))
send("#{self.class.version_association_name}=", version)
send(self.class.versions_association_name).send :load_target
update_transaction_id(version)
save_associations(version)
end
Expand Down
16 changes: 16 additions & 0 deletions test/paper_trail_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,20 @@ class PaperTrailTest < ActiveSupport::TestCase
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
assert_equal 2, versions_for_widget.length
end

context "destroy" do
setup do
@widget = Widget.create
association = @widget.send(@widget.class.versions_association_name)
association.define_singleton_method(:load_target) do
raise "#{association.class}#load_traget was called"
end
end

should 'not call PaperTrail::Version::ActiveRecord_Associations_CollectionProxy#load_target' do
assert_nothing_raised do
@widget.destroy
end
end
end
end

0 comments on commit 2dd4ce8

Please sign in to comment.