diff --git a/.eslintrc.js b/.eslintrc.js
index 7a025a84..f488b51e 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -14,24 +14,18 @@ module.exports = {
extends: [
'eslint:recommended',
'plugin:ember/recommended',
- // 'plugin:prettier/recommended',
+ 'plugin:prettier/recommended',
],
env: {
- browser: true
+ browser: true,
},
rules: {
'ember/avoid-leaking-state-in-ember-objects': 'off',
- 'ember/no-actions-hash': 'off',
'ember/no-classic-classes': 'off',
- 'ember/no-classic-components': 'off',
- 'ember/no-component-lifecycle-hooks': 'off',
'ember/no-get': 'off',
- 'ember/no-jquery': 'off',
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
'ember/no-string-prototype-extensions': 'off',
- 'ember/require-tagless-components': 'off',
- 'ember/require-super-in-lifecycle-hooks': 'off',
'ember/use-ember-data-rfc-395-imports': 'off',
},
overrides: [
@@ -63,9 +57,7 @@ module.exports = {
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
- 'qunit/no-assert-equal-boolean': 'off',
'qunit/no-conditional-assertions': 'off',
- 'qunit/no-ok-equality': 'off',
},
},
],
diff --git a/.template-lintrc.js b/.template-lintrc.js
index 071cdbc0..aaad20d6 100644
--- a/.template-lintrc.js
+++ b/.template-lintrc.js
@@ -2,20 +2,5 @@
module.exports = {
extends: 'recommended',
- rules: {
- // TODO: Remove over time
- 'link-href-attributes': false,
- 'no-action': false,
- 'no-curly-component-invocation': false,
- 'no-implicit-this': false,
- 'no-inline-styles': false,
- 'no-invalid-interactive': false,
- 'no-link-to-positional-params': false,
- 'no-partial': false,
- 'no-unbalanced-curlies': false,
- 'require-button-type': false,
- 'require-iframe-title': false,
- 'require-input-label': false,
- 'require-valid-alt-text': false,
- },
+ rules: {},
};
diff --git a/addon/adapters/base.js b/addon/adapters/base.js
index 72f744d5..54b19e95 100644
--- a/addon/adapters/base.js
+++ b/addon/adapters/base.js
@@ -9,16 +9,16 @@ import { _buildKey } from '../helpers/storage';
const getKeys = Object.keys || keys;
-const {
- JSONAPIAdapter
-} = DS;
+const { JSONAPIAdapter } = DS;
// Ember data ships with ember-inflector
import { singularize, pluralize } from 'ember-inflector';
export default JSONAPIAdapter.extend(ImportExportMixin, {
_debug: false,
- _indices: computed(function() { return {}; }),
+ _indices: computed(function () {
+ return {};
+ }),
coalesceFindRequests: false,
// TODO: v2.0 - What are the defaults now? What versions to support?
@@ -26,10 +26,18 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
// TODO: v2.0 - Can we deprecate or remove that? What are the defaults now? What versions to support?
// Reload behavior
- shouldReloadRecord() { return true; },
- shouldReloadAll() { return true; },
- shouldBackgroundReloadRecord() { return true; },
- shouldBackgroundReloadAll() { return true; },
+ shouldReloadRecord() {
+ return true;
+ },
+ shouldReloadAll() {
+ return true;
+ },
+ shouldBackgroundReloadRecord() {
+ return true;
+ },
+ shouldBackgroundReloadAll() {
+ return true;
+ },
generateIdForRecord() {
return Math.random().toString(32).slice(2).substr(0, 8);
@@ -37,19 +45,15 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
// Relationship sugar
createRecord(store, type, snapshot) {
- snapshot.eachRelationship(function(name, relationship) {
- const {
- kind,
- options
- } = relationship;
+ snapshot.eachRelationship(function (name, relationship) {
+ const { kind, options } = relationship;
if (kind === 'belongsTo' && options.autoSave) {
- snapshot.record.get(name)
- .then(function(record) {
- if (record) {
- record.save();
- }
- });
+ snapshot.record.get(name).then(function (record) {
+ if (record) {
+ record.save();
+ }
+ });
}
});
@@ -57,28 +61,23 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
},
deleteRecord(store, type, snapshot) {
- snapshot.eachRelationship(function(name, relationship) {
- const {
- kind,
- options
- } = relationship;
+ snapshot.eachRelationship(function (name, relationship) {
+ const { kind, options } = relationship;
if (kind === 'hasMany' && options.dependent === 'destroy') {
- snapshot.record.get(name)
- .then(function(records) {
- records.forEach(function(record) {
- record.destroyRecord();
- });
+ snapshot.record.get(name).then(function (records) {
+ records.forEach(function (record) {
+ record.destroyRecord();
});
+ });
}
if (kind === 'belongsTo' && options.autoSave) {
- snapshot.record.get(name)
- .then(function(record) {
- if (record) {
- record.save();
- }
- });
+ snapshot.record.get(name).then(function (record) {
+ if (record) {
+ record.save();
+ }
+ });
}
});
@@ -100,10 +99,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
records = this.ajax(url, 'GET', { data: query });
}
- return records
- .then(function(result) {
- return {data: result.data[0] || null};
- });
+ return records.then(function (result) {
+ return { data: result.data[0] || null };
+ });
},
// TODO: v2.0 - What are the defaults now? What versions to support?
@@ -114,11 +112,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
// Delegate to _handleStorageRequest
makeRequest(request) {
- return this._handleStorageRequest(
- request.url,
- request.method,
- { data: request.data }
- );
+ return this._handleStorageRequest(request.url, request.method, {
+ data: request.data,
+ });
},
// Work arround ds-improved-ajax Feature Flag
@@ -141,13 +137,9 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
const handler = this[`_handle${type}Request`];
if (handler) {
const data = handler.call(this, url, options.data);
- run(null, resolve, {data: data});
+ run(null, resolve, { data: data });
} else {
- run(
- null,
- reject,
- `There is nothing to handle _handle${type}Request`
- );
+ run(null, reject, `There is nothing to handle _handle${type}Request`);
}
}, 'DS: LocalStorageAdapter#_handleStorageRequest ' + type + ' to ' + url);
},
@@ -159,16 +151,16 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
if (id) {
if (!storage[storageKey]) {
- throw this.handleResponse(404, {}, "Not found", { url, method: 'GET' });
+ throw this.handleResponse(404, {}, 'Not found', { url, method: 'GET' });
}
return JSON.parse(storage[storageKey]);
}
const records = this._getIndex(type)
- .filter(function(storageKey) {
+ .filter(function (storageKey) {
return storage[storageKey];
})
- .map(function(storageKey) {
+ .map(function (storageKey) {
return JSON.parse(storage[storageKey]);
});
@@ -257,18 +249,21 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
} else if (queryType === 'array') {
// belongsTo
if (dataType === 'object') {
- const queryMessage = query.map(function(item) {
- return getKeys(item).map(function(key) {
- return key + ': ' + item[key];
- });
- }).join(', ');
+ const queryMessage = query
+ .map(function (item) {
+ return getKeys(item).map(function (key) {
+ return key + ': ' + item[key];
+ });
+ })
+ .join(', ');
throw new Error(
'You can not provide an array with a belongsTo relation. ' +
- 'Query: ' + queryMessage
+ 'Query: ' +
+ queryMessage
);
- // hasMany
+ // hasMany
} else {
return query.every((queryValue) => {
return this._queryFilter(data, serializer, queryValue);
@@ -279,7 +274,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
if (dataType === 'object') {
return this._matches(data.id, query);
- // hasMany
+ // hasMany
} else {
return data.some((record) => {
return this._queryFilter(record, serializer, query);
@@ -312,7 +307,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
return {
type: type,
- id: id
+ id: id,
};
},
@@ -322,8 +317,7 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
// Should be overwriten
// Signature: _getIndex(type)
- _getIndex() {
- },
+ _getIndex() {},
_indexHasKey(type, id) {
return this._getIndex(type).indexOf(id) !== -1;
@@ -337,5 +331,5 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
_removeFromIndex(type, id) {
this._getIndex(type).removeObject(id);
- }
+ },
});
diff --git a/addon/adapters/local.js b/addon/adapters/local.js
index 2ec68645..0333d18a 100644
--- a/addon/adapters/local.js
+++ b/addon/adapters/local.js
@@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);
- indices[type] = StorageArray
- .extend({ _storageKey: storageKey })
- .create();
+ indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}
return indices[type];
- }
+ },
});
diff --git a/addon/adapters/session.js b/addon/adapters/session.js
index e2c8c902..eb015fe7 100644
--- a/addon/adapters/session.js
+++ b/addon/adapters/session.js
@@ -12,11 +12,9 @@ export default BaseAdapter.extend({
if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);
- indices[type] = StorageArray
- .extend({ _storageKey: storageKey })
- .create();
+ indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
}
return indices[type];
- }
+ },
});
diff --git a/addon/helpers/import-export.js b/addon/helpers/import-export.js
index d9c07ebc..db70e58c 100644
--- a/addon/helpers/import-export.js
+++ b/addon/helpers/import-export.js
@@ -6,12 +6,16 @@ import { A } from '@ember/array';
export function importData(store, content, options) {
// merge defaults
- options = Object.assign({
- json: true,
- truncate: true
- }, options || {});
+ options = Object.assign(
+ {
+ json: true,
+ truncate: true,
+ },
+ options || {}
+ );
- let truncateTypes = A(), reloadTypes = A();
+ let truncateTypes = A(),
+ reloadTypes = A();
content = options.json ? JSON.parse(content) : content;
@@ -42,38 +46,43 @@ export function importData(store, content, options) {
reloadTypes.addObject(singularize(record.type));
return adapter._handleStorageRequest(null, 'POST', {
- data: {data: record}
+ data: { data: record },
});
});
- return all(promises)
- .then(function() {
- // reload from store
- reloadTypes.forEach(function(type) {
- store.findAll(type);
- });
+ return all(promises).then(function () {
+ // reload from store
+ reloadTypes.forEach(function (type) {
+ store.findAll(type);
});
+ });
}
export function exportData(store, types, options) {
// merge defaults
- options = Object.assign({
- json: true,
- download: false,
- filename: 'ember-data.json'
- }, options || {});
+ options = Object.assign(
+ {
+ json: true,
+ download: false,
+ filename: 'ember-data.json',
+ },
+ options || {}
+ );
let json, data;
// collect data
- data = types.reduce((records, type) => {
- const adapter = store.adapterFor(singularize(type));
- const url = adapter.buildURL(type),
- exportData = adapter._handleGETRequest(url);
-
- records.data = records.data.concat(exportData);
- return records;
- }, {data: []});
+ data = types.reduce(
+ (records, type) => {
+ const adapter = store.adapterFor(singularize(type));
+ const url = adapter.buildURL(type);
+ const exportData = adapter._handleGETRequest(url);
+
+ records.data = records.data.concat(exportData);
+ return records;
+ },
+ { data: [] }
+ );
if (options.json || options.download) {
json = JSON.stringify(data);
@@ -85,7 +94,7 @@ export function exportData(store, types, options) {
if (options.download) {
window.saveAs(
- new Blob([json], {type: 'application/json;charset=utf-8'}),
+ new Blob([json], { type: 'application/json;charset=utf-8' }),
options.filename
);
}
diff --git a/addon/helpers/storage.js b/addon/helpers/storage.js
index 40161c18..b5137d36 100644
--- a/addon/helpers/storage.js
+++ b/addon/helpers/storage.js
@@ -3,7 +3,6 @@ import EmberObject, { computed, get } from '@ember/object';
import { getOwner } from '@ember/application';
import { dasherize } from '@ember/string';
-
const storage = {};
function tryStorage(name) {
@@ -11,7 +10,7 @@ function tryStorage(name) {
// safari private mode exposes xStorage but fails on setItem
try {
- nativeStorage = (name === 'local') ? localStorage : sessionStorage;
+ nativeStorage = name === 'local' ? localStorage : sessionStorage;
nativeStorage.setItem('emberlocalstorage.test', 'ok');
nativeStorage.removeItem('emberlocalstorage.test');
} catch (e) {
@@ -25,7 +24,7 @@ function getStorage(name) {
if (storage[name]) {
return storage[name];
} else {
- return storage[name] = tryStorage(name) || {};
+ return (storage[name] = tryStorage(name) || {});
}
}
@@ -36,7 +35,7 @@ function storageFor(key, modelName) {
key = dasherize(key);
if (!modelName) {
- return computed(function() {
+ return computed(function () {
if (!storages[key]) {
storages[key] = createStorage(this, key, null);
}
@@ -48,7 +47,7 @@ function storageFor(key, modelName) {
assert('The second argument must be a string', typeof modelName === 'string');
// TODO: Allow callbacks to delete the storage if model gets deleted
- return computed(modelName, function() {
+ return computed(modelName, function () {
const model = get(this, modelName);
// If the propertyValue is null/undefined we simply return null/undefined
@@ -75,10 +74,12 @@ function createStorage(context, key, modelKey) {
const owner = getOwner(context);
const factoryType = 'storage';
const storageFactory = `${factoryType}:${key}`;
- const storageKey = modelKey ? `${storageFactory}:${modelKey}` : storageFactory;
+ const storageKey = modelKey
+ ? `${storageFactory}:${modelKey}`
+ : storageFactory;
const defaultState = {
- _storageKey: _buildKey(context, storageKey)
+ _storageKey: _buildKey(context, storageKey),
};
const StorageFactory = owner.factoryFor(storageFactory);
@@ -88,7 +89,7 @@ function createStorage(context, key, modelKey) {
const StorageFactoryClass = StorageFactory.class;
- if (typeof(StorageFactoryClass.initialState) === 'function') {
+ if (typeof StorageFactoryClass.initialState === 'function') {
defaultState._initialContent = StorageFactoryClass.initialState.call(
StorageFactoryClass,
context
@@ -98,17 +99,15 @@ function createStorage(context, key, modelKey) {
}
if (EmberObject.detect(StorageFactoryClass)) {
- return StorageFactoryClass.create(
- owner.ownerInjection(),
- defaultState
- );
+ return StorageFactoryClass.create(owner.ownerInjection(), defaultState);
}
return EmberObject.create(owner.ownerInjection(), StorageFactoryClass);
}
function _modelKey(model) {
- const modelName = model.modelName || model.constructor.typeKey || model.constructor.modelName;
+ const modelName =
+ model.modelName || model.constructor.typeKey || model.constructor.modelName;
const id = model.get('id');
if (!modelName || !id) {
@@ -125,7 +124,7 @@ function _getNamespace(appConfig, addonConfig) {
// Shortcut for modulePrefix
if (namespace === true) {
- namespace = appConfig.modulePrefix
+ namespace = appConfig.modulePrefix;
}
return namespace;
@@ -134,7 +133,7 @@ function _getNamespace(appConfig, addonConfig) {
// TODO: Add migration helper
function _buildKey(context, key) {
let appConfig = getOwner(context).resolveRegistration('config:environment');
- let addonConfig = appConfig && appConfig['ember-local-storage'] || {};
+ let addonConfig = (appConfig && appConfig['ember-local-storage']) || {};
let namespace = _getNamespace(appConfig, addonConfig);
let delimiter = addonConfig.keyDelimiter || ':';
@@ -146,10 +145,4 @@ function _resetStorages() {
storages = {};
}
-export {
- tryStorage,
- getStorage,
- storageFor,
- _resetStorages,
- _buildKey
-};
+export { tryStorage, getStorage, storageFor, _resetStorages, _buildKey };
diff --git a/addon/helpers/utils.js b/addon/helpers/utils.js
index 614ecdc1..9ee1c9c1 100644
--- a/addon/helpers/utils.js
+++ b/addon/helpers/utils.js
@@ -11,7 +11,4 @@ function saveIfChanged(key) {
}
}
-export {
- save,
- saveIfChanged
-};
+export { save, saveIfChanged };
diff --git a/addon/index.js b/addon/index.js
index 8a8caea8..cdbe443c 100644
--- a/addon/index.js
+++ b/addon/index.js
@@ -1,5 +1,3 @@
import { storageFor } from 'ember-local-storage/helpers/storage';
-export {
- storageFor
-};
+export { storageFor };
diff --git a/addon/initializers/local-storage-adapter.js b/addon/initializers/local-storage-adapter.js
index a8ab3c04..dfb1cb91 100644
--- a/addon/initializers/local-storage-adapter.js
+++ b/addon/initializers/local-storage-adapter.js
@@ -1,16 +1,19 @@
import DS from 'ember-data';
-import { importData, exportData } from 'ember-local-storage/helpers/import-export';
+import {
+ importData,
+ exportData,
+} from 'ember-local-storage/helpers/import-export';
export function initialize() {
if (!DS.Store.prototype._emberLocalStoragePatched) {
DS.Store.reopen({
_emberLocalStoragePatched: true,
- importData: function(json, options) {
+ importData: function (json, options) {
return importData(this, json, options);
},
- exportData: function(types, options) {
+ exportData: function (types, options) {
return exportData(this, types, options);
- }
+ },
});
}
}
@@ -18,5 +21,5 @@ export function initialize() {
export default {
name: 'local-storage-adapter',
after: 'ember-data',
- initialize: initialize
+ initialize: initialize,
};
diff --git a/addon/local/array.js b/addon/local/array.js
index 7362e300..4ed2fd41 100644
--- a/addon/local/array.js
+++ b/addon/local/array.js
@@ -2,5 +2,5 @@ import ArrayProxy from '@ember/array/proxy';
import ArrayProxyMixin from '../mixins/array';
export default ArrayProxy.extend(ArrayProxyMixin, {
- _storageType: 'local'
+ _storageType: 'local',
});
diff --git a/addon/local/object.js b/addon/local/object.js
index 5ea2493f..e7c1a742 100644
--- a/addon/local/object.js
+++ b/addon/local/object.js
@@ -2,5 +2,5 @@ import ObjectProxy from '@ember/object/proxy';
import ObjectProxyMixin from '../mixins/object';
export default ObjectProxy.extend(ObjectProxyMixin, {
- _storageType: 'local'
+ _storageType: 'local',
});
diff --git a/addon/mixins/adapters/import-export.js b/addon/mixins/adapters/import-export.js
index 9bacff46..6f88a471 100644
--- a/addon/mixins/adapters/import-export.js
+++ b/addon/mixins/adapters/import-export.js
@@ -1,5 +1,8 @@
import Mixin from '@ember/object/mixin';
-import { importData, exportData } from 'ember-local-storage/helpers/import-export';
+import {
+ importData,
+ exportData,
+} from 'ember-local-storage/helpers/import-export';
export default Mixin.create({
importData(store, content, options) {
@@ -8,5 +11,5 @@ export default Mixin.create({
exportData(store, types, options) {
return exportData(store, types, options);
- }
+ },
});
diff --git a/addon/mixins/array.js b/addon/mixins/array.js
index 96890066..5d3e9564 100644
--- a/addon/mixins/array.js
+++ b/addon/mixins/array.js
@@ -6,8 +6,10 @@ import { save } from '../helpers/utils';
export default Mixin.create(StorageProxyMixin, {
_initialContent: A(),
- _clear() { set(this, 'content', A()); },
+ _clear() {
+ set(this, 'content', A());
+ },
replaceContent: save,
- reset: save
+ reset: save,
});
diff --git a/addon/mixins/object.js b/addon/mixins/object.js
index 7bed132e..543d600b 100644
--- a/addon/mixins/object.js
+++ b/addon/mixins/object.js
@@ -5,9 +5,11 @@ import { save, saveIfChanged } from '../helpers/utils';
export default Mixin.create(StorageProxyMixin, {
_initialContent: {},
- _clear() { set(this, 'content', {}); },
+ _clear() {
+ set(this, 'content', {});
+ },
setUnknownProperty: saveIfChanged,
set: saveIfChanged,
- setProperties: save
+ setProperties: save,
});
diff --git a/addon/mixins/storage.js b/addon/mixins/storage.js
index e7873077..ae82651a 100644
--- a/addon/mixins/storage.js
+++ b/addon/mixins/storage.js
@@ -2,7 +2,7 @@ import Mixin from '@ember/object/mixin';
import { set, get } from '@ember/object';
import { isArray, A } from '@ember/array';
import { getStorage } from '../helpers/storage';
-import { copy } from 'ember-copy'
+import { copy } from 'ember-copy';
export default Mixin.create({
_storageKey: null,
@@ -59,7 +59,9 @@ export default Mixin.create({
if (window.addEventListener) {
this._storageEventHandler = (event) => {
- if (this.isDestroying) { return; }
+ if (this.isDestroying) {
+ return;
+ }
if (event.storageArea === storage && event.key === storageKey) {
if (
@@ -131,5 +133,5 @@ export default Mixin.create({
clear() {
this._clear();
delete this._storage()[get(this, '_storageKey')];
- }
+ },
});
diff --git a/addon/serializers/serializer.js b/addon/serializers/serializer.js
index 94f0138f..88754f4b 100644
--- a/addon/serializers/serializer.js
+++ b/addon/serializers/serializer.js
@@ -1,8 +1,6 @@
import DS from 'ember-data';
-const {
- JSONAPISerializer
-} = DS;
+const { JSONAPISerializer } = DS;
const emberDataVersionOlderThan3Point1 = DS.VERSION.match(/^[0-2]\.|^3\.0/);
@@ -10,8 +8,12 @@ export default JSONAPISerializer.extend({
// Serialization behavior
// Can be removed (_shouldSerializeHasMany) removed in ember data 3.0.0
// https://github.com/emberjs/data/pull/5290
- _shouldSerializeHasMany: function() { return true; },
- shouldSerializeHasMany: function() { return true; },
+ _shouldSerializeHasMany: function () {
+ return true;
+ },
+ shouldSerializeHasMany: function () {
+ return true;
+ },
serializeBelongsTo(snapshot, json, relationship) {
if (emberDataVersionOlderThan3Point1) {
@@ -34,7 +36,8 @@ export default JSONAPISerializer.extend({
if (this._canSerialize(key)) {
let belongsTo = snapshot.belongsTo(key);
- let belongsToIsNotNew = belongsTo && belongsTo.record && belongsTo.record.get('id');
+ let belongsToIsNotNew =
+ belongsTo && belongsTo.record && belongsTo.record.get('id');
if (belongsTo === null || belongsToIsNotNew) {
json.relationships = json.relationships || {};
@@ -75,7 +78,9 @@ export default JSONAPISerializer.extend({
}
// only serialize has many relationships that are not new
- let nonNewHasMany = hasMany.filter(item => item.record && item.record.get('id'));
+ let nonNewHasMany = hasMany.filter(
+ (item) => item.record && item.record.get('id')
+ );
let data = new Array(nonNewHasMany.length);
for (let i = 0; i < nonNewHasMany.length; i++) {
diff --git a/addon/session/array.js b/addon/session/array.js
index e0ae8ad3..467b969a 100644
--- a/addon/session/array.js
+++ b/addon/session/array.js
@@ -2,5 +2,5 @@ import ArrayProxy from '@ember/array/proxy';
import ArrayProxyMixin from '../mixins/array';
export default ArrayProxy.extend(ArrayProxyMixin, {
- _storageType: 'session'
+ _storageType: 'session',
});
diff --git a/addon/session/object.js b/addon/session/object.js
index 5726d49e..e5b9b3ad 100644
--- a/addon/session/object.js
+++ b/addon/session/object.js
@@ -2,5 +2,5 @@ import ObjectProxy from '@ember/object/proxy';
import ObjectProxyMixin from '../mixins/object';
export default ObjectProxy.extend(ObjectProxyMixin, {
- _storageType: 'session'
+ _storageType: 'session',
});
diff --git a/app/initializers/local-storage-adapter.js b/app/initializers/local-storage-adapter.js
index 2c5c261c..40f39cad 100644
--- a/app/initializers/local-storage-adapter.js
+++ b/app/initializers/local-storage-adapter.js
@@ -1 +1,4 @@
-export { default, initialize } from 'ember-local-storage/initializers/local-storage-adapter';
+export {
+ default,
+ initialize,
+} from 'ember-local-storage/initializers/local-storage-adapter';
diff --git a/blueprints/storage/index.js b/blueprints/storage/index.js
index 2b24c3dc..f29fc01b 100644
--- a/blueprints/storage/index.js
+++ b/blueprints/storage/index.js
@@ -10,40 +10,34 @@ module.exports = {
name: 'type',
type: ['object', 'array'],
default: 'object',
- aliases:[
- { 'a': 'array'},
- { 'array': 'array'}
- ]
+ aliases: [{ a: 'array' }, { array: 'array' }],
},
{
name: 'storage',
type: ['local', 'session'],
default: 'local',
- aliases:[
- { 's': 'session'},
- { 'session': 'session'}
- ]
- }
+ aliases: [{ s: 'session' }, { session: 'session' }],
+ },
],
- locals: function(options) {
- var storage = options.storage;
- var type = options.type;
- var path = [storage, type].join('/');
+ locals: function (options) {
+ var storage = options.storage;
+ var type = options.type;
+ var path = [storage, type].join('/');
- var baseClass = stringUtils.classify('storage-' + type);
- var initialState = type === 'object' ? '{}' : '[]';
+ var baseClass = stringUtils.classify('storage-' + type);
+ var initialState = type === 'object' ? '{}' : '[]';
var importStatement = [
'import ' + baseClass,
- ' from ' + '\'ember-local-storage/' + path +'\'',
- ';'
+ ' from ' + "'ember-local-storage/" + path + "'",
+ ';',
].join('');
return {
importStatement: importStatement,
baseClass: baseClass,
- initialState: initialState
+ initialState: initialState,
};
- }
-};
\ No newline at end of file
+ },
+};
diff --git a/ember-cli-build.js b/ember-cli-build.js
index e92907bc..a32b1f5e 100644
--- a/ember-cli-build.js
+++ b/ember-cli-build.js
@@ -6,9 +6,7 @@ module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
// Add options here
sassOptions: {
- includePaths: [
- 'node_modules',
- ],
+ includePaths: ['node_modules'],
onlyIncluded: true,
},
});
diff --git a/index.js b/index.js
index b2bf2fc3..dfb2aebe 100644
--- a/index.js
+++ b/index.js
@@ -51,11 +51,9 @@ module.exports = {
this._super.included.apply(this, arguments);
},
- treeForApp: function(tree) {
+ treeForApp: function (tree) {
if (!this.hasEmberData) {
- [
- 'initializers/local-storage-adapter.js'
- ].forEach(function(file) {
+ ['initializers/local-storage-adapter.js'].forEach(function (file) {
tree = stew.rm(tree, file);
});
}
@@ -63,7 +61,7 @@ module.exports = {
return tree;
},
- treeForAddon: function(tree) {
+ treeForAddon: function (tree) {
if (!this.hasEmberData) {
[
'adapters/adapter.js',
@@ -72,8 +70,8 @@ module.exports = {
'adapters/session.js',
'initializers/local-storage-adapter.js',
'mixins/adapters/import-export.js',
- 'serializers/serializer.js'
- ].forEach(function(file) {
+ 'serializers/serializer.js',
+ ].forEach(function (file) {
tree = stew.rm(tree, file);
});
}
@@ -83,9 +81,9 @@ module.exports = {
treeForVendor(vendorTree) {
let blobTree = new Funnel(path.dirname(require.resolve('blob-polyfill')), {
- files: ['Blob.js']
+ files: ['Blob.js'],
});
return mergeTrees([vendorTree, blobTree]);
- }
+ },
};
diff --git a/tests/dummy/app/adapters/application.js b/tests/dummy/app/adapters/application.js
index 7c4e2eb8..a8c04302 100644
--- a/tests/dummy/app/adapters/application.js
+++ b/tests/dummy/app/adapters/application.js
@@ -2,4 +2,4 @@ import Adapter from 'ember-local-storage/adapters/local';
export default Adapter.extend({
// _debug: true
-});
\ No newline at end of file
+});
diff --git a/tests/dummy/app/adapters/blog/post.js b/tests/dummy/app/adapters/blog/post.js
index 0eab70b4..e60a7c90 100644
--- a/tests/dummy/app/adapters/blog/post.js
+++ b/tests/dummy/app/adapters/blog/post.js
@@ -1,5 +1,5 @@
import Adapter from 'ember-local-storage/adapters/adapter';
export default Adapter.extend({
- modelNamespace: 'blog'
-});
\ No newline at end of file
+ modelNamespace: 'blog',
+});
diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js
index b642ad26..5d3411f8 100644
--- a/tests/dummy/app/app.js
+++ b/tests/dummy/app/app.js
@@ -6,7 +6,7 @@ import config from 'dummy/config/environment';
const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
- Resolver
+ Resolver,
});
loadInitializers(App, config.modulePrefix);
diff --git a/tests/dummy/app/controllers/projects.js b/tests/dummy/app/controllers/projects.js
index f157a928..88eb902c 100644
--- a/tests/dummy/app/controllers/projects.js
+++ b/tests/dummy/app/controllers/projects.js
@@ -9,12 +9,12 @@ function readFile(file) {
const reader = new FileReader();
return new Promise((resolve) => {
- reader.onload = function(event) {
+ reader.onload = function (event) {
resolve({
file: file.name,
type: file.type,
data: event.target.result,
- size: file.size
+ size: file.size,
});
};
@@ -33,18 +33,15 @@ export default class extends Controller {
createProject(name) {
let project = this.store.createRecord('project', { name: name });
- this.store
- .findRecord('user', this.settings.get('userId'))
- .then((user) => {
- user.get('projects').addObject(project);
- user.save();
+ this.store.findRecord('user', this.settings.get('userId')).then((user) => {
+ user.get('projects').addObject(project);
+ user.save();
- project.get('users').addObject(user);
- project.save()
- .then(() => {
- this.name = '';
- });
+ project.get('users').addObject(user);
+ project.save().then(() => {
+ this.name = '';
});
+ });
}
@action
@@ -60,9 +57,8 @@ export default class extends Controller {
task.destroyRecord();
})
).then(() => {
- project.destroyRecord()
- .then(() => {
- this.router.transitionTo('projects')
+ project.destroyRecord().then(() => {
+ this.router.transitionTo('projects');
});
});
});
@@ -70,23 +66,27 @@ export default class extends Controller {
@action
importData(event) {
- readFile(event.target.files[0])
- .then((file) => {
- this.store
- .importData(file.data)
- .then(function() {
- // show a flash message or transitionTo somewehere
- });
+ readFile(event.target.files[0]).then((file) => {
+ this.store.importData(file.data).then(function () {
+ // show a flash message or transitionTo somewehere
});
+ });
}
@action
exportData() {
- this.store.exportData(
- ['projects', 'tasks', 'users'],
- {download: true, filename: 'my-data.json'}
- ).then(function() {
- // show a flash message or transitionTo somewehere
- });
+ this.store
+ .exportData(['projects', 'tasks', 'users'], {
+ download: true,
+ filename: 'my-data.json',
+ })
+ .then(function () {
+ // show a flash message or transitionTo somewehere
+ });
+ }
+
+ @action
+ setName(event) {
+ this.name = event.target.value;
}
}
diff --git a/tests/dummy/app/controllers/projects/project.js b/tests/dummy/app/controllers/projects/project.js
index 7edc6c32..8b8eead9 100644
--- a/tests/dummy/app/controllers/projects/project.js
+++ b/tests/dummy/app/controllers/projects/project.js
@@ -17,14 +17,18 @@ export default class extends Controller {
project.get('tasks').addObject(task);
task.set('project', project);
- task.save()
- .then(() => {
- this.name = '';
- });
+ task.save().then(() => {
+ this.name = '';
+ });
}
@action
deleteTask(task) {
task.destroyRecord();
}
+
+ @action
+ setName(event) {
+ this.name = event.target.value;
+ }
}
diff --git a/tests/dummy/app/models/blog/post.js b/tests/dummy/app/models/blog/post.js
index edeba080..79f13814 100644
--- a/tests/dummy/app/models/blog/post.js
+++ b/tests/dummy/app/models/blog/post.js
@@ -1,15 +1,10 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- belongsTo,
- hasMany
-} = DS;
+const { Model, attr, belongsTo, hasMany } = DS;
export default Model.extend({
name: attr('string'),
user: belongsTo('user', { async: true, autoSave: true }),
- comments: hasMany('comment', { async: true, dependent: 'destroy' })
+ comments: hasMany('comment', { async: true, dependent: 'destroy' }),
});
diff --git a/tests/dummy/app/models/book-publication.js b/tests/dummy/app/models/book-publication.js
index 23a273ea..61e9ca3c 100644
--- a/tests/dummy/app/models/book-publication.js
+++ b/tests/dummy/app/models/book-publication.js
@@ -1,13 +1,9 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- hasMany
-} = DS;
+const { Model, attr, hasMany } = DS;
export default Model.extend({
name: attr('string'),
- user: hasMany('user', { async: true })
+ user: hasMany('user', { async: true }),
});
diff --git a/tests/dummy/app/models/comment.js b/tests/dummy/app/models/comment.js
index ac45a13a..a2efedd7 100644
--- a/tests/dummy/app/models/comment.js
+++ b/tests/dummy/app/models/comment.js
@@ -1,13 +1,9 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- belongsTo
-} = DS;
+const { Model, attr, belongsTo } = DS;
export default Model.extend({
name: attr('string'),
- post: belongsTo('post', { async: true, autoSave: true })
+ post: belongsTo('post', { async: true, autoSave: true }),
});
diff --git a/tests/dummy/app/models/pet.js b/tests/dummy/app/models/pet.js
index 033c7bdf..47e64a9d 100644
--- a/tests/dummy/app/models/pet.js
+++ b/tests/dummy/app/models/pet.js
@@ -1,13 +1,9 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- hasMany
-} = DS;
+const { Model, attr, hasMany } = DS;
export default Model.extend({
name: attr('string'),
- users: hasMany('user', { async: true })
+ users: hasMany('user', { async: true }),
});
diff --git a/tests/dummy/app/models/post.js b/tests/dummy/app/models/post.js
index f7b1d758..3751d6f8 100644
--- a/tests/dummy/app/models/post.js
+++ b/tests/dummy/app/models/post.js
@@ -1,11 +1,6 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- belongsTo,
- hasMany
-} = DS;
+const { Model, attr, belongsTo, hasMany } = DS;
export default Model.extend({
name: attr('string'),
@@ -13,5 +8,5 @@ export default Model.extend({
isPrivate: attr('boolean', { defaultValue: true }),
user: belongsTo('user', { async: true, autoSave: true }),
- comments: hasMany('comment', { async: true, dependent: 'destroy' })
+ comments: hasMany('comment', { async: true, dependent: 'destroy' }),
});
diff --git a/tests/dummy/app/models/project.js b/tests/dummy/app/models/project.js
index d19c3616..d4ddfe3f 100644
--- a/tests/dummy/app/models/project.js
+++ b/tests/dummy/app/models/project.js
@@ -1,10 +1,6 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- hasMany
-} = DS;
+const { Model, attr, hasMany } = DS;
export default Model.extend({
name: attr('string'),
diff --git a/tests/dummy/app/models/task.js b/tests/dummy/app/models/task.js
index b4188d87..b4ad983e 100644
--- a/tests/dummy/app/models/task.js
+++ b/tests/dummy/app/models/task.js
@@ -1,11 +1,6 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- belongsTo,
- hasMany
-} = DS;
+const { Model, attr, belongsTo, hasMany } = DS;
export default Model.extend({
name: attr('string'),
@@ -13,18 +8,18 @@ export default Model.extend({
project: belongsTo('project', {
async: true,
- autoSave: true
+ autoSave: true,
}),
parent: belongsTo('task', {
async: true,
autoSave: true,
- inverse: 'children'
+ inverse: 'children',
}),
children: hasMany('task', {
async: true,
dependent: 'destroy',
- inverse: 'parent'
- })
+ inverse: 'parent',
+ }),
});
diff --git a/tests/dummy/app/models/user.js b/tests/dummy/app/models/user.js
index 75563fad..5f9bc7fb 100644
--- a/tests/dummy/app/models/user.js
+++ b/tests/dummy/app/models/user.js
@@ -1,10 +1,6 @@
import DS from 'ember-data';
-const {
- Model,
- attr,
- hasMany
-} = DS;
+const { Model, attr, hasMany } = DS;
export default Model.extend({
name: attr('string'),
@@ -12,5 +8,9 @@ export default Model.extend({
bookPublications: hasMany('book-publications', { async: true }),
projects: hasMany('project', { async: true }),
posts: hasMany('post', { async: true, dependent: 'destroy' }),
- pets: hasMany('pet', { async: true, polymorphic: true, dependent: 'destroy' })
+ pets: hasMany('pet', {
+ async: true,
+ polymorphic: true,
+ dependent: 'destroy',
+ }),
});
diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js
index 06acff50..11b7be21 100644
--- a/tests/dummy/app/router.js
+++ b/tests/dummy/app/router.js
@@ -3,14 +3,14 @@ import config from 'dummy/config/environment';
const Router = EmberRouter.extend({
location: config.locationType,
- rootURL: config.rootURL
+ rootURL: config.rootURL,
});
-Router.map(function() {
- this.route('adapter', function() {
- this.route('projects', { resetNamespace: true }, function() {
- this.route('project', { path: ':project_id' }, function() {
- this.route('tasks', { resetNamespace: true }, function() {
+Router.map(function () {
+ this.route('adapter', function () {
+ this.route('projects', { resetNamespace: true }, function () {
+ this.route('project', { path: ':project_id' }, function () {
+ this.route('tasks', { resetNamespace: true }, function () {
this.route('task', { path: ':task_id' });
});
});
diff --git a/tests/dummy/app/routes/application.js b/tests/dummy/app/routes/application.js
index 5976933f..9e9f87eb 100644
--- a/tests/dummy/app/routes/application.js
+++ b/tests/dummy/app/routes/application.js
@@ -13,7 +13,7 @@ export default class extends Route {
// setup a user
if (!this.settings.get('userId')) {
this.store
- .createRecord('user', {name: 'Me'})
+ .createRecord('user', { name: 'Me' })
.save()
.then((user) => {
this.settings.set('userId', user.get('id'));
diff --git a/tests/dummy/app/serializers/application.js b/tests/dummy/app/serializers/application.js
index 54ef820e..7b52485f 100644
--- a/tests/dummy/app/serializers/application.js
+++ b/tests/dummy/app/serializers/application.js
@@ -1 +1 @@
-export { default } from 'ember-local-storage/serializers/serializer';
\ No newline at end of file
+export { default } from 'ember-local-storage/serializers/serializer';
diff --git a/tests/dummy/app/storages/anonymous-likes.js b/tests/dummy/app/storages/anonymous-likes.js
index 05dd7af7..075611f1 100644
--- a/tests/dummy/app/storages/anonymous-likes.js
+++ b/tests/dummy/app/storages/anonymous-likes.js
@@ -1,3 +1,3 @@
import StorageArray from 'ember-local-storage/local/array';
-export default StorageArray.extend();
\ No newline at end of file
+export default StorageArray.extend();
diff --git a/tests/dummy/app/storages/likes.js b/tests/dummy/app/storages/likes.js
index 37a253e7..7b5807df 100644
--- a/tests/dummy/app/storages/likes.js
+++ b/tests/dummy/app/storages/likes.js
@@ -6,7 +6,7 @@ const Storage = StorageArray.extend();
Storage.reopenClass({
initialState() {
return A(['1234']);
- }
+ },
});
-export default Storage;
\ No newline at end of file
+export default Storage;
diff --git a/tests/dummy/app/storages/post-likes.js b/tests/dummy/app/storages/post-likes.js
index 05dd7af7..075611f1 100644
--- a/tests/dummy/app/storages/post-likes.js
+++ b/tests/dummy/app/storages/post-likes.js
@@ -1,3 +1,3 @@
import StorageArray from 'ember-local-storage/local/array';
-export default StorageArray.extend();
\ No newline at end of file
+export default StorageArray.extend();
diff --git a/tests/dummy/app/storages/settings.js b/tests/dummy/app/storages/settings.js
index 9064a28f..48d34835 100644
--- a/tests/dummy/app/storages/settings.js
+++ b/tests/dummy/app/storages/settings.js
@@ -6,9 +6,9 @@ Storage.reopenClass({
initialState() {
return {
welcomeMessageSeen: false,
- userId: null
+ userId: null,
};
- }
+ },
});
-export default Storage;
\ No newline at end of file
+export default Storage;
diff --git a/tests/dummy/app/storages/stats.js b/tests/dummy/app/storages/stats.js
index af11080b..e1c8b7bd 100644
--- a/tests/dummy/app/storages/stats.js
+++ b/tests/dummy/app/storages/stats.js
@@ -5,9 +5,9 @@ const Storage = StorageObject.extend();
Storage.reopenClass({
initialState() {
return {
- counter: 0
+ counter: 0,
};
- }
+ },
});
-export default Storage;
\ No newline at end of file
+export default Storage;
diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs
index c8acb09f..69b188f8 100644
--- a/tests/dummy/app/templates/index.hbs
+++ b/tests/dummy/app/templates/index.hbs
@@ -3,5 +3,5 @@ The addon provides a storageFor
computed property that returns a pr
It ships with an ember-data adapter that works almost the same as the JSONAPIAdapter with some relationship sugar added.
Your Page Visits: {{this.stats.counter}}
-Count up
-X
+Count up
+X
diff --git a/tests/dummy/app/templates/post.hbs b/tests/dummy/app/templates/post.hbs
deleted file mode 100644
index 5671ac27..00000000
--- a/tests/dummy/app/templates/post.hbs
+++ /dev/null
@@ -1,17 +0,0 @@
-
-{{model.id}}
-{{model.name}}
-{{model.comments.length}}
-
-Post Visits: {{postStats.counter}}
-
-X
-
-
-{{#each model.comments as |comment|}}
- {{comment.name}} -
- Delete
-
-{{/each}}
-
-Create comment
\ No newline at end of file
diff --git a/tests/dummy/app/templates/projects.hbs b/tests/dummy/app/templates/projects.hbs
index d23e8752..5532ee57 100644
--- a/tests/dummy/app/templates/projects.hbs
+++ b/tests/dummy/app/templates/projects.hbs
@@ -1,17 +1,18 @@
Open the developer tools and go to Resources
-> Local Storage
or reload to see the effect.
-
-Export
+
+
+
+Export
-Name:
-
-Create project
+
+ Name:
+
+
+Create project
@@ -22,7 +23,7 @@ Open the developer tools and go to Resources
-> Local Storage
{{#each this.model as |project|}}
{{project.name}} -
- Delete
+ Delete
{{/each}}
diff --git a/tests/dummy/app/templates/projects/project.hbs b/tests/dummy/app/templates/projects/project.hbs
index 57908bd7..27641946 100644
--- a/tests/dummy/app/templates/projects/project.hbs
+++ b/tests/dummy/app/templates/projects/project.hbs
@@ -3,9 +3,11 @@
-Name:
-
-Create task
+
+ Name:
+
+
+Create task
@@ -16,7 +18,7 @@
{{#each this.model.tasks as |task|}}
{{task.name}} -
- Delete
+ Delete
{{/each}}
diff --git a/tests/dummy/app/templates/storage-for.hbs b/tests/dummy/app/templates/storage-for.hbs
index 24179629..2721e78c 100644
--- a/tests/dummy/app/templates/storage-for.hbs
+++ b/tests/dummy/app/templates/storage-for.hbs
@@ -1,5 +1,5 @@
Generator
-{{! template-lint-disable block-indentation}}
+{{! template-lint-disable block-indentation no-unbalanced-curlies}}
Run ember g storage -h
for all options.
@@ -20,9 +20,9 @@ Open the developer tools and go to Resources
-> Local Storage
{{! template-lint-disable simple-unless}}
{{#unless this.settings.welcomeMessageSeen}}
You will see this message until you click
- X
+ X
{{else}}
- Undo
+ Undo
{{/unless}}
diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js
index cd132360..9cfc7b90 100644
--- a/tests/dummy/config/environment.js
+++ b/tests/dummy/config/environment.js
@@ -50,7 +50,7 @@ module.exports = function (environment) {
if (environment === 'production') {
// here you can enable a production-specific feature
- ENV.rootURL = '/ember-local-storage'
+ ENV.rootURL = '/ember-local-storage';
ENV.locationType = 'hash';
}
diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js
index b208d38d..319b45fc 100644
--- a/tests/helpers/resolver.js
+++ b/tests/helpers/resolver.js
@@ -5,7 +5,7 @@ const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
- podModulePrefix: config.podModulePrefix
+ podModulePrefix: config.podModulePrefix,
};
export default resolver;
diff --git a/tests/helpers/storage.js b/tests/helpers/storage.js
index efbbf8cb..621e231c 100644
--- a/tests/helpers/storage.js
+++ b/tests/helpers/storage.js
@@ -11,10 +11,12 @@ function storageDeepEqual(assert, actual, expected, message) {
function registerConfigEnvironment(context) {
let environment = {
modulePrefix: 'my-app',
- 'ember-local-storage': {}
+ 'ember-local-storage': {},
};
- context.owner.register('config:environment', environment, { instantiate: false });
+ context.owner.register('config:environment', environment, {
+ instantiate: false,
+ });
}
function setConfigEnvironment(context, key, value) {
@@ -27,5 +29,5 @@ export {
storageEqual,
storageDeepEqual,
registerConfigEnvironment,
- setConfigEnvironment
+ setConfigEnvironment,
};
diff --git a/tests/helpers/test-data.js b/tests/helpers/test-data.js
index db15a5cc..ca98ae67 100644
--- a/tests/helpers/test-data.js
+++ b/tests/helpers/test-data.js
@@ -1,3 +1,4 @@
export default {
- importFileContent: '{"data":[{"id":"a18uk9g","attributes":{"name":"Test Post"},"relationships":{"comments":{"data":[{"type":"comments","id":"q3nd438"},{"type":"comments","id":"u1efmqg"},{"type":"comments","id":"l4139to"}]}},"type":"posts"},{"id":"dju3e8g","attributes":{"name":"Test Post"},"relationships":{"comments":{"data":[]}},"type":"posts"},{"id":"q3nd438","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"},{"id":"u1efmqg","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"},{"id":"l4139to","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"}]}'
-};
\ No newline at end of file
+ importFileContent:
+ '{"data":[{"id":"a18uk9g","attributes":{"name":"Test Post"},"relationships":{"comments":{"data":[{"type":"comments","id":"q3nd438"},{"type":"comments","id":"u1efmqg"},{"type":"comments","id":"l4139to"}]}},"type":"posts"},{"id":"dju3e8g","attributes":{"name":"Test Post"},"relationships":{"comments":{"data":[]}},"type":"posts"},{"id":"q3nd438","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"},{"id":"u1efmqg","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"},{"id":"l4139to","attributes":{"name":"Test comment"},"relationships":{"post":{"data":{"type":"posts","id":"a18uk9g"}}},"type":"comments"}]}',
+};
diff --git a/tests/unit/adapters/application-test.js b/tests/unit/adapters/application-test.js
index 73bcf723..d774b66d 100644
--- a/tests/unit/adapters/application-test.js
+++ b/tests/unit/adapters/application-test.js
@@ -3,49 +3,48 @@ import DS from 'ember-data';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-const {
- AdapterError,
- Model,
- attr
-} = DS;
+const { AdapterError, Model, attr } = DS;
let SimpleModel = Model.extend({
- prop: attr('string')
+ prop: attr('string'),
});
-module('Unit | Adapter | application', function(hooks) {
+module('Unit | Adapter | application', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
this.owner.register('model:simple', SimpleModel);
this.store = this.owner.lookup('service:store');
});
// Replace this with your real tests.
- test('it exists', function(assert) {
+ test('it exists', function (assert) {
var adapter = this.owner.lookup('adapter:application');
assert.ok(adapter);
});
- test('it has a importData method', function(assert) {
+ test('it has a importData method', function (assert) {
var adapter = this.owner.lookup('adapter:application');
- assert.ok(typeof adapter.importData === 'function');
+ assert.strictEqual(typeof adapter.importData, 'function');
});
- test('it has a exportData method', function(assert) {
+ test('it has a exportData method', function (assert) {
var adapter = this.owner.lookup('adapter:application');
- assert.ok(typeof adapter.exportData === 'function');
+ assert.strictEqual(typeof adapter.exportData, 'function');
});
- test('it handles requests for missing records', function(assert) {
+ test('it handles requests for missing records', function (assert) {
assert.expect(1);
return run(() => {
- return this.store.findRecord('simple', '12345').then(() => {
- assert.notOk(true, "should not have succeeded");
- }).catch((e) => {
- assert.ok(e instanceof AdapterError, "an adapter error was thrown");
- });
+ return this.store
+ .findRecord('simple', '12345')
+ .then(() => {
+ assert.notOk(true, 'should not have succeeded');
+ })
+ .catch((e) => {
+ assert.ok(e instanceof AdapterError, 'an adapter error was thrown');
+ });
});
});
});
diff --git a/tests/unit/adapters/import-export-test.js b/tests/unit/adapters/import-export-test.js
index 284c9e09..1696c32b 100644
--- a/tests/unit/adapters/import-export-test.js
+++ b/tests/unit/adapters/import-export-test.js
@@ -7,127 +7,140 @@ import testData from '../../helpers/test-data';
import { initialize } from 'ember-local-storage/initializers/local-storage-adapter';
import SessionStorageAdapter from 'ember-local-storage/adapters/session';
-module('Unit | Adapter | import/export', function(hooks) {
+module('Unit | Adapter | import/export', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
initialize();
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('import', function(assert) {
+ test('import', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
- return run(function() {
+ return run(function () {
return store.importData(testData.importFileContent);
- }).then(function() {
- const posts = store.findAll('post');
- const comments = store.findAll('comment');
-
- return hash({
- posts: posts,
- comments: comments
+ })
+ .then(function () {
+ const posts = store.findAll('post');
+ const comments = store.findAll('comment');
+
+ return hash({
+ posts: posts,
+ comments: comments,
+ });
+ })
+ .then(function (data) {
+ assert.equal(get(data.posts, 'length'), 2);
+ assert.equal(get(data.comments, 'length'), 3);
});
- }).then(function(data) {
- assert.equal(get(data.posts, 'length'), 2);
- assert.equal(get(data.comments, 'length'), 3);
- });
});
- test('import with records loaded', function(assert) {
+ test('import with records loaded', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
- return run(function() {
+ return run(function () {
return hash({
posts: store.findAll('post'),
- comments: store.findAll('comment')
+ comments: store.findAll('comment'),
});
- }).then(function() {
- return store.importData(testData.importFileContent);
- }).then(function() {
- return hash({
- posts: store.findAll('post'),
- comments: store.findAll('comment')
+ })
+ .then(function () {
+ return store.importData(testData.importFileContent);
+ })
+ .then(function () {
+ return hash({
+ posts: store.findAll('post'),
+ comments: store.findAll('comment'),
+ });
+ })
+ .then(function (data) {
+ assert.equal(get(data.posts, 'length'), 2);
+ assert.equal(get(data.comments, 'length'), 3);
});
- }).then(function(data) {
- assert.equal(get(data.posts, 'length'), 2);
- assert.equal(get(data.comments, 'length'), 3);
- });
});
- test('import to multiple adapter types', function(assert) {
+ test('import to multiple adapter types', function (assert) {
assert.expect(4);
this.owner.register('adapter:post', SessionStorageAdapter);
const store = this.owner.lookup('service:store');
- return run(function() {
+ return run(function () {
return store.importData(testData.importFileContent);
- }).then(function() {
- const posts = store.findAll('post');
- const comments = store.findAll('comment');
-
- return hash({
- posts: posts,
- comments: comments
+ })
+ .then(function () {
+ const posts = store.findAll('post');
+ const comments = store.findAll('comment');
+
+ return hash({
+ posts: posts,
+ comments: comments,
+ });
+ })
+ .then(function (data) {
+ assert.equal(get(data.posts, 'length'), 2);
+ assert.equal(get(data.comments, 'length'), 3);
+ assert.equal(
+ JSON.parse(window.localStorage['index-comments']).length,
+ 3
+ );
+ assert.equal(
+ JSON.parse(window.sessionStorage['index-posts']).length,
+ 2
+ );
});
- }).then(function(data) {
- assert.equal(get(data.posts, 'length'), 2);
- assert.equal(get(data.comments, 'length'), 3);
- assert.equal(JSON.parse(window.localStorage['index-comments']).length, 3);
- assert.equal(JSON.parse(window.sessionStorage['index-posts']).length, 2);
- });
});
- test('export', function(assert) {
+ test('export', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
- return run(function() {
+ return run(function () {
return store.importData(testData.importFileContent);
- }).then(function() {
- const posts = store.findAll('post');
- const comments = store.findAll('comment');
-
- return hash({
- posts: posts,
- comments: comments
+ })
+ .then(function () {
+ const posts = store.findAll('post');
+ const comments = store.findAll('comment');
+
+ return hash({
+ posts: posts,
+ comments: comments,
+ });
+ })
+ .then(function () {
+ return store.exportData(['posts', 'comments'], { json: false });
+ })
+ .then(function (data) {
+ assert.equal(data.data.length, 5);
});
- }).then(function() {
- return store.exportData(
- ['posts', 'comments'],
- {json: false}
- );
- }).then(function(data) {
- assert.equal(data.data.length, 5);
- });
});
- test('export from multiple adapter types', function(assert) {
+ test('export from multiple adapter types', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
this.owner.register('adapter:post', SessionStorageAdapter);
- return run(function() {
+ return run(function () {
return store.importData(testData.importFileContent);
- }).then(function() {
- const posts = store.findAll('post');
- const comments = store.findAll('comment');
-
- return hash({
- posts: posts,
- comments: comments
+ })
+ .then(function () {
+ const posts = store.findAll('post');
+ const comments = store.findAll('comment');
+
+ return hash({
+ posts: posts,
+ comments: comments,
+ });
+ })
+ .then(function () {
+ return store.exportData(['posts', 'comments'], { json: false });
+ })
+ .then(function (data) {
+ assert.equal(data.data.length, 5);
});
- }).then(function() {
- return store.exportData(
- ['posts', 'comments'],
- {json: false}
- );
- }).then(function(data) {
- assert.equal(data.data.length, 5);
- });
});
});
diff --git a/tests/unit/adapters/indices-test.js b/tests/unit/adapters/indices-test.js
index 21457aad..eeee8d07 100644
--- a/tests/unit/adapters/indices-test.js
+++ b/tests/unit/adapters/indices-test.js
@@ -4,22 +4,22 @@ import {
storageEqual,
storageDeepEqual,
registerConfigEnvironment,
- setConfigEnvironment
+ setConfigEnvironment,
} from '../../helpers/storage';
-module('Unit | Adapter | indices', function(hooks) {
+module('Unit | Adapter | indices', function (hooks) {
setupTest(hooks);
// Specify the other units that are required for this test.
// needs: ['serializer:foo']
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
registerConfigEnvironment(this);
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('it persists the index', function(assert) {
+ test('it persists the index', function (assert) {
assert.expect(2);
var adapter = this.owner.lookup('adapter:application');
@@ -29,7 +29,7 @@ module('Unit | Adapter | indices', function(hooks) {
storageDeepEqual(assert, window.localStorage['index-projects'], ['1234']);
});
- test('it does not persists duplicates to index', function(assert) {
+ test('it does not persists duplicates to index', function (assert) {
assert.expect(2);
var adapter = this.owner.lookup('adapter:application');
@@ -40,7 +40,7 @@ module('Unit | Adapter | indices', function(hooks) {
storageDeepEqual(assert, window.localStorage['index-projects'], ['1234']);
});
- test('it removes ids from index (namespace not set)', function(assert) {
+ test('it removes ids from index (namespace not set)', function (assert) {
assert.expect(3);
var adapter = this.owner.lookup('adapter:application');
@@ -53,7 +53,7 @@ module('Unit | Adapter | indices', function(hooks) {
storageDeepEqual(assert, window.localStorage['index-projects'], []);
});
- test('it removes ids from index (namespace: true)', function(assert) {
+ test('it removes ids from index (namespace: true)', function (assert) {
assert.expect(3);
setConfigEnvironment(this, 'namespace', true);
@@ -63,17 +63,15 @@ module('Unit | Adapter | indices', function(hooks) {
storageEqual(assert, window.localStorage['index-projects'], undefined);
adapter._addToIndex('projects', '1234');
- storageDeepEqual(
- assert,
- window.localStorage['my-app:index-projects'],
- ['1234']
- );
+ storageDeepEqual(assert, window.localStorage['my-app:index-projects'], [
+ '1234',
+ ]);
adapter._removeFromIndex('projects', '1234');
storageDeepEqual(assert, window.localStorage['my-app:index-projects'], []);
});
- test('it removes ids from index (namespace: "custom")', function(assert) {
+ test('it removes ids from index (namespace: "custom")', function (assert) {
assert.expect(3);
setConfigEnvironment(this, 'namespace', 'custom');
@@ -83,17 +81,15 @@ module('Unit | Adapter | indices', function(hooks) {
storageEqual(assert, window.localStorage['index-projects'], undefined);
adapter._addToIndex('projects', '1234');
- storageDeepEqual(
- assert,
- window.localStorage['custom:index-projects'],
- ['1234']
- );
+ storageDeepEqual(assert, window.localStorage['custom:index-projects'], [
+ '1234',
+ ]);
adapter._removeFromIndex('projects', '1234');
storageDeepEqual(assert, window.localStorage['custom:index-projects'], []);
});
- test('it removes ids from index (keyDelimiter: "/")', function(assert) {
+ test('it removes ids from index (keyDelimiter: "/")', function (assert) {
assert.expect(3);
setConfigEnvironment(this, 'namespace', true);
@@ -104,11 +100,9 @@ module('Unit | Adapter | indices', function(hooks) {
storageEqual(assert, window.localStorage['index-projects'], undefined);
adapter._addToIndex('projects', '1234');
- storageDeepEqual(
- assert,
- window.localStorage['my-app/index-projects'],
- ['1234']
- );
+ storageDeepEqual(assert, window.localStorage['my-app/index-projects'], [
+ '1234',
+ ]);
adapter._removeFromIndex('projects', '1234');
storageDeepEqual(assert, window.localStorage['my-app/index-projects'], []);
diff --git a/tests/unit/array-test.js b/tests/unit/array-test.js
index fd7a8e3e..90572eb4 100644
--- a/tests/unit/array-test.js
+++ b/tests/unit/array-test.js
@@ -2,40 +2,41 @@ import { run } from '@ember/runloop';
import EmberObject, { get } from '@ember/object';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-import {
- storageDeepEqual
-} from '../helpers/storage';
+import { storageDeepEqual } from '../helpers/storage';
import StorageArray from 'ember-local-storage/local/array';
import {
storageFor,
- _resetStorages
+ _resetStorages,
} from 'ember-local-storage/helpers/storage';
let subject;
-module('array - likes', function(hooks) {
+module('array - likes', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
let mockStorage = StorageArray.extend();
let mockStorageB = StorageArray.extend();
this.owner.register('storage:anonymous-likes', mockStorage);
this.owner.register('storage:post-likes', mockStorageB);
- this.owner.register('object:test', EmberObject.extend({
- anonymousLikes: storageFor('anonymous-likes'),
- postLikes: storageFor('post-likes')
- }));
+ this.owner.register(
+ 'object:test',
+ EmberObject.extend({
+ anonymousLikes: storageFor('anonymous-likes'),
+ postLikes: storageFor('post-likes'),
+ })
+ );
subject = this.owner.lookup('object:test');
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
window.localStorage.clear();
_resetStorages();
});
- test('it has correct defaults', function(assert) {
+ test('it has correct defaults', function (assert) {
assert.expect(3);
assert.equal(get(subject, 'anonymousLikes._storageType'), 'local');
@@ -46,19 +47,19 @@ module('array - likes', function(hooks) {
assert.deepEqual(get(subject, 'anonymousLikes._initialContent'), []);
});
- test('it does not share data', function(assert) {
+ test('it does not share data', function (assert) {
assert.expect(5);
// ImageLikes
assert.deepEqual(get(subject, 'anonymousLikes._initialContent'), []);
- run(function() {
+ run(function () {
get(subject, 'anonymousLikes').addObject('martin');
});
assert.deepEqual(get(subject, 'anonymousLikes.content'), ['martin']);
// PostLikes
assert.deepEqual(get(subject, 'postLikes._initialContent'), []);
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('peter');
});
assert.deepEqual(get(subject, 'postLikes.content'), ['peter']);
@@ -67,14 +68,14 @@ module('array - likes', function(hooks) {
assert.deepEqual(get(subject, 'anonymousLikes.content'), ['martin']);
});
- test('reset method restores initialContent', function(assert) {
+ test('reset method restores initialContent', function (assert) {
assert.expect(4);
//initialContent is set properly
assert.deepEqual(get(subject, 'postLikes.content'), []);
//add new objects
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
@@ -91,73 +92,67 @@ module('array - likes', function(hooks) {
storageDeepEqual(assert, window.localStorage['storage:post-likes'], []);
});
- test('it updates _isInitialContent', function(assert) {
+ test('it updates _isInitialContent', function (assert) {
assert.expect(2);
- assert.equal(get(subject, 'postLikes').isInitialContent(), true);
- run(function() {
+ assert.true(get(subject, 'postLikes').isInitialContent());
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
- assert.equal(get(subject, 'postLikes').isInitialContent(), false);
+ assert.false(get(subject, 'postLikes').isInitialContent());
});
- test('it updates _isInitialContent on reset', function(assert) {
+ test('it updates _isInitialContent on reset', function (assert) {
assert.expect(2);
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
- assert.equal(get(subject, 'postLikes').isInitialContent(), false);
+ assert.false(get(subject, 'postLikes').isInitialContent());
- run(function() {
+ run(function () {
get(subject, 'postLikes').reset();
});
- assert.equal(get(subject, 'postLikes').isInitialContent(), true);
+ assert.true(get(subject, 'postLikes').isInitialContent());
});
- test('clear method removes the content from localStorage', function(assert) {
+ test('clear method removes the content from localStorage', function (assert) {
assert.expect(2);
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
- storageDeepEqual(
- assert,
- window.localStorage['storage:post-likes'],
- ['martin']
- );
+ storageDeepEqual(assert, window.localStorage['storage:post-likes'], [
+ 'martin',
+ ]);
- run(function() {
+ run(function () {
get(subject, 'postLikes').clear();
});
assert.equal(window.localStorage['storage:post-likes'], undefined);
});
- test('after .clear() the array works as expected', function(assert) {
+ test('after .clear() the array works as expected', function (assert) {
assert.expect(4);
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
- storageDeepEqual(
- assert,
- window.localStorage['storage:post-likes'],
- ['martin']
- );
+ storageDeepEqual(assert, window.localStorage['storage:post-likes'], [
+ 'martin',
+ ]);
- run(function() {
+ run(function () {
get(subject, 'postLikes').clear();
});
assert.equal(window.localStorage['storage:post-likes'], undefined);
- run(function() {
+ run(function () {
get(subject, 'postLikes').addObject('martin');
});
- storageDeepEqual(
- assert,
- window.localStorage['storage:post-likes'],
- ['martin']
- );
+ storageDeepEqual(assert, window.localStorage['storage:post-likes'], [
+ 'martin',
+ ]);
assert.deepEqual(get(subject, 'postLikes.content'), ['martin']);
});
});
diff --git a/tests/unit/initializers/local-storage-adapter-test.js b/tests/unit/initializers/local-storage-adapter-test.js
index a8a85c7d..31da9117 100644
--- a/tests/unit/initializers/local-storage-adapter-test.js
+++ b/tests/unit/initializers/local-storage-adapter-test.js
@@ -4,26 +4,26 @@ import { initialize } from '../../../initializers/local-storage-adapter';
let store;
-module('Unit | Initializer | local storage adapter', function(hooks) {
+module('Unit | Initializer | local storage adapter', function (hooks) {
setupApplicationTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
store = this.owner.lookup('service:store');
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
store = null;
});
- test('it adds importData to DS.Store', function(assert) {
+ test('it adds importData to DS.Store', function (assert) {
initialize();
- assert.ok(typeof store.importData === 'function');
+ assert.strictEqual(typeof store.importData, 'function');
});
- test('it adds exportData to DS.Store', function(assert) {
+ test('it adds exportData to DS.Store', function (assert) {
initialize();
- assert.ok(typeof store.exportData === 'function');
+ assert.strictEqual(typeof store.exportData, 'function');
});
-});
\ No newline at end of file
+});
diff --git a/tests/unit/models/blog/post-test.js b/tests/unit/models/blog/post-test.js
index ebefdb14..bcbeb366 100644
--- a/tests/unit/models/blog/post-test.js
+++ b/tests/unit/models/blog/post-test.js
@@ -3,15 +3,15 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-module('Unit | Model | blog/post', function(hooks) {
+module('Unit | Model | blog/post', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('create a namespaced record', function(assert) {
+ test('create a namespaced record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -20,20 +20,19 @@ module('Unit | Model | blog/post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
+ run(function () {
store.createRecord('blog/post', { name: 'Super Name' }).save();
store.createRecord('blog/post', { name: 'Just awesome' }).save();
store.createRecord('blog/post', { name: 'Just a Name' }).save();
});
- store.findAll('blog/post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 3);
- done();
- });
+ store.findAll('blog/post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 3);
+ done();
+ });
});
- test('push a namespaced record', function(assert) {
+ test('push a namespaced record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -42,54 +41,54 @@ module('Unit | Model | blog/post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
- store.push({data: [
- {
- id: '1',
- type: 'blog/post',
- attributes: {name: 'Super Name'}
- },
- {
- id: '2',
- type: 'blog/post',
- attributes: {name: 'Totally rad'}
- }
- ]});
+ run(function () {
+ store.push({
+ data: [
+ {
+ id: '1',
+ type: 'blog/post',
+ attributes: { name: 'Super Name' },
+ },
+ {
+ id: '2',
+ type: 'blog/post',
+ attributes: { name: 'Totally rad' },
+ },
+ ],
+ });
});
- store.findAll('blog/post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.findAll('blog/post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
- test('find a single namespaced record', function(assert) {
+ test('find a single namespaced record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
let newPost;
- run(function() {
+ run(function () {
newPost = store.createRecord('blog/post', {
- name: 'Ember.js: 10 most common mistakes'
+ name: 'Ember.js: 10 most common mistakes',
});
newPost.save();
});
- run(function() {
- store.find('blog/post', get(newPost, 'id'))
- .then(function(post) {
- assert.equal(get(post, 'id'), get(newPost, 'id'));
- assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
- done();
- });
+ run(function () {
+ store.findRecord('blog/post', get(newPost, 'id')).then(function (post) {
+ assert.equal(get(post, 'id'), get(newPost, 'id'));
+ assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
+ done();
+ });
});
});
- test('namespaced get all', function(assert) {
+ test('namespaced get all', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -97,25 +96,27 @@ module('Unit | Model | blog/post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
-
- run(function() {
- store.createRecord('blog/post', {
- name: 'Ember.js: 10 most common mistakes'
- }).save();
-
- store.createRecord('blog/post', {
- name: 'Ember.js: Ember-CPM'
- }).save();
+ run(function () {
+ store
+ .createRecord('blog/post', {
+ name: 'Ember.js: 10 most common mistakes',
+ })
+ .save();
+
+ store
+ .createRecord('blog/post', {
+ name: 'Ember.js: Ember-CPM',
+ })
+ .save();
});
- store.findAll('blog/post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.findAll('blog/post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
- test('namespaced queryRecord attributes', function(assert) {
+ test('namespaced queryRecord attributes', function (assert) {
assert.expect(3);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -123,27 +124,33 @@ module('Unit | Model | blog/post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
- store.createRecord('blog/post', {
- name: 'Super Name'
- }).save();
-
- store.createRecord('blog/post', {
- name: 'Just a Name'
- }).save();
-
- store.createRecord('blog/post', {
- name: 'Just a Name'
- }).save();
+ run(function () {
+ store
+ .createRecord('blog/post', {
+ name: 'Super Name',
+ })
+ .save();
+
+ store
+ .createRecord('blog/post', {
+ name: 'Just a Name',
+ })
+ .save();
+
+ store
+ .createRecord('blog/post', {
+ name: 'Just a Name',
+ })
+ .save();
});
- store.findAll('blog/post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 3);
- });
+ store.findAll('blog/post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 3);
+ });
- store.queryRecord('blog/post', { filter: { name: 'Super Name' } })
- .then(function(post) {
+ store
+ .queryRecord('blog/post', { filter: { name: 'Super Name' } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Super Name');
done();
});
diff --git a/tests/unit/models/post-test.js b/tests/unit/models/post-test.js
index db6457e8..972d09db 100644
--- a/tests/unit/models/post-test.js
+++ b/tests/unit/models/post-test.js
@@ -5,26 +5,28 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
registerConfigEnvironment,
- setConfigEnvironment
+ setConfigEnvironment,
} from '../../helpers/storage';
-module('Unit | Model | post', function(hooks) {
+module('Unit | Model | post', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
registerConfigEnvironment(this);
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('it exists', function(assert) {
- let model = run(() => this.owner.lookup('service:store').createRecord('post'));
+ test('it exists', function (assert) {
+ let model = run(() =>
+ this.owner.lookup('service:store').createRecord('post')
+ );
// var store = this.store();
assert.ok(!!model);
});
- test('create a record', function(assert) {
+ test('create a record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -33,20 +35,19 @@ module('Unit | Model | post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
+ run(function () {
store.createRecord('post', { name: 'Super Name' }).save();
store.createRecord('post', { name: 'Just awesome' }).save();
store.createRecord('post', { name: 'Just a Name' }).save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 3);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 3);
+ done();
+ });
});
- test('push a record', function(assert) {
+ test('push a record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -55,54 +56,54 @@ module('Unit | Model | post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
- store.push({data: [
- {
- id: '1',
- type: 'post',
- attributes: {name: 'Super Name'}
- },
- {
- id: '2',
- type: 'post',
- attributes: {name: 'Totally rad'}
- }
- ]});
+ run(function () {
+ store.push({
+ data: [
+ {
+ id: '1',
+ type: 'post',
+ attributes: { name: 'Super Name' },
+ },
+ {
+ id: '2',
+ type: 'post',
+ attributes: { name: 'Totally rad' },
+ },
+ ],
+ });
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
- test('find a single record', function(assert) {
+ test('find a single record', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
let newPost;
- run(function() {
+ run(function () {
newPost = store.createRecord('post', {
- name: 'Ember.js: 10 most common mistakes'
+ name: 'Ember.js: 10 most common mistakes',
});
newPost.save();
});
- run(function() {
- store.find('post', get(newPost, 'id'))
- .then(function(post) {
- assert.equal(get(post, 'id'), get(newPost, 'id'));
- assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
- done();
- });
+ run(function () {
+ store.findRecord('post', get(newPost, 'id')).then(function (post) {
+ assert.equal(get(post, 'id'), get(newPost, 'id'));
+ assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
+ done();
+ });
});
});
- test('get all', function(assert) {
+ test('get all', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -110,25 +111,27 @@ module('Unit | Model | post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
-
- run(function() {
- store.createRecord('post', {
- name: 'Ember.js: 10 most common mistakes'
- }).save();
-
- store.createRecord('post', {
- name: 'Ember.js: Ember-CPM'
- }).save();
+ run(function () {
+ store
+ .createRecord('post', {
+ name: 'Ember.js: 10 most common mistakes',
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Ember.js: Ember-CPM',
+ })
+ .save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
- test('queryRecord attributes', function(assert) {
+ test('queryRecord attributes', function (assert) {
assert.expect(3);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -138,43 +141,49 @@ module('Unit | Model | post', function(hooks) {
let paul;
- run(function() {
+ run(function () {
paul = store.createRecord('user', {
- name: 'Paul'
+ name: 'Paul',
});
paul.save();
});
- run(function() {
- store.createRecord('post', {
- name: 'Super Name',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Just a Name',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Just a Name',
- user: paul
- }).save();
+ run(function () {
+ store
+ .createRecord('post', {
+ name: 'Super Name',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Just a Name',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Just a Name',
+ user: paul,
+ })
+ .save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 3);
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 3);
+ });
- store.queryRecord('post', { filter: { name: 'Super Name' } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { name: 'Super Name' } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Super Name');
done();
});
});
- test('queryRecord empty store', function(assert) {
+ test('queryRecord empty store', function (assert) {
assert.expect(2);
const done = assert.async();
const store = this.owner.lookup('service:store');
@@ -182,8 +191,9 @@ module('Unit | Model | post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- store.queryRecord('post', { filter: { name: 'Super Name' } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { name: 'Super Name' } })
+ .then(function (post) {
if (DS.VERSION.match(/^1\.13\./) || DS.VERSION.match(/^2\.[0|1]\./)) {
assert.deepEqual(post, []);
} else {
@@ -191,13 +201,17 @@ module('Unit | Model | post', function(hooks) {
}
done();
- }).catch(function(error) {
- assert.ok(false, 'queryRecord on empty store throws error: ' + error.message);
+ })
+ .catch(function (error) {
+ assert.ok(
+ false,
+ 'queryRecord on empty store throws error: ' + error.message
+ );
done();
});
});
- test('create a record (namespace: true)', function(assert) {
+ test('create a record (namespace: true)', function (assert) {
assert.expect(1);
setConfigEnvironment(this, 'namespace', true);
@@ -205,18 +219,17 @@ module('Unit | Model | post', function(hooks) {
const done = assert.async();
const store = this.owner.lookup('service:store');
- run(function() {
+ run(function () {
store.createRecord('post', { name: 'Just a Name' }).save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 1);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 1);
+ done();
+ });
});
- test('create a record (namespace: "custom")', function(assert) {
+ test('create a record (namespace: "custom")', function (assert) {
assert.expect(1);
setConfigEnvironment(this, 'namespace', 'custom');
@@ -224,18 +237,17 @@ module('Unit | Model | post', function(hooks) {
const done = assert.async();
const store = this.owner.lookup('service:store');
- run(function() {
+ run(function () {
store.createRecord('post', { name: 'Just a Name' }).save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 1);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 1);
+ done();
+ });
});
- test('create a record (keyDelimiter: "/")', function(assert) {
+ test('create a record (keyDelimiter: "/")', function (assert) {
assert.expect(1);
setConfigEnvironment(this, 'namespace', 'custom');
@@ -244,18 +256,17 @@ module('Unit | Model | post', function(hooks) {
const done = assert.async();
const store = this.owner.lookup('service:store');
- run(function() {
+ run(function () {
store.createRecord('post', { name: 'Just a Name' }).save();
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 1);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 1);
+ done();
+ });
});
- test('push a record (namespace: true)', function(assert) {
+ test('push a record (namespace: true)', function (assert) {
assert.expect(2);
setConfigEnvironment(this, 'namespace', true);
@@ -267,29 +278,30 @@ module('Unit | Model | post', function(hooks) {
assert.equal(get(posts, 'length'), 0);
- run(function() {
- store.push({data: [
- {
- id: '1',
- type: 'post',
- attributes: {name: 'Super Name'}
- },
- {
- id: '2',
- type: 'post',
- attributes: {name: 'Totally rad'}
- }
- ]});
+ run(function () {
+ store.push({
+ data: [
+ {
+ id: '1',
+ type: 'post',
+ attributes: { name: 'Super Name' },
+ },
+ {
+ id: '2',
+ type: 'post',
+ attributes: { name: 'Totally rad' },
+ },
+ ],
+ });
});
- store.findAll('post')
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.findAll('post').then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
- test('find a single record (namespace: true)', function(assert) {
+ test('find a single record (namespace: true)', function (assert) {
assert.expect(2);
setConfigEnvironment(this, 'namespace', true);
@@ -299,21 +311,20 @@ module('Unit | Model | post', function(hooks) {
let newPost;
- run(function() {
+ run(function () {
newPost = store.createRecord('post', {
- name: 'Ember.js: 10 most common mistakes'
+ name: 'Ember.js: 10 most common mistakes',
});
newPost.save();
});
- run(function() {
- store.find('post', get(newPost, 'id'))
- .then(function(post) {
- assert.equal(get(post, 'id'), get(newPost, 'id'));
- assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
- done();
- });
+ run(function () {
+ store.findRecord('post', get(newPost, 'id')).then(function (post) {
+ assert.equal(get(post, 'id'), get(newPost, 'id'));
+ assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
+ done();
+ });
});
});
});
diff --git a/tests/unit/models/query-record-test.js b/tests/unit/models/query-record-test.js
index daeac2da..efd41e50 100644
--- a/tests/unit/models/query-record-test.js
+++ b/tests/unit/models/query-record-test.js
@@ -3,108 +3,130 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-module('Unit | Model | queryRecord', function(hooks) {
+module('Unit | Model | queryRecord', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('attributes (string, regex, boolean, number)', function(assert) {
+ test('attributes (string, regex, boolean, number)', function (assert) {
assert.expect(5);
const done = assert.async();
const store = this.owner.lookup('service:store');
- run(function() {
+ run(function () {
// Create records
- store.createRecord('post', {
- name: 'Super Name',
- commentCount: 3
- }).save();
- store.createRecord('post', {
- name: 'Just awesome',
- commentCount: 1
- }).save();
- store.createRecord('post', {
- name: 'Just a Name',
- commentCount: 3
- }).save();
- store.createRecord('post', {
- commentCount: 2,
- isPrivate: false
- }).save();
- store.createRecord('post', {
- commentCount: 0
- }).save();
+ store
+ .createRecord('post', {
+ name: 'Super Name',
+ commentCount: 3,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ name: 'Just awesome',
+ commentCount: 1,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ name: 'Just a Name',
+ commentCount: 3,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ commentCount: 2,
+ isPrivate: false,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ commentCount: 0,
+ })
+ .save();
});
// string
- store.queryRecord('post', { filter: { name: 'Super Name' } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { name: 'Super Name' } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Super Name');
});
// boolean
- store.queryRecord('post', { filter: { isPrivate: false } })
- .then(function(post) {
- assert.equal(get(post, 'isPrivate'), false);
+ store
+ .queryRecord('post', { filter: { isPrivate: false } })
+ .then(function (post) {
+ assert.false(get(post, 'isPrivate'));
});
// number
- store.queryRecord('post', { filter: { commentCount: 3 } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { commentCount: 3 } })
+ .then(function (post) {
assert.equal(get(post, 'commentCount'), 3);
});
// regex
- store.queryRecord('post', { filter: { name: /^Just(.*)/ } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { name: /^Just(.*)/ } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Just awesome');
});
// camelized key
- store.queryRecord('post', { filter: { commentCount: 3 } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { commentCount: 3 } })
+ .then(function (post) {
assert.equal(get(post, 'commentCount'), 3);
done();
});
});
-
- test('belongsTo relationship', function(assert) {
+ test('belongsTo relationship', function (assert) {
assert.expect(8);
const done = assert.async();
const store = this.owner.lookup('service:store');
let paul, peter, moritz;
- run(function() {
+ run(function () {
// Create users
paul = store.createRecord('editor', { name: 'Paul' });
peter = store.createRecord('editor', { name: 'Peter' });
moritz = store.createRecord('user', { name: 'Moritz' });
// Create posts
- store.createRecord('post', {
- name: 'Ember.js: 10 most common mistakes',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Ember.js: Ember-CPM',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Ember.js: Testing with Ember PageObjects',
- user: peter
- }).save();
-
- store.createRecord('post', {
- name: 'ES6',
- user: moritz
- }).save();
+ store
+ .createRecord('post', {
+ name: 'Ember.js: 10 most common mistakes',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Ember.js: Ember-CPM',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Ember.js: Testing with Ember PageObjects',
+ user: peter,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'ES6',
+ user: moritz,
+ })
+ .save();
});
const id = get(peter, 'id'),
@@ -112,68 +134,96 @@ module('Unit | Model | queryRecord', function(hooks) {
// get first post from user '123'
// string
- store.queryRecord('post', { filter: { user: id } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects');
- });
+ store.queryRecord('post', { filter: { user: id } }).then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects'
+ );
+ });
// object
- store.queryRecord('post', { filter: { user: { id: id } } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects');
+ store
+ .queryRecord('post', { filter: { user: { id: id } } })
+ .then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects'
+ );
});
// regex
- store.queryRecord('post', { filter: { user: regexId } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects');
+ store
+ .queryRecord('post', { filter: { user: regexId } })
+ .then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects'
+ );
});
// object regex
- store.queryRecord('post', { filter: { user: { id: regexId } } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects');
+ store
+ .queryRecord('post', { filter: { user: { id: regexId } } })
+ .then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects'
+ );
});
// polymorphic
// get first post from editors
- store.queryRecord('post', { filter: { user: { type: 'editor' } } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { user: { type: 'editor' } } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
});
// regex
- store.queryRecord('post', { filter: { user: { type: /^ed(.*)ors$/ } } })
- .then(function(post) {
+ store
+ .queryRecord('post', { filter: { user: { type: /^ed(.*)ors$/ } } })
+ .then(function (post) {
assert.equal(get(post, 'name'), 'Ember.js: 10 most common mistakes');
});
// get first post from editor '123'
- store.queryRecord('post', { filter: { user: { id: id, type: 'editor' } } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects', 'nuu');
+ store
+ .queryRecord('post', { filter: { user: { id: id, type: 'editor' } } })
+ .then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects',
+ 'nuu'
+ );
});
// regex
- store.queryRecord('post', { filter: { user: { id: id, type: /^ed(.*)ors$/ } } })
- .then(function(post) {
- assert.equal(get(post, 'name'), 'Ember.js: Testing with Ember PageObjects', 'ups');
+ store
+ .queryRecord('post', {
+ filter: { user: { id: id, type: /^ed(.*)ors$/ } },
+ })
+ .then(function (post) {
+ assert.equal(
+ get(post, 'name'),
+ 'Ember.js: Testing with Ember PageObjects',
+ 'ups'
+ );
done();
});
});
- test('hasMany relationship', function(assert) {
+ test('hasMany relationship', function (assert) {
assert.expect(9);
const done = assert.async();
const store = this.owner.lookup('service:store');
let anna, peter, moritz, project, bookPublication, cat, dog, dog2;
- run(function() {
+ run(function () {
project = store.createRecord('project', {
- name: 'Componentize all the things!'
+ name: 'Componentize all the things!',
});
bookPublication = store.createRecord('book-publication', {
- name: 'Books For Dummies'
+ name: 'Books For Dummies',
});
cat = store.createRecord('cat', { name: 'Cat name' });
@@ -182,7 +232,7 @@ module('Unit | Model | queryRecord', function(hooks) {
anna = store.createRecord('user', {
name: 'Anna',
- pets: [cat]
+ pets: [cat],
});
anna.save();
@@ -190,7 +240,7 @@ module('Unit | Model | queryRecord', function(hooks) {
name: 'Peter',
pets: [dog2],
projects: [project],
- bookPublications: [bookPublication]
+ bookPublications: [bookPublication],
});
peter.save();
@@ -198,7 +248,7 @@ module('Unit | Model | queryRecord', function(hooks) {
name: 'Moritz',
pets: [cat, dog],
projects: [project],
- bookPublications: [bookPublication]
+ bookPublications: [bookPublication],
});
moritz.save();
@@ -213,59 +263,72 @@ module('Unit | Model | queryRecord', function(hooks) {
// get first user who've contributed to project.id = 123
// string
- store.queryRecord('user', { filter: { projects: id } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { projects: id } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Peter');
});
// object
- store.queryRecord('user', { filter: { projects: { id: id } } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { projects: { id: id } } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Peter');
});
// regex
- store.queryRecord('user', { filter: { projects: regexId } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { projects: regexId } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Peter');
});
// object regex
- store.queryRecord('user', { filter: { projects: { id: regexId } } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { projects: { id: regexId } } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Peter');
});
// polymorphic
// get first user with cats
- store.queryRecord('user', { filter: { pets: { type: 'cat' } } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { pets: { type: 'cat' } } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Anna');
});
// get first user with cat '123'
- store.queryRecord('user', { filter: { pets: { id: get(cat, 'id'), type: 'cat' } } })
- .then(function(user) {
+ store
+ .queryRecord('user', {
+ filter: { pets: { id: get(cat, 'id'), type: 'cat' } },
+ })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Anna');
});
// get first user with cats AND dogs
- store.queryRecord('user', { filter: { pets: [{ type: 'cat' }, { type: 'dog' }] } })
- .then(function(user) {
+ store
+ .queryRecord('user', {
+ filter: { pets: [{ type: 'cat' }, { type: 'dog' }] },
+ })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Moritz');
});
// get first user with cats OR dogs
- store.queryRecord('user', { filter: { pets: { type: /cats|dogs/ } } })
- .then(function(user) {
+ store
+ .queryRecord('user', { filter: { pets: { type: /cats|dogs/ } } })
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Anna');
});
// get the first user with bookPublication '123' (camelcased key)
- store.queryRecord('user', {
- filter: { bookPublications: get(bookPublication, 'id') }
+ store
+ .queryRecord('user', {
+ filter: { bookPublications: get(bookPublication, 'id') },
})
- .then(function(user) {
+ .then(function (user) {
assert.equal(get(user, 'name'), 'Peter');
done();
});
diff --git a/tests/unit/models/query-test.js b/tests/unit/models/query-test.js
index d2485c87..1121d0a6 100644
--- a/tests/unit/models/query-test.js
+++ b/tests/unit/models/query-test.js
@@ -3,108 +3,126 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-module('Unit | Model | query', function(hooks) {
+module('Unit | Model | query', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
});
- test('attributes (string, regex, boolean, number)', function(assert) {
+ test('attributes (string, regex, boolean, number)', function (assert) {
assert.expect(5);
const done = assert.async();
const store = this.owner.lookup('service:store');
- run(function() {
+ run(function () {
// Create records
- store.createRecord('post', {
- name: 'Super Name',
- commentCount: 3
- }).save();
- store.createRecord('post', {
- name: 'Just awesome',
- commentCount: 1
- }).save();
- store.createRecord('post', {
- name: 'Just a Name',
- commentCount: 3
- }).save();
- store.createRecord('post', {
- commentCount: 2,
- isPrivate: false
- }).save();
- store.createRecord('post', {
- commentCount: 0
- }).save();
+ store
+ .createRecord('post', {
+ name: 'Super Name',
+ commentCount: 3,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ name: 'Just awesome',
+ commentCount: 1,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ name: 'Just a Name',
+ commentCount: 3,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ commentCount: 2,
+ isPrivate: false,
+ })
+ .save();
+ store
+ .createRecord('post', {
+ commentCount: 0,
+ })
+ .save();
});
// string
- store.query('post', { filter: { name: 'Super Name' } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { name: 'Super Name' } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 1);
});
// boolean
- store.query('post', { filter: { isPrivate: false } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { isPrivate: false } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 1);
});
// number
- store.query('post', { filter: { commentCount: 3 } })
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- });
+ store.query('post', { filter: { commentCount: 3 } }).then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ });
// regex
- store.query('post', { filter: { name: /^Just(.*)/ } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { name: /^Just(.*)/ } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 2);
});
// camelized key
- store.query('post', { filter: { commentCount: 3 } })
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- done();
- });
+ store.query('post', { filter: { commentCount: 3 } }).then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ done();
+ });
});
-
- test('belongsTo relationship', function(assert) {
+ test('belongsTo relationship', function (assert) {
assert.expect(8);
const done = assert.async();
const store = this.owner.lookup('service:store');
let paul, peter, moritz;
- run(function() {
+ run(function () {
// Create users
paul = store.createRecord('editor', { name: 'Paul' });
peter = store.createRecord('editor', { name: 'Peter' });
moritz = store.createRecord('user', { name: 'Moritz' });
// Create posts
- store.createRecord('post', {
- name: 'Ember.js: 10 most common mistakes',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Ember.js: Ember-CPM',
- user: paul
- }).save();
-
- store.createRecord('post', {
- name: 'Ember.js: Testing with Ember PageObjects',
- user: peter
- }).save();
-
- store.createRecord('post', {
- name: 'ES6',
- user: moritz
- }).save();
+ store
+ .createRecord('post', {
+ name: 'Ember.js: 10 most common mistakes',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Ember.js: Ember-CPM',
+ user: paul,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'Ember.js: Testing with Ember PageObjects',
+ user: peter,
+ })
+ .save();
+
+ store
+ .createRecord('post', {
+ name: 'ES6',
+ user: moritz,
+ })
+ .save();
});
const id = get(paul, 'id'),
@@ -112,68 +130,72 @@ module('Unit | Model | query', function(hooks) {
// get posts from user '123'
// string
- store.query('post', { filter: { user: id } })
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- });
+ store.query('post', { filter: { user: id } }).then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ });
// object
- store.query('post', { filter: { user: { id: id } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { id: id } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 2);
});
// regex
- store.query('post', { filter: { user: regexId } })
- .then(function(posts) {
- assert.equal(get(posts, 'length'), 2);
- });
+ store.query('post', { filter: { user: regexId } }).then(function (posts) {
+ assert.equal(get(posts, 'length'), 2);
+ });
// object regex
- store.query('post', { filter: { user: { id: regexId } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { id: regexId } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 2);
});
// polymorphic
// get posts from editors
- store.query('post', { filter: { user: { type: 'editor' } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { type: 'editor' } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 3);
});
// regex
- store.query('post', { filter: { user: { type: /^ed(.*)ors$/ } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { type: /^ed(.*)ors$/ } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 3);
});
// get posts from editor '123'
- store.query('post', { filter: { user: { id: id, type: 'editor' } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { id: id, type: 'editor' } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 2, 'nuu');
});
// regex
- store.query('post', { filter: { user: { id: id, type: /^ed(.*)ors$/ } } })
- .then(function(posts) {
+ store
+ .query('post', { filter: { user: { id: id, type: /^ed(.*)ors$/ } } })
+ .then(function (posts) {
assert.equal(get(posts, 'length'), 2, 'ups');
done();
});
});
- test('hasMany relationship', function(assert) {
+ test('hasMany relationship', function (assert) {
assert.expect(9);
const done = assert.async();
const store = this.owner.lookup('service:store');
let anna, peter, moritz, project, bookPublication, cat, dog, dog2;
- run(function() {
+ run(function () {
project = store.createRecord('project', {
- name: 'Componentize all the things!'
+ name: 'Componentize all the things!',
});
bookPublication = store.createRecord('book-publication', {
- name: 'Books For Dummies'
+ name: 'Books For Dummies',
});
cat = store.createRecord('cat', { name: 'Cat name' });
@@ -182,7 +204,7 @@ module('Unit | Model | query', function(hooks) {
anna = store.createRecord('user', {
name: 'Anna',
- pets: [cat]
+ pets: [cat],
});
anna.save();
@@ -190,7 +212,7 @@ module('Unit | Model | query', function(hooks) {
name: 'Peter',
pets: [dog2],
projects: [project],
- bookPublications: [bookPublication]
+ bookPublications: [bookPublication],
});
peter.save();
@@ -198,7 +220,7 @@ module('Unit | Model | query', function(hooks) {
name: 'Moritz',
pets: [cat, dog],
projects: [project],
- bookPublications: [bookPublication]
+ bookPublications: [bookPublication],
});
moritz.save();
@@ -213,59 +235,66 @@ module('Unit | Model | query', function(hooks) {
// get users who've contributed to project.id = 123
// string
- store.query('user', { filter: { projects: id } })
- .then(function(users) {
- assert.equal(get(users, 'length'), 2);
- });
+ store.query('user', { filter: { projects: id } }).then(function (users) {
+ assert.equal(get(users, 'length'), 2);
+ });
// object
- store.query('user', { filter: { projects: { id: id } } })
- .then(function(users) {
+ store
+ .query('user', { filter: { projects: { id: id } } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
});
// regex
- store.query('user', { filter: { projects: regexId } })
- .then(function(users) {
+ store
+ .query('user', { filter: { projects: regexId } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
});
// object regex
- store.query('user', { filter: { projects: { id: regexId } } })
- .then(function(users) {
+ store
+ .query('user', { filter: { projects: { id: regexId } } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
});
// polymorphic
// get users with cats
- store.query('user', { filter: { pets: { type: 'cat' } } })
- .then(function(users) {
+ store
+ .query('user', { filter: { pets: { type: 'cat' } } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
});
// get users with cat '123'
- store.query('user', { filter: { pets: { id: get(cat, 'id'), type: 'cat' } } })
- .then(function(users) {
+ store
+ .query('user', { filter: { pets: { id: get(cat, 'id'), type: 'cat' } } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
});
// get users with cats AND dogs
- store.query('user', { filter: { pets: [{ type: 'cat' }, { type: 'dog' }] } })
- .then(function(users) {
+ store
+ .query('user', { filter: { pets: [{ type: 'cat' }, { type: 'dog' }] } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 1);
});
// get users with cats OR dogs
- store.query('user', { filter: { pets: { type: /cats|dogs/ } } })
- .then(function(users) {
+ store
+ .query('user', { filter: { pets: { type: /cats|dogs/ } } })
+ .then(function (users) {
assert.equal(get(users, 'length'), 3);
});
// get the users with bookPublication '123' (camelcased key)
- store.query('user', {
- filter: { bookPublications: get(bookPublication, 'id') }
+ store
+ .query('user', {
+ filter: { bookPublications: get(bookPublication, 'id') },
})
- .then(function(users) {
+ .then(function (users) {
assert.equal(get(users, 'length'), 2);
done();
});
diff --git a/tests/unit/object-test.js b/tests/unit/object-test.js
index 5a57c08a..8d509da4 100644
--- a/tests/unit/object-test.js
+++ b/tests/unit/object-test.js
@@ -2,23 +2,21 @@ import { run } from '@ember/runloop';
import EmberObject, { get } from '@ember/object';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
-import {
- storageDeepEqual
-} from '../helpers/storage';
+import { storageDeepEqual } from '../helpers/storage';
import StorageObject from 'ember-local-storage/local/object';
import SessionStorageObject from 'ember-local-storage/session/object';
import {
storageFor,
- _resetStorages
+ _resetStorages,
} from 'ember-local-storage/helpers/storage';
let subject;
-module('object - settings', function(hooks) {
+module('object - settings', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
let mockStorage = StorageObject.extend();
let mockStorageB = StorageObject.extend();
let mockStorageC = SessionStorageObject.extend();
@@ -27,9 +25,9 @@ module('object - settings', function(hooks) {
mockStorage.reopenClass({
initialState() {
return {
- welcomeMessageSeen: false
+ welcomeMessageSeen: false,
};
- }
+ },
});
mockStorageB.reopenClass({
@@ -38,10 +36,10 @@ module('object - settings', function(hooks) {
address: {
first: null,
second: null,
- anotherProp: null
- }
+ anotherProp: null,
+ },
};
- }
+ },
});
this.owner.register('storage:settings', mockStorage);
@@ -49,28 +47,31 @@ module('object - settings', function(hooks) {
this.owner.register('storage:cache', mockStorageC);
this.owner.register('storage:local-cache', mockStorageD);
- this.owner.register('object:test', EmberObject.extend({
- settings: storageFor('settings'),
- nestedObjects: storageFor('nested-objects'),
- cache: storageFor('cache'),
- localCache: storageFor('local-cache')
- }));
+ this.owner.register(
+ 'object:test',
+ EmberObject.extend({
+ settings: storageFor('settings'),
+ nestedObjects: storageFor('nested-objects'),
+ cache: storageFor('cache'),
+ localCache: storageFor('local-cache'),
+ })
+ );
subject = this.owner.lookup('object:test');
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
_resetStorages();
});
- test('it has correct defaults', function(assert) {
+ test('it has correct defaults', function (assert) {
assert.expect(6);
assert.equal(get(subject, 'settings._storageType'), 'local');
assert.equal(get(subject, 'settings._storageKey'), 'storage:settings');
assert.deepEqual(get(subject, 'settings._initialContent'), {
- welcomeMessageSeen: false
+ welcomeMessageSeen: false,
});
assert.equal(get(subject, 'cache._storageType'), 'session');
@@ -78,44 +79,48 @@ module('object - settings', function(hooks) {
assert.deepEqual(get(subject, 'cache._initialContent'), {});
});
- test('it saves changes to sessionStorage', function(assert) {
+ test('it saves changes to sessionStorage', function (assert) {
assert.expect(3);
assert.ok(window.sessionStorage);
storageDeepEqual(assert, window.sessionStorage['storage:cache'], undefined);
- run(function() {
+ run(function () {
subject.set('cache.image1', 'image1png');
});
storageDeepEqual(assert, window.sessionStorage['storage:cache'], {
- image1: 'image1png'
+ image1: 'image1png',
});
});
- test('it saves changes to localStorage', function(assert) {
+ test('it saves changes to localStorage', function (assert) {
assert.expect(3);
assert.ok(window.localStorage);
- storageDeepEqual(assert, window.localStorage['storage:settings'], undefined);
+ storageDeepEqual(
+ assert,
+ window.localStorage['storage:settings'],
+ undefined
+ );
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
storageDeepEqual(assert, window.localStorage['storage:settings'], {
- welcomeMessageSeen: true
+ welcomeMessageSeen: true,
});
});
- test('it does not share data', function(assert) {
+ test('it does not share data', function (assert) {
assert.expect(10);
assert.equal(get(subject, 'cache._storageType'), 'session');
assert.equal(get(subject, 'cache._storageKey'), 'storage:cache');
assert.deepEqual(get(subject, 'cache._initialContent'), {});
- run(function() {
+ run(function () {
subject.set('cache.key1', '123456');
});
@@ -127,7 +132,7 @@ module('object - settings', function(hooks) {
assert.deepEqual(get(subject, 'cache.key1'), '123456');
- run(function() {
+ run(function () {
subject.set('localCache.key1', 'abcde');
});
@@ -136,152 +141,158 @@ module('object - settings', function(hooks) {
assert.deepEqual(get(subject, 'cache.key1'), '123456');
});
- test('it updates when change events fire', function(assert) {
+ test('it updates when change events fire', function (assert) {
assert.expect(3);
// setup testing
get(subject, 'settings')._testing = true;
assert.equal(get(subject, 'settings.changeFired'), undefined);
- window.dispatchEvent(new window.StorageEvent('storage', {
- key: 'storage:settings',
- newValue: '{"welcomeMessageSeen":false,"changeFired":true}',
- oldValue: '{"welcomeMessageSeen":false}',
- storageArea: get(subject, 'settings')._storage()
- }));
- assert.equal(get(subject, 'settings.welcomeMessageSeen'), false);
- assert.equal(get(subject, 'settings.changeFired'), true);
+ window.dispatchEvent(
+ new window.StorageEvent('storage', {
+ key: 'storage:settings',
+ newValue: '{"welcomeMessageSeen":false,"changeFired":true}',
+ oldValue: '{"welcomeMessageSeen":false}',
+ storageArea: get(subject, 'settings')._storage(),
+ })
+ );
+ assert.false(get(subject, 'settings.welcomeMessageSeen'));
+ assert.true(get(subject, 'settings.changeFired'));
});
- test('nested values get persisted', function(assert) {
+ test('nested values get persisted', function (assert) {
assert.expect(4);
- storageDeepEqual(assert, window.localStorage['storage:nested-objects'], undefined);
+ storageDeepEqual(
+ assert,
+ window.localStorage['storage:nested-objects'],
+ undefined
+ );
assert.equal(get(subject, 'nestedObjects.address.first'), null);
- run(function() {
+ run(function () {
get(subject, 'nestedObjects').set('address.first', {
street: 'Somestreet 1',
- city: 'A City'
+ city: 'A City',
});
});
assert.deepEqual(get(subject, 'nestedObjects.address.first'), {
street: 'Somestreet 1',
- city: 'A City'
+ city: 'A City',
});
storageDeepEqual(assert, window.localStorage['storage:nested-objects'], {
address: {
first: {
street: 'Somestreet 1',
- city: 'A City'
+ city: 'A City',
},
second: null,
- anotherProp: null
- }
+ anotherProp: null,
+ },
});
});
- test('reset method restores initialContent', function(assert) {
+ test('reset method restores initialContent', function (assert) {
assert.expect(5);
//initialContent is set properly
assert.deepEqual(get(subject, 'settings.content'), {
- welcomeMessageSeen: false
+ welcomeMessageSeen: false,
});
//set new properties and overwrite others
- run(function() {
+ run(function () {
subject.set('settings.newProp', 'some-value');
subject.set('settings.welcomeMessageSeen', true);
});
//we expect them to be present
assert.equal(get(subject, 'settings.newProp'), 'some-value');
- assert.equal(get(subject, 'settings.welcomeMessageSeen'), true);
+ assert.true(get(subject, 'settings.welcomeMessageSeen'));
//reset
get(subject, 'settings').reset();
//data is back to initial values
assert.deepEqual(get(subject, 'settings.content'), {
- welcomeMessageSeen: false
+ welcomeMessageSeen: false,
});
assert.strictEqual(get(subject, 'settings.newProp'), undefined);
});
- test('it updates _isInitialContent', function(assert) {
+ test('it updates _isInitialContent', function (assert) {
assert.expect(2);
- assert.equal(get(subject, 'settings').isInitialContent(), true);
+ assert.true(get(subject, 'settings').isInitialContent());
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
- assert.equal(get(subject, 'settings').isInitialContent(), false);
+ assert.false(get(subject, 'settings').isInitialContent());
});
- test('it updates _isInitialContent on reset', function(assert) {
+ test('it updates _isInitialContent on reset', function (assert) {
assert.expect(2);
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
- assert.equal(get(subject, 'settings').isInitialContent(), false);
+ assert.false(get(subject, 'settings').isInitialContent());
- run(function() {
+ run(function () {
get(subject, 'settings').reset();
});
- assert.equal(get(subject, 'settings').isInitialContent(), true);
+ assert.true(get(subject, 'settings').isInitialContent());
});
- test('clear method removes the content from localStorage', function(assert) {
+ test('clear method removes the content from localStorage', function (assert) {
assert.expect(2);
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
storageDeepEqual(assert, window.localStorage['storage:settings'], {
- welcomeMessageSeen: true
+ welcomeMessageSeen: true,
});
- run(function() {
+ run(function () {
get(subject, 'settings').clear();
});
assert.equal(window.localStorage['storage:settings'], undefined);
});
- test('after .clear() the object works as expected', function(assert) {
+ test('after .clear() the object works as expected', function (assert) {
assert.expect(4);
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
storageDeepEqual(assert, window.localStorage['storage:settings'], {
- welcomeMessageSeen: true
+ welcomeMessageSeen: true,
});
- run(function() {
+ run(function () {
get(subject, 'settings').clear();
});
assert.equal(window.localStorage['storage:settings'], undefined);
- run(function() {
+ run(function () {
subject.set('settings.welcomeMessageSeen', true);
});
storageDeepEqual(assert, window.localStorage['storage:settings'], {
- welcomeMessageSeen: true
+ welcomeMessageSeen: true,
});
- assert.equal(get(subject, 'settings.welcomeMessageSeen'), true);
+ assert.true(get(subject, 'settings.welcomeMessageSeen'));
});
});
diff --git a/tests/unit/storage-di-test.js b/tests/unit/storage-di-test.js
index d54c076d..f8d8ba7b 100644
--- a/tests/unit/storage-di-test.js
+++ b/tests/unit/storage-di-test.js
@@ -6,51 +6,53 @@ import { setupTest } from 'ember-qunit';
import StorageObject from 'ember-local-storage/local/object';
import {
storageFor,
- _resetStorages
+ _resetStorages,
} from 'ember-local-storage/helpers/storage';
let subject;
-module('storageFor - DI', function(hooks) {
+module('storageFor - DI', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
- this.owner.register('service:backend', Service.extend({
- name: 'Backend Name'
- }));
+ hooks.beforeEach(function () {
+ this.owner.register(
+ 'service:backend',
+ Service.extend({
+ name: 'Backend Name',
+ })
+ );
let mockStorage = StorageObject.extend({
- backend: service()
+ backend: service(),
});
mockStorage.reopenClass({
initialState() {
return {
- perPage: 10
+ perPage: 10,
};
- }
+ },
});
this.owner.register('storage:settings', mockStorage);
- this.owner.register('object:test', EmberObject.extend({
- settings: storageFor('settings'),
- }));
+ this.owner.register(
+ 'object:test',
+ EmberObject.extend({
+ settings: storageFor('settings'),
+ })
+ );
subject = this.owner.lookup('object:test');
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
window.localStorage.clear();
_resetStorages();
});
- test('DI is working in a storage', function(assert) {
+ test('DI is working in a storage', function (assert) {
assert.expect(1);
- assert.equal(
- subject.get('settings.backend.name'),
- 'Backend Name'
- );
+ assert.equal(subject.get('settings.backend.name'), 'Backend Name');
});
});
-
diff --git a/tests/unit/storage-for-test.js b/tests/unit/storage-for-test.js
index cb4c207b..35b1cae8 100644
--- a/tests/unit/storage-for-test.js
+++ b/tests/unit/storage-for-test.js
@@ -4,21 +4,21 @@ import { setupTest } from 'ember-qunit';
import {
storageDeepEqual,
registerConfigEnvironment,
- setConfigEnvironment
+ setConfigEnvironment,
} from '../helpers/storage';
import StorageObject from 'ember-local-storage/local/object';
import {
storageFor,
- _resetStorages
+ _resetStorages,
} from 'ember-local-storage/helpers/storage';
let subject;
-module('storageFor', function(hooks) {
+module('storageFor', function (hooks) {
setupTest(hooks);
- hooks.beforeEach(function() {
+ hooks.beforeEach(function () {
registerConfigEnvironment(this);
let mockStorage = StorageObject.extend();
@@ -26,9 +26,9 @@ module('storageFor', function(hooks) {
mockStorage.reopenClass({
initialState() {
return {
- perPage: 10
+ perPage: 10,
};
- }
+ },
});
this.owner.register('storage:settings', mockStorage);
@@ -36,23 +36,26 @@ module('storageFor', function(hooks) {
let post = EmberObject.extend({
modelName: 'post',
- id: '123'
+ id: '123',
}).create();
- this.owner.register('object:test', EmberObject.extend({
- post: post,
- settings: storageFor('settings', 'post'),
- options: storageFor('options', 'post')
- }));
+ this.owner.register(
+ 'object:test',
+ EmberObject.extend({
+ post: post,
+ settings: storageFor('settings', 'post'),
+ options: storageFor('options', 'post'),
+ })
+ );
subject = this.owner.lookup('object:test');
});
- hooks.afterEach(function() {
+ hooks.afterEach(function () {
window.localStorage.clear();
_resetStorages();
});
- test('it has the correct key (namespace not set)', function(assert) {
+ test('it has the correct key (namespace not set)', function (assert) {
assert.expect(4);
assert.equal(
@@ -66,15 +69,15 @@ module('storageFor', function(hooks) {
);
storageDeepEqual(assert, window.localStorage['storage:settings:post:123'], {
- perPage: 10
+ perPage: 10,
});
storageDeepEqual(assert, window.localStorage['storage:options:post:123'], {
- perPage: 10
+ perPage: 10,
});
});
- test('it has the correct key (namespace: true)', function(assert) {
+ test('it has the correct key (namespace: true)', function (assert) {
assert.expect(4);
setConfigEnvironment(this, 'namespace', true);
@@ -89,22 +92,24 @@ module('storageFor', function(hooks) {
'my-app:storage:options:post:123'
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['my-app:storage:settings:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['my-app:storage:options:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
});
- test('it has the correct key (namespace: "custom")', function(assert) {
+ test('it has the correct key (namespace: "custom")', function (assert) {
assert.expect(4);
setConfigEnvironment(this, 'namespace', 'custom');
@@ -119,22 +124,24 @@ module('storageFor', function(hooks) {
'custom:storage:options:post:123'
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['custom:storage:settings:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['custom:storage:options:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
});
- test('it has the correct key (keyDelimiter: "/")', function(assert) {
+ test('it has the correct key (keyDelimiter: "/")', function (assert) {
assert.expect(4);
setConfigEnvironment(this, 'namespace', true);
@@ -150,19 +157,20 @@ module('storageFor', function(hooks) {
'my-app/storage:options:post:123'
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['my-app/storage:settings:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
- storageDeepEqual(assert,
+ storageDeepEqual(
+ assert,
window.localStorage['my-app/storage:options:post:123'],
{
- perPage: 10
+ perPage: 10,
}
);
});
});
-