Last active
August 29, 2015 14:03
-
-
Save jakecraige/310a8933f7f962bbe8e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import icAjax from 'ic-ajax'; | |
// ... | |
authenticate: function() { | |
var request = icAjax(this.get('createSessionUrl'), { | |
method: 'POST', | |
dataType: 'json', | |
data: JSON.stringify(data), | |
contentType: 'application/json' | |
}); | |
var session = this; | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
request.then(function(userData){ | |
session.save(userData); | |
session.setPrefilter(); | |
resolve(userData); | |
}, function(err){ | |
console.log('Authentication error: ', err); | |
reject(err); | |
}); | |
}); | |
} | |
// test | |
session.authenticate('[email protected]', 'password').then(function() {}, function() { | |
// If I don't wrap the ic-ajax request in RSVP.Promise, it will always resolve successfully | |
// when I chain something on to it, even though internally it's rejected. | |
// (I see the console log on LN18) | |
// | |
// When I wrap it, this test passes | |
ok('Promise rejected') | |
start(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment