Skip to content

Commit

Permalink
MONGOID-5790/MONGOID-5791 Fix error caused by loading a referenced cl…
Browse files Browse the repository at this point in the history
…ass prematurely (#5839)

It's such a pleasure to delete dead code...and even more so when the
dead-code is responsible for a bug, simply by existing!
  • Loading branch information
jamis authored Jul 15, 2024
1 parent 971cf67 commit d2fcc26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 0 additions & 6 deletions lib/mongoid/touchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ def touch_callback_statuses
#
# @return [ Symbol ] The method name.
def define_relation_touch_method(name, association)
relation_classes = if association.polymorphic?
association.send(:inverse_association_classes)
else
[ association.relation_class ]
end

method_name = "touch_#{name}_after_create_or_destroy"
association.inverse_class.class_eval do
define_method(method_name) do
Expand Down
14 changes: 14 additions & 0 deletions spec/mongoid/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
)
end

context "when class_name references an unknown class" do
context "when loading" do
it "does not raise an exception" do
expect do
class AssocationSpecModel
include Mongoid::Document

embedded_in :parent, class_name: 'SomethingBogusThatDoesNotExistYet'
end
end.not_to raise_exception
end
end
end

describe "#embedded?" do

let(:person) do
Expand Down

0 comments on commit d2fcc26

Please sign in to comment.