I have incorporated promise-based code (MyLib
) that needs to execute on every model save by extending the save function:
DS.Model.extend
save: ->
parentSave = @_super.bind this, arguments...
deferred = Ember.RSVP.defer()
MyLib.func().then((val) =>
@set 'prop', val
parentSave()
.then(deferred.resolve)
.fail(deferred.reject)
)
DS.PromiseObject.create promise: deferred.promise
Please note that the promise returned by MyLib.func()
utilizes an rsvp.js promise instead of an Ember.RSVP promise.
Although this solution appears to be effective in practice, certain test cases are failing with the error message
You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run
.
Even after attempting to encapsulate the @set
and parentSave
calls within Ember.run
, I am still encountering asynchronous issues during testing.
Thus, my inquiry is centered around how to extend the save function with asynchronous code while ensuring compatibility with testing procedures?