describe('<%= object_name %>View', function() { var view, model; 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.$('button.save')).toHaveText('Create'); }); }); describe('existing record', function() { beforeEach(function() { model = new <%= object_name %>({id: 1}); setFixtures('
'); }); it('should render with an update button', function() { view = new <%= object_name %>View({model: model}); view.render(); expect(view.$('button.save')).toHaveText('Update'); }); it('should destroy the model', function() { spyOn(window, 'confirm').andReturn(true); spyOn(model, 'destroy'); $('#facility').append(view.el); view.$('button.delete').trigger('click'); expect(model.destroy).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled(); }); it('should remove the view when the model is destroyed', function() { $('#container').append(view.render().el); expect($('button.save')).toExist(); model.trigger('remove'); expect($('button.save')).not.toExist(); }); }); });