Skip to content

Commit

Permalink
add lastUpdated timestamp to all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Mar 19, 2014
1 parent 45a0f16 commit 4388b0b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Module.js
Expand Up @@ -20,6 +20,11 @@ Module = Backbone.Model.extend({
this.viewId = this.config.viewId;
}
this.initialize();
},

set: function () {
this.lastUpdated = new Date().getTime();
Backbone.Model.prototype.set.apply(this, arguments);
}
});

Expand Down
5 changes: 4 additions & 1 deletion lib/View.js
Expand Up @@ -53,8 +53,11 @@ View = Backbone.View.extend({

render: function () {
this.updateHtml();
this.postRender();
},

postRender: function () {},

updateHtml: function () {
var attrs = _.extend({}, _.result(this, 'attributes'), { 'class': _.result(this, 'className') }),
html = !_.isEmpty(this.module.attributes) ? this.renderViewWithData() : this.renderViewWithoutData();
Expand All @@ -74,7 +77,7 @@ View = Backbone.View.extend({
return this.compiledTemplate(_.extend({
id: this.module.id,
title: this.module.title,
lastUpdated: new Date().getTime()
lastUpdated: this.module.lastUpdated
}, this.module.attributes, this.getViewData()));
},

Expand Down
9 changes: 9 additions & 0 deletions test/specs/lib/Module.js
Expand Up @@ -36,4 +36,13 @@ describe('Module', function () {
});
});

describe('set', function () {
it('should add a lastUpdated timestamp', function () {
var module = new Module({}, {}),
now = new Date().getTime();
module.set('test', 'attribute');
expect(module.lastUpdated).to.be.within(now-10, now+10);
});
});

});
2 changes: 2 additions & 0 deletions test/specs/lib/View.js
Expand Up @@ -106,6 +106,7 @@ describe('View', function () {
template: 'json',
title: 'bar',
attributes: { some: 'json', data: 'of', the: 'module' },
lastUpdated: 123,
has: sinon.stub().returns(false)
},
view = new View(module);
Expand All @@ -118,6 +119,7 @@ describe('View', function () {
expect(view.compiledTemplate).to.have.been.calledWithMatch({
id: module.id,
title: module.title,
lastUpdated: 123,
json: JSON.stringify(module.attributes),
some: 'json',
data: 'of',
Expand Down

0 comments on commit 4388b0b

Please sign in to comment.