Support saving posts via Store

This commit is contained in:
Robin Ward
2015-04-09 14:54:17 -04:00
parent d4a05825da
commit 76f7786d0d
16 changed files with 205 additions and 160 deletions
@@ -28,6 +28,21 @@ test('update', function() {
});
});
test('save new', function() {
const store = createStore();
const widget = store.createRecord('widget');
ok(widget.get('isNew'), 'it is a new record');
ok(!widget.get('isCreated'), 'it is not created');
widget.save({ name: 'Evil Widget' }).then(function() {
ok(widget.get('id'), 'it has an id');
ok(widget.get('name'), 'Evil Widget');
ok(widget.get('isCreated'), 'it is created');
ok(!widget.get('isNew'), 'it is no longer new');
});
});
test('destroyRecord', function() {
const store = createStore();
store.find('widget', 123).then(function(widget) {
@@ -5,6 +5,8 @@ import createStore from 'helpers/create-store';
test('createRecord', function() {
const store = createStore();
const widget = store.createRecord('widget', {id: 111, name: 'hello'});
ok(!widget.get('isNew'), 'it is not a new record');
equal(widget.get('name'), 'hello');
equal(widget.get('id'), 111);
});
@@ -13,6 +15,7 @@ test('createRecord without an `id`', function() {
const store = createStore();
const widget = store.createRecord('widget', {name: 'hello'});
ok(widget.get('isNew'), 'it is a new record');
ok(!widget.get('id'), 'there is no id');
});
@@ -21,6 +24,7 @@ test('createRecord without attributes', function() {
const widget = store.createRecord('widget');
ok(!widget.get('id'), 'there is no id');
ok(widget.get('isNew'), 'it is a new record');
});
test('createRecord with a record as attributes returns that record from the map', function() {
@@ -36,6 +40,7 @@ test('find', function() {
store.find('widget', 123).then(function(w) {
equal(w.get('name'), 'Trout Lure');
equal(w.get('id'), 123);
ok(!w.get('isNew'), 'found records are not new');
// A second find by id returns the same object
store.find('widget', 123).then(function(w2) {
@@ -70,6 +75,7 @@ test('findAll', function() {
store.findAll('widget').then(function(result) {
equal(result.get('length'), 2);
const w = result.findBy('id', 124);
ok(!w.get('isNew'), 'found records are not new');
equal(w.get('name'), 'Evil Repellant');
});
});