mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
Merge pull request #5471 from kowsheek/5370-settings-model-events
Add events to settings model
This commit is contained in:
commit
b3f4beade8
@ -59,12 +59,15 @@ Settings = ghostBookshelf.Model.extend({
|
||||
|
||||
this.on('created', function (model) {
|
||||
model.emitChange('added');
|
||||
model.emitChange(model.attributes.key + '.' + 'added');
|
||||
});
|
||||
this.on('updated', function (model) {
|
||||
model.emitChange('edited');
|
||||
model.emitChange(model.attributes.key + '.' + 'edited');
|
||||
});
|
||||
this.on('destroyed', function (model) {
|
||||
model.emitChange('deleted');
|
||||
model.emitChange(model.attributes.key + '.' + 'deleted');
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -80,8 +80,9 @@ describe('Settings Model', function () {
|
||||
edited.attributes.key.should.equal('description');
|
||||
edited.attributes.value.should.equal('new value');
|
||||
|
||||
eventSpy.calledOnce.should.be.true;
|
||||
eventSpy.calledWith('settings.edited').should.be.true;
|
||||
eventSpy.calledTwice.should.be.true;
|
||||
eventSpy.firstCall.calledWith('settings.edited').should.be.true;
|
||||
eventSpy.secondCall.calledWith('settings.description.edited').should.be.true;
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
@ -116,8 +117,11 @@ describe('Settings Model', function () {
|
||||
editedModel.attributes.key.should.equal(model2.key);
|
||||
editedModel.attributes.value.should.equal(model2.value);
|
||||
|
||||
eventSpy.calledTwice.should.be.true;
|
||||
eventSpy.calledWith('settings.edited').should.be.true;
|
||||
eventSpy.callCount.should.equal(4);
|
||||
eventSpy.getCall(0).calledWith('settings.edited').should.be.true;
|
||||
eventSpy.getCall(1).calledWith('settings.description.edited').should.be.true;
|
||||
eventSpy.getCall(2).calledWith('settings.edited').should.be.true;
|
||||
eventSpy.getCall(3).calledWith('settings.title.edited').should.be.true;
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
@ -136,8 +140,9 @@ describe('Settings Model', function () {
|
||||
createdSetting.attributes.value.should.equal(newSetting.value, 'value is correct');
|
||||
createdSetting.attributes.type.should.equal('core');
|
||||
|
||||
eventSpy.calledOnce.should.be.true;
|
||||
eventSpy.calledWith('settings.added').should.be.true;
|
||||
eventSpy.calledTwice.should.be.true;
|
||||
eventSpy.firstCall.calledWith('settings.added').should.be.true;
|
||||
eventSpy.secondCall.calledWith('settings.TestSetting1.added').should.be.true;
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
|
Loading…
Reference in New Issue
Block a user