Created
January 10, 2017 11:29
-
-
Save jgwhite/e9299f8db716e9f84dc39344e6801a93 to your computer and use it in GitHub Desktop.
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
/** | |
* app/services/storage.js | |
*/ | |
import Service from 'ember-service'; | |
import computed from 'ember-computed'; | |
import Ember from 'ember'; | |
const { getOwner } = Ember; | |
export default Service.extend({ | |
engine: computed(function() { | |
let owner = getOwner(this); | |
return owner.lookup('engine:storage'); | |
}) | |
}); |
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
/** | |
* app/initializers/storage-engine.js | |
*/ | |
export function initialize(application) { | |
let engine = application.storageEngine || window.localStorage; | |
application.register('engine:storage', engine, { instantiate: false }); | |
} | |
export default { | |
name: 'storage-engine', | |
initialize | |
}; |
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
/** | |
* tests/helpers/module-for-acceptance.js | |
*/ | |
import { module } from 'qunit'; | |
import Ember from 'ember'; | |
import startApp from '../helpers/start-app'; | |
import destroyApp from '../helpers/destroy-app'; | |
import MockStorage from 'my-app/tests/helpers/mocks/storage-engine'; | |
const { RSVP: { Promise } } = Ember; | |
export default function(name, options = {}) { | |
module(name, { | |
beforeEach() { | |
let storageEngine = new MockStorage(); | |
this.application = startApp({ storageEngine }); | |
this.storageEngine = storageEngine; | |
if (options.beforeEach) { | |
return options.beforeEach.apply(this, arguments); | |
} | |
}, | |
afterEach() { | |
let afterEach = options.afterEach && options.afterEach.apply(this, arguments); | |
return Promise.resolve(afterEach).then(() => destroyApp(this.application)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment