Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5790 MONGOID-5791 Fix error caused by loading a referenced class prematurely #5839

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading