Skip to content

Commit

Permalink
cleanup tests/unit/store/create-record
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Mar 1, 2017
1 parent 8b06cb9 commit 4411988
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions tests/unit/store/create-record-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Ember from 'ember';
import {module, test} from 'qunit';
import DS from 'ember-data';

var store, Record, Storage;
var run = Ember.run;
let store, Record, Storage;
const { run } = Ember;

module("unit/store/createRecord - Store creating records", {
module('unit/store/createRecord - Store creating records', {
beforeEach() {
Record = DS.Model.extend({
title: DS.attr('string')
Expand All @@ -26,60 +26,65 @@ module("unit/store/createRecord - Store creating records", {
}
});

test("doesn't modify passed in properties hash", function(assert) {
var attributes = { foo: 'bar' };
run(function() {
test(`doesn't modify passed in properties hash`, function(assert) {
let attributes = { foo: 'bar' };

run(() => {
store.createRecord('record', attributes);
store.createRecord('record', attributes);
});

assert.deepEqual(attributes, { foo: 'bar' }, "The properties hash is not modified");
assert.deepEqual(attributes, { foo: 'bar' }, 'The properties hash is not modified');
});

test("allow passing relationships as well as attributes", function(assert) {
var records, storage;
run(function() {
test('allow passing relationships as well as attributes', function(assert) {
let records, storage;

run(() => {
store.push({
data: [{
type: 'record',
id: '1',
attributes: {
title: "it's a beautiful day"
}
}, {
type: 'record',
id: '2',
attributes: {
title: "it's a beautiful day"
data: [
{
type: 'record',
id: '1',
attributes: {
title: "it's a beautiful day"
}
},
{
type: 'record',
id: '2',
attributes: {
title: "it's a beautiful day"
}
}
}]
]
});

records = store.peekAll('record');
storage = store.createRecord('storage', { name: 'Great store', records: records });
});

assert.equal(storage.get('name'), 'Great store', "The attribute is well defined");
assert.equal(storage.get('records').findBy('id', '1'), Ember.A(records).findBy('id', '1'), "Defined relationships are allowed in createRecord");
assert.equal(storage.get('records').findBy('id', '2'), Ember.A(records).findBy('id', '2'), "Defined relationships are allowed in createRecord");
assert.equal(storage.get('name'), 'Great store', 'The attribute is well defined');
assert.equal(storage.get('records').findBy('id', '1'), Ember.A(records).findBy('id', '1'), 'Defined relationships are allowed in createRecord');
assert.equal(storage.get('records').findBy('id', '2'), Ember.A(records).findBy('id', '2'), 'Defined relationships are allowed in createRecord');
});

module("unit/store/createRecord - Store with models by dash", {
module('unit/store/createRecord - Store with models by dash', {
beforeEach() {
var env = setupStore({
someThing: DS.Model.extend({ foo: DS.attr('string') })
let env = setupStore({
someThing: DS.Model.extend({
foo: DS.attr('string')
})
});
store = env.store;
}
});

test("creating a record by dasherize string finds the model", function(assert) {
var attributes = { foo: 'bar' };
var record;
test('creating a record by dasherize string finds the model', function(assert) {
let attributes = { foo: 'bar' };

run(function() {
record = store.createRecord('some-thing', attributes);
});
let record = run(() => store.createRecord('some-thing', attributes));

assert.equal(record.get('foo'), attributes.foo, "The record is created");
assert.equal(record.get('foo'), attributes.foo, 'The record is created');
assert.equal(store.modelFor('some-thing').modelName, 'some-thing');
});

0 comments on commit 4411988

Please sign in to comment.