Open
Description
I have a has_many
relation defined with dependent: :destroy
like so:
class HostNode
include Mongoid::Document
include Mongoid::Timestamps
has_many :containers, dependent: :destroy
On the other side of the relation, there's a default_scope
defined:
class Container
include Mongoid::Document
include Mongoid::Timestamps
field :deleted_at, type: Time
field :container_type, type: String, default: 'container'
default_scope -> { where(deleted_at: nil, container_type: 'container') }
Now within specs when I delete a HostNode
model all the Containers
are deleted, even those that do NOT match the default_scope. If I do the same operation WITHOUT mongoid-rspec
loaded only the containers matching the default_scope
gets deleted as expected.
This is somewhat un-expected in my opinion. Why does it behave differently when mongoid-rspec
is loaded and is there any way to control this? Tried to look from the code but failed miserably. :D