Skip to content

Commit

Permalink
Spec for the case a user incorrectly defines an around callback witho…
Browse files Browse the repository at this point in the history
…ut a yield
  • Loading branch information
adviti-mishra committed Jul 18, 2024
1 parent 16c9c00 commit 1732a2c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/mongoid/interceptable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2594,4 +2594,37 @@ class TestClass
end
end
end

context "when around callbacks for embedded children are enabled" do
config_override :around_callbacks_for_embeds, true

context "when around callback is defined without a yield" do
class Foo
include Mongoid::Document
embeds_many :bars, cascade_callbacks: true
end

class Bar
include Mongoid::Document
embedded_in :foo
field :flag_around_save, type: String
around_save :log_callback

private

def log_callback
flag_around_save = true
end
end

foo = Foo.create
2.times { foo.bars.build }

it "raises an InvalidAroundCallback error" do
expect do
foo.save
end.to raise_error(Mongoid::Errors::InvalidAroundCallback)
end
end
end
end

0 comments on commit 1732a2c

Please sign in to comment.