Last active
March 23, 2017 14:56
-
-
Save ultimatemonty/4db6f5e6e7d92b11bceac1a06cfffa09 to your computer and use it in GitHub Desktop.
ember-data async testing issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: attr('string'), | |
sources: hasMany('source', { async: false }) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: attr('string'), | |
nurture: belongsTo('nurture', { async: false }) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RESTSerializer from 'ember-data/serializers/rest'; | |
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; | |
export default RESTSerializer.extend(EmbeddedRecordsMixin, { | |
attrs: { | |
sources: { embedded: 'always' } | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RESTSerializer from 'ember-data/serializers/rest'; | |
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; | |
export default RESTSerializer.extend(EmbeddedRecordsMixin, { | |
attrs: { | |
name: { serialize: false } | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { moduleForModel, test } from 'ember-qunit'; | |
moduleForModel('source', 'Unit | Serializer | source', { | |
beforeEach: function() { | |
this.server = new Pretender(function() { | |
this.get('/sources', function() { | |
let sources = [{ | |
id: 1, | |
name: 'test source', | |
nurture_id: 1 | |
}]; | |
let response = { sources: sources }; | |
return [200, { "Content-Type": "application/json" }, JSON.stringify(response)]; | |
}); | |
this.get('/nurtures/:id', function(request) { | |
let nurture = { | |
id: 1, | |
name: 'test workflow', | |
sources: [{ | |
id: 1, | |
name: 'test source', | |
nurture_id: 1 | |
}] | |
} | |
let response = { nurture: nurture }; | |
return [200, { "Content-Type": "application/json" }, JSON.stringify(response)]; | |
}); | |
}); | |
}, | |
afterEach: function() { | |
this.server.shutdown(); | |
}, | |
needs: [ 'serializer:source', 'model:nurture', 'serializer:nurture'] | |
}); | |
// Replace this with your real tests. | |
test('it exists', function(assert) { | |
let controller = this.subject(); | |
assert.ok(controller); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.9.1", | |
"ember-template-compiler": "2.9.1", | |
"ember-data": "2.11.3", | |
"ember-testing": "2.9.1", | |
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js", | |
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js" | |
}, | |
"addons": { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment