Throw exception if no templateName gets provided but allow setting templateName to false explicitly
closes #6877
This commit is contained in:
parent
3ae3bfe520
commit
898c3d404f
4 changed files with 37 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
## Refactor
|
## Refactor
|
||||||
|
|
||||||
* Removed the publisher from a user's photo stream due to various issues [#6851](https://github.com/diaspora/diaspora/pull/6851)
|
* Removed the publisher from a user's photo stream due to various issues [#6851](https://github.com/diaspora/diaspora/pull/6851)
|
||||||
|
* Don't implicitly ignore missing templateName in app.views.Base [#6877](https://github.com/diaspora/diaspora/pull/6877)
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
||||||
|
|
||||||
app.pages.Profile = app.views.Base.extend({
|
app.pages.Profile = app.views.Base.extend({
|
||||||
|
templateName: false,
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'click #block_user_button': 'blockPerson',
|
'click #block_user_button': 'blockPerson',
|
||||||
'click #unblock_user_button': 'unblockPerson'
|
'click #unblock_user_button': 'unblockPerson'
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,19 @@ app.views.Base = Backbone.View.extend({
|
||||||
renderTemplate : function(){
|
renderTemplate : function(){
|
||||||
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter;
|
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter;
|
||||||
this.template = HandlebarsTemplates[this.templateName+"_tpl"];
|
this.template = HandlebarsTemplates[this.templateName+"_tpl"];
|
||||||
if(!this.template) {
|
|
||||||
console.log(this.templateName ? ("no template for " + this.templateName) : "no templateName specified");
|
if (this.templateName === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.templateName) {
|
||||||
|
throw new Error("No templateName set, set to false to ignore.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.template) {
|
||||||
|
throw new Error("Invalid templateName provided: " + this.templateName);
|
||||||
|
}
|
||||||
|
|
||||||
this.$el
|
this.$el
|
||||||
.html(this.template(presenter))
|
.html(this.template(presenter))
|
||||||
.attr("data-template", _.last(this.templateName.split("/")));
|
.attr("data-template", _.last(this.templateName.split("/")));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,30 @@ describe("app.views.Base", function(){
|
||||||
this.view.render();
|
this.view.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("throws an exception if no templateName was provided", function() {
|
||||||
|
expect(function() {
|
||||||
|
new app.views.Base().render();
|
||||||
|
}).toThrow(new Error("No templateName set, set to false to ignore."));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not throw an exception if templateName is set to false", function() {
|
||||||
|
var ViewClass = app.views.Base.extend({
|
||||||
|
templateName: false
|
||||||
|
});
|
||||||
|
|
||||||
|
new ViewClass().render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws an exception if an invalid templateName was provided", function() {
|
||||||
|
expect(function() {
|
||||||
|
var ViewClass = app.views.Base.extend({
|
||||||
|
templateName: "noiamnotavalidtemplate"
|
||||||
|
});
|
||||||
|
|
||||||
|
new ViewClass().render();
|
||||||
|
}).toThrow(new Error("Invalid templateName provided: noiamnotavalidtemplate"));
|
||||||
|
});
|
||||||
|
|
||||||
it("renders the template with the presenter", function(){
|
it("renders the template with the presenter", function(){
|
||||||
expect($(this.view.el).text().trim()).toBe("model attributes are in the default presenter");
|
expect($(this.view.el).text().trim()).toBe("model attributes are in the default presenter");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue