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');
|
||||
},
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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() {
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue