backbone-generator/templates/view_spec.coffee.erb

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2011-05-09 02:44:21 +00:00
describe '<%= object_name %>View', ->
view = model = null
describe 'new record', ->
beforeEach ->
model = new <%= object_name %>
it 'should render with a create button', ->
view = new <%= object_name %>View({model: model})
2011-05-09 11:35:37 +00:00
view.render()
2011-05-09 02:44:21 +00:00
expect(view.$('button.save')).toHaveText('Create')
describe 'existing record', ->
beforeEach ->
model = new <%= object_name %>({id: 1})
setFixtures('<div id="container" />')
view = new <%= object_name %>View({model: model})
it 'should render with an update button', ->
2011-05-09 11:35:37 +00:00
view.render()
2011-05-09 02:44:21 +00:00
expect(view.$('button.save')).toHaveText('Update')
it 'should destroy the model', ->
spyOn(window, 'confirm').andReturn(true)
2011-05-09 11:35:37 +00:00
spyOn(model, 'destroy')
2011-05-09 02:44:21 +00:00
$('#container').append(view.el)
view.$('button.delete').trigger('click')
2011-05-13 14:06:44 +00:00
expect(model.destroy).toHaveBeenCalled()
expect(window.confirm).toHaveBeenCalled()
2011-05-09 02:44:21 +00:00
it 'should remove the view when the model is destroyed', ->
$('#container').append(view.render().el)
2011-05-13 14:06:44 +00:00
expect($('button.save')).toExist()
2011-05-09 02:44:21 +00:00
model.trigger('remove')
2011-05-13 14:06:44 +00:00
expect($('button.save')).not.toExist()
2011-05-09 02:44:21 +00:00