Add "complete" callback support for updateShare
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
726c6c73f4
commit
488020cf2e
2 changed files with 55 additions and 0 deletions
|
@ -208,6 +208,10 @@
|
||||||
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
|
url: this._getUrl('shares/' + encodeURIComponent(shareId)),
|
||||||
data: attrs,
|
data: attrs,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
|
}).always(function() {
|
||||||
|
if (_.isFunction(options.complete)) {
|
||||||
|
options.complete(self);
|
||||||
|
}
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
self.fetch({
|
self.fetch({
|
||||||
success: function() {
|
success: function() {
|
||||||
|
|
|
@ -737,6 +737,29 @@ describe('OC.Share.ShareItemModel', function() {
|
||||||
permissions: '' + (OC.PERMISSION_READ | OC.PERMISSION_SHARE)
|
permissions: '' + (OC.PERMISSION_READ | OC.PERMISSION_SHARE)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('calls complete handler before refreshing the model', function() {
|
||||||
|
var completeStub = sinon.stub();
|
||||||
|
model.updateShare(123, {
|
||||||
|
permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
|
||||||
|
}, {
|
||||||
|
complete: completeStub
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fakeServer.requests.length).toEqual(1);
|
||||||
|
fakeServer.requests[0].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({ })
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(completeStub.calledOnce).toEqual(true);
|
||||||
|
expect(completeStub.lastCall.args[0]).toEqual(model);
|
||||||
|
|
||||||
|
fetchReshareDeferred.resolve(makeOcsResponse([]));
|
||||||
|
fetchSharesDeferred.resolve(makeOcsResponse([]));
|
||||||
|
|
||||||
|
expect(completeStub.calledOnce).toEqual(true);
|
||||||
|
});
|
||||||
it('calls success handler after refreshing the model', function() {
|
it('calls success handler after refreshing the model', function() {
|
||||||
var successStub = sinon.stub();
|
var successStub = sinon.stub();
|
||||||
model.updateShare(123, {
|
model.updateShare(123, {
|
||||||
|
@ -760,6 +783,34 @@ describe('OC.Share.ShareItemModel', function() {
|
||||||
expect(successStub.calledOnce).toEqual(true);
|
expect(successStub.calledOnce).toEqual(true);
|
||||||
expect(successStub.lastCall.args[0]).toEqual(model);
|
expect(successStub.lastCall.args[0]).toEqual(model);
|
||||||
});
|
});
|
||||||
|
it('calls complete handler before error handler', function() {
|
||||||
|
var completeStub = sinon.stub();
|
||||||
|
var errorStub = sinon.stub();
|
||||||
|
model.updateShare(123, {
|
||||||
|
permissions: OC.PERMISSION_READ | OC.PERMISSION_SHARE
|
||||||
|
}, {
|
||||||
|
complete: completeStub,
|
||||||
|
error: errorStub
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fakeServer.requests.length).toEqual(1);
|
||||||
|
fakeServer.requests[0].respond(
|
||||||
|
400,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({
|
||||||
|
ocs: {
|
||||||
|
meta: {
|
||||||
|
message: 'Some error message'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(completeStub.calledOnce).toEqual(true);
|
||||||
|
expect(completeStub.lastCall.args[0]).toEqual(model);
|
||||||
|
expect(errorStub.calledOnce).toEqual(true);
|
||||||
|
expect(completeStub.calledBefore(errorStub)).toEqual(true);
|
||||||
|
});
|
||||||
it('calls error handler with error message', function() {
|
it('calls error handler with error message', function() {
|
||||||
var errorStub = sinon.stub();
|
var errorStub = sinon.stub();
|
||||||
model.updateShare(123, {
|
model.updateShare(123, {
|
||||||
|
|
Loading…
Reference in a new issue