Skip to content

Instantly share code, notes, and snippets.

@davetheninja
Created October 13, 2014 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davetheninja/e46b955a2542704e7e46 to your computer and use it in GitHub Desktop.
Save davetheninja/e46b955a2542704e7e46 to your computer and use it in GitHub Desktop.
Daddy needs a tissue for these issues....
"{"presentation":{"title":""}}"
Subject:
Acceptance testing
Whats happening:
1. Test runs
2. I can see the text field being filled
3. It is pressing the save button (I can see a mockjax request to POST)
Whats not happening:
1. The request being sent does not include the title value details
My assumptions:
1. I am a total fool and am doing it wrong
2. fillIn is not doing what I think it should
3. There is some ember voodoo going on that i am missing...
`import Ember from 'ember'`
PresentationsNewRoute = Ember.Route.extend
model: ->
@store.createRecord 'presentation'
actions:
save: ->
route = @
@currentModel.save().then (model) ->
debugger
route.transitionTo 'presentations.show', model
cancel: ->
@transitionTo 'presentations.index'
willTransition: ->
@currentModel.rollback() if @currentModel.get 'isNew'
`export default PresentationsNewRoute`
<form>
<label for='title'>Presentation Title</label>
{{view Ember.TextField valueBinding='title' id='title' }}
<button id='save' {{action 'save'}}>Save</button>
<button {{action 'cancel'}}>Cancel</button>
</form>
`import Ember from 'ember'`
`import startApp from '../../helpers/start-app'`
App = null
module 'Presentations: Creating a presentation',
setup: ->
App = startApp()
teardown: ->
Ember.run App, 'destroy'
test 'I can successfully create a presentation', ->
Ember.$.mockjax
url: '/api/presentations'
type: 'POST',
status: 201,
response: JSON.stringify
presentation:
id: 1,
title: 'Law of Demeter'
visit '/presentations/new'
fillIn 'input#title', 'Law of Demeter'
click 'button#save'
andThen ->
equal currentPath(), 'presentations.show'
equal $('#presentations li:eq(0)').text(), 'Law of Demeter'
Presentations: Creating a presentation: I can successfully create a presentation (2, 0, 2)Rerun817 ms
failed
Expected:
"presentations.show"
Result:
"presentations.new"
Diff:
"presentations.show" "presentations.new"
Source:
at http://localhost:7357/assets/test-support.js:1912:13
at eval (web/tests/acceptance/presentations/create-test.js:36:15)
at andThen (http://localhost:7357/assets/vendor.js:48991:35)
at http://localhost:7357/assets/vendor.js:49698:25
at isolate (http://localhost:7357/assets/vendor.js:49892:15)
at http://localhost:7357/assets/vendor.js:49875:16
failed
Expected:
"Law of Demeter"
Result:
""
Diff:
"Law of Demeter" ""
Source:
at http://localhost:7357/assets/test-support.js:1912:13
at eval (web/tests/acceptance/presentations/create-test.js:37:51)
at andThen (http://localhost:7357/assets/vendor.js:48991:35)
at http://localhost:7357/assets/vendor.js:49698:25
at isolate (http://localhost:7357/assets/vendor.js:49892:15)
at http://localhost:7357/assets/vendor.js:49875:16
@davetheninja
Copy link
Author

Oh and the model

import DS from 'ember-data'

Presentation = DS.Model.extend

title: DS.attr 'string'

presenters: DS.hasMany 'presenter'

export default Presentation

@dagda1
Copy link

dagda1 commented Oct 13, 2014

Hard to say without working code but a couple of points, use the input helper instead of textfield

{{input type="text" value=title}}

Don't override the id in any control like you are doing with id='title'

Use Fixtures instead of mock ajax, look at this jsbin

  1. use the fixture adapter
App.Store = DS.Store.extend({
  adapter: DS.FixtureAdapter.extend({
    simulateRemoteResponse: true,
    latency: 200
  })
});
  1. Create the Fixtures array for your model:
App.Company.FIXTURES = [
  {
    id: 1,
    name: 'Acme Ltd',
    deals: []
  },
  {
    id: 2,
    name: 'Banana Bombs',
    deals: []
  },
  {
    id: 3,
    name: 'Radium',
    deals: []
  },
  {
    id: 4,
    name: 'Continuity2',
    deals: []
  },
  {
    id: 5,
    name: 'Mc Burney & Cowan',
    deals: []
  }
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment