make views more useful when created
This commit is contained in:
parent
8fbe5628ff
commit
2919235390
|
@ -4,7 +4,8 @@ var <%= object_name %>View = Backbone.View.extend({
|
||||||
_.bindAll(this, 'render');
|
_.bindAll(this, 'render');
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
$(this.el).html(this.template());
|
$(this.el).html(this.template(this.model.toJSON()));
|
||||||
|
this.$('button').text(this.model.isNew() ? 'Create' : 'Update');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
<!-- your <%= object_name %>View template goes here -->
|
<!-- your <%= object_name %>View template fields go here -->
|
||||||
|
<button />
|
||||||
|
|
|
@ -1,10 +1,29 @@
|
||||||
describe('<%= object_name %>View', function() {
|
describe('<%= object_name %>View', function() {
|
||||||
var view;
|
var view, model;
|
||||||
|
|
||||||
it('should render', function() {
|
describe('new record', function() {
|
||||||
view = new <%= object_name %>View();
|
beforeEach(function() {
|
||||||
view.render();
|
model = new <%= object_name %>();
|
||||||
|
});
|
||||||
|
|
||||||
expect($(view.el)).toContain('.something');
|
it('should render with a create button', function() {
|
||||||
|
view = new <%= object_name %>View({model: model});
|
||||||
|
view.render();
|
||||||
|
|
||||||
|
expect(view.$('button')).toHaveText('Create');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('existing record', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
model = new <%= object_name %>({id: 1});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render with an update button', function() {
|
||||||
|
view = new <%= object_name %>View({model: model});
|
||||||
|
view.render();
|
||||||
|
|
||||||
|
expect(view.$('button')).toHaveText('Update');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue