Skip to content

Commit

Permalink
Better implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Jan 31, 2023
1 parent cb926ee commit 7df3fb1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/mongoid/orderable/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def include_mixins
klass.send :include, Mixins::Callbacks
klass.send :include, Mixins::Movable
klass.send :include, Mixins::Listable
klass.send :prepend, Mixins::Changeable
klass.send :prepend, Mixins::Cascadeable if klass.embedded?
end

def generate_all_helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
module Mongoid
module Orderable
module Mixins
# This is required for dirty tracking on embedded objects.
# This is required to trigger callbacks on embedded objects.
# Otherwise, the #move_to parameter won't work when saving the parent.
module Changeable
def changed?
module Cascadeable
def in_callback_state?(kind)
super || move_all.present?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid_orderable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
require 'mongoid/orderable/errors/transaction_failed'
require 'mongoid/orderable/mixins/helpers'
require 'mongoid/orderable/mixins/callbacks'
require 'mongoid/orderable/mixins/changeable'
require 'mongoid/orderable/mixins/listable'
require 'mongoid/orderable/mixins/movable'
require 'mongoid/orderable/mixins/cascadeable'
require 'mongoid/orderable/generators/base'
require 'mongoid/orderable/generators/listable'
require 'mongoid/orderable/generators/lock_collection'
Expand Down
12 changes: 12 additions & 0 deletions spec/integration/cascadeable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe Mongoid::Orderable::Mixins::Cascadeable do

it do
eo = EmbedsOrderable.create!
orderable = eo.embedded_orderables.create!
expect(orderable.in_callback_state?(:update)).to eq false
orderable.move_to = 2
expect(orderable.in_callback_state?(:update)).to eq true
end
end
11 changes: 0 additions & 11 deletions spec/integration/changeable_spec.rb

This file was deleted.

0 comments on commit 7df3fb1

Please sign in to comment.