make views more useful when created

This commit is contained in:
John Bintz 2011-04-29 15:05:54 -04:00
parent 8fbe5628ff
commit 2919235390
3 changed files with 28 additions and 7 deletions

View File

@ -4,7 +4,8 @@ var <%= object_name %>View = Backbone.View.extend({
_.bindAll(this, 'render');
},
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;
}
});

View File

@ -1 +1,2 @@
<!-- your <%= object_name %>View template goes here -->
<!-- your <%= object_name %>View template fields go here -->
<button />

View File

@ -1,10 +1,29 @@
describe('<%= object_name %>View', function() {
var view;
var view, model;
it('should render', function() {
view = new <%= object_name %>View();
describe('new record', function() {
beforeEach(function() {
model = new <%= object_name %>();
});
it('should render with a create button', function() {
view = new <%= object_name %>View({model: model});
view.render();
expect($(view.el)).toContain('.something');
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');
});
});
});