fix bugs in the view templates

This commit is contained in:
John Bintz 2011-05-03 16:10:26 -04:00
parent ed9a824c37
commit 5c2e078c02
2 changed files with 8 additions and 5 deletions

View File

@ -1,15 +1,17 @@
var <%= object_name %>View = Backbone.View.extend({
events: {
'click button.save': 'save',
'click button.destroy': 'destroy'
'click button.delete': 'destroy'
},
attributeFields: [],
template: JST['<%= underscore_name %>s/view'],
className: '<%= underscore_name %>',
initialize: function() {
_.bindAll(this, 'render', 'save', 'destroy');
_.bindAll(this, 'render', 'save', 'destroy', 'remove');
this.model.bind('change', this.render);
this.model.bind('remove', this.remove);
this.model.view = this;
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
@ -17,7 +19,7 @@ var <%= object_name %>View = Backbone.View.extend({
return this;
},
save: function() {
this.model.save(this.attributes());
this.model.save(this.attributes(), { success: function(model) { model.view.render(); } });
},
destroy: function() {
if (confirm("Are you sure?")) {

View File

@ -18,10 +18,11 @@ describe('<%= object_name %>View', function() {
beforeEach(function() {
model = new <%= object_name %>({id: 1});
setFixtures('<div id="container" />');
view = new <%= object_name %>View({model: model});
});
it('should render with an update button', function() {
view = new <%= object_name %>View({model: model});
view.render();
expect(view.$('button.save')).toHaveText('Update');
@ -31,7 +32,7 @@ describe('<%= object_name %>View', function() {
spyOn(window, 'confirm').andReturn(true);
spyOn(model, 'destroy');
$('#facility').append(view.el);
$('#container').append(view.el);
view.$('button.delete').trigger('click');
expect(model.destroy).toHaveBeenCalled();