Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2198

Cancelling around_create callback still firing after_create callbacks

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.5.0
    • Affects Version/s: None
    • Component/s: None
    • None

      When returning false in an around_create callback, this will cancel the document creation as expected. However, after_create callbacks will still be triggered. This behavior does not occur with before_create. Mongoid 2.4.12 and Mongoid 3.0.1 have the same results. Here is the example code:

      class A
        include Mongoid::Document
        before_create { false }
        after_create { p 'not here' }
      end
      
      class B
        include Mongoid::Document
        around_create { false }
        after_create { p 'but here?' }
      end
      
      class Observer < Mongoid::Observer
        observe :a, :b
        def after_create(o); p "#{o.class} - and here?"; end
      end
      
      Mongoid.observers = Observer
      Mongoid.instantiate_observers
      
      a = A.new; p a.save
      b = B.new; p b.save
      

      I would expect the output to be:

      false
      false
      

      Instead, the output is:

      false
      "but here?"
      "B - and here?"
      false
      

      Is this a bug or expected behavior?

            Assignee:
            Unassigned Unassigned
            Reporter:
            jingoro jingoro
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: