Skip to content

Frontend Stage 18 contact edit cancel changes

Wojtek Ryrych edited this page Mar 29, 2014 · 2 revisions

spec/javascripts/integration/contact_edit_spec.js.coffee

describe 'ContactEdit', ->
  # ...

  it 'cancel changes', ->
    visit '/contacts/2/edit'
    andThen ->
      fillIn '#first-name', 'Yehuda'
      fillIn '#last-name', 'Katz'
      click '#cancel-changes'
      andThen ->
        name = find('.contact-heading').text()
        name.should.equal 'Richard Stallman'

app/assets/javascripts/templates/shared/_edit_fields.hbs

  <div class='form-group'>
    <div class='col-lg-offset-2 col-lg-10'>
      <button id='save-contact' class='btn btn-success' {{action 'saveContact' this}}>save</button>
      <button id='cancel-changes' class='btn btn-danger' {{action 'cancelEditing'}}>cancel</button>
    </div>
  </div>

app/assets/javascripts/controllers/contact_edit_controller.js.coffee

AddressBook.ContactEditController = Em.ObjectController.extend
  actions:
    cancelEditing: ->
      contact = @get 'model'
      contact.rollback()
      @transitionToRoute 'contact', contact
Clone this wiki locally