Skip to content

Commit

Permalink
Add failing test for loading hasMany associations
Browse files Browse the repository at this point in the history
This incorporates the proposed fix for pouchdb-community#16, but it doesn’t
actually fix the problem. Perhaps I’m misunderstanding!
  • Loading branch information
backspace committed Jan 23, 2016
1 parent 80882ce commit 0654b2a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion addon/serializers/pouch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import DS from 'ember-data';

export default DS.RESTSerializer.extend({});
export default DS.RESTSerializer.extend({
_shouldSerializeHasMany: function() { return true; }
});
3 changes: 2 additions & 1 deletion tests/dummy/app/models/food-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import DS from 'ember-data';
export default DS.Model.extend({
rev: DS.attr('string'),

name: DS.attr('string')
name: DS.attr('string'),
soup: DS.belongsTo('taco-soup', { async: true })
});
32 changes: 32 additions & 0 deletions tests/integration/adapters/pouch-basics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,38 @@ test('create a new record', function (assert) {
});
});

test('creating an associated record saves it in the parent', function (assert) {
assert.expect(1);

var done = assert.async();
Ember.RSVP.Promise.resolve().then(() => {
return this.db().bulkDocs([
{ _id: 'tacoSoup_2_C', data: { flavor: 'al pastor', ingredients: [] } }
]);
}).then(() => {
return this.store().findRecord('taco-soup', 'C');
}).then(tacoSoup => {
var newIngredient = this.store().createRecord('food-item', {
name: 'pineapple'
});

return Ember.RSVP.all([newIngredient.save().then(ingredient => ingredient), tacoSoup]);
}).then(([ingredient, tacoSoup]) => {
tacoSoup.get('ingredients').pushObject(ingredient);
return tacoSoup.save();
}).then(() => {
this.store().unloadAll();

return this.store().findRecord('taco-soup', 'C');
}).then(tacoSoup => {
return tacoSoup.get('ingredients');
}).then(foundIngredients => {
assert.deepEqual(foundIngredients.mapBy('name'), ['pineapple'],
'should have fully loaded the associated items');
done();
});
});

// This test fails due to a bug in ember data
// (https://github.com/emberjs/data/issues/3736)
// starting with ED v2.0.0-beta.1. It works again with ED v2.1.0.
Expand Down

0 comments on commit 0654b2a

Please sign in to comment.