Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Created January 10, 2017 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwhite/e9299f8db716e9f84dc39344e6801a93 to your computer and use it in GitHub Desktop.
Save jgwhite/e9299f8db716e9f84dc39344e6801a93 to your computer and use it in GitHub Desktop.
/**
* 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');
})
});
/**
* 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
};
/**
* 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