More deprecations to allow us to work on future versions of Ember

This commit is contained in:
Robin Ward 2014-10-07 16:03:51 -04:00
parent 0ab9a0867a
commit 11b52d1334
5 changed files with 24 additions and 21 deletions

View File

@ -473,16 +473,16 @@ Discourse.Composer = Discourse.Model.extend({
});
this.set('composeState', CLOSED);
return Em.Deferred.promise(function(promise) {
return new Ember.RSVP.Promise(function(resolve, reject) {
post.save(function(result) {
post.updateFromPost(result);
composer.clearState();
}, function(error) {
var response = $.parseJSON(error.responseText);
if (response && response.errors) {
promise.reject(response.errors[0]);
reject(response.errors[0]);
} else {
promise.reject(I18n.t('generic_error'));
reject(I18n.t('generic_error'));
}
post.set('cooked', oldCooked);
composer.set('composeState', OPEN);
@ -550,7 +550,7 @@ Discourse.Composer = Discourse.Model.extend({
}
var composer = this;
return Em.Deferred.promise(function(promise) {
return new Ember.RSVP.Promise(function(resolve, reject) {
composer.set('composeState', SAVING);
createdPost.save(function(result) {
@ -584,7 +584,7 @@ Discourse.Composer = Discourse.Model.extend({
composer.set('composeState', SAVING);
}
return promise.resolve({ post: result });
return resolve({ post: result });
}, function(error) {
// If an error occurs
if (postStream) {
@ -605,7 +605,7 @@ Discourse.Composer = Discourse.Model.extend({
catch(ex) {
parsedError = "Unknown error saving post, try again. Error: " + error.status + " " + error.statusText;
}
promise.reject(parsedError);
reject(parsedError);
});
});
},

View File

@ -15,6 +15,10 @@ function response(code, obj) {
return [code, {"Content-Type": "application/json"}, obj];
}
function success() {
return response();
}
export default function() {
var server = new Pretender(function() {
@ -77,6 +81,9 @@ export default function() {
this.get('/login.html', function() {
return [200, {}, 'LOGIN PAGE'];
});
this.delete('/posts/:post_id', success);
this.put('/posts/:post_id/recover', success);
});

View File

@ -158,8 +158,8 @@ test('editingFirstPost', function() {
asyncTestDiscourse('importQuote with a post', function() {
expect(1);
sandbox.stub(Discourse.Post, 'load').withArgs(123).returns(Em.Deferred.promise(function (p) {
p.resolve(Discourse.Post.create({raw: "let's quote"}));
sandbox.stub(Discourse.Post, 'load').withArgs(123).returns(new Ember.RSVP.Promise(function (resolve) {
resolve(Discourse.Post.create({raw: "let's quote"}));
}));
var composer = Discourse.Composer.create({post: Discourse.Post.create({id: 123})});
@ -172,8 +172,8 @@ asyncTestDiscourse('importQuote with a post', function() {
asyncTestDiscourse('importQuote with no post', function() {
expect(1);
sandbox.stub(Discourse.Post, 'load').withArgs(4).returns(Em.Deferred.promise(function (p) {
p.resolve(Discourse.Post.create({raw: 'quote me'}));
sandbox.stub(Discourse.Post, 'load').withArgs(4).returns(new Ember.RSVP.Promise(function (resolve) {
resolve(Discourse.Post.create({raw: 'quote me'}));
}));
var composer = Discourse.Composer.create({topic: Discourse.Topic.create()});

View File

@ -56,15 +56,13 @@ test('hasHistory', function() {
test('destroy by staff', function() {
var user = Discourse.User.create({username: 'staff', staff: true});
var post = buildPost({user: user});
var user = Discourse.User.create({username: 'staff', staff: true}),
post = buildPost({user: user});
sandbox.stub(Discourse, 'ajax').returns(new Em.Deferred());
post.destroy(user);
present(post.get('deleted_at'), "it has a `deleted_at` field.");
equal(post.get('deleted_by'), user, "it has the user in the `deleted_by` field");
ok(Discourse.ajax.calledOnce, "it made an AJAX call");
post.recover();
blank(post.get('deleted_at'), "it clears `deleted_at` when recovering");
@ -73,16 +71,14 @@ test('destroy by staff', function() {
});
test('destroy by non-staff', function() {
var originalCooked = "this is the original cooked value";
var user = Discourse.User.create({username: 'evil trout'});
var post = buildPost({user: user, cooked: originalCooked});
var originalCooked = "this is the original cooked value",
user = Discourse.User.create({username: 'evil trout'}),
post = buildPost({user: user, cooked: originalCooked});
sandbox.stub(Discourse, 'ajax');
post.destroy(user);
ok(!post.get('can_delete'), "the post can't be deleted again in this session");
ok(post.get('cooked') !== originalCooked, "the cooked content changed");
equal(post.get('version'), 2, "the version number increased");
ok(Discourse.ajax.calledOnce, "it made an AJAX call");
});