Fix an issue with the store hydrating embedded objects
This commit is contained in:
@@ -39,6 +39,13 @@ const _moreWidgets = [
|
||||
{id: 224, name: 'Good Repellant'}
|
||||
];
|
||||
|
||||
const fruits = [{id: 1, name: 'apple', farmer_id: 1, category_id: 4},
|
||||
{id: 2, name: 'banana', farmer_id: 1, category_id: 3},
|
||||
{id: 3, name: 'grape', farmer_id: 2, category_id: 5}];
|
||||
|
||||
const farmers = [{id: 1, name: 'Old MacDonald'},
|
||||
{id: 2, name: 'Luke Skywalker'}];
|
||||
|
||||
function loggedIn() {
|
||||
return !!Discourse.User.current();
|
||||
}
|
||||
@@ -178,11 +185,13 @@ export default function() {
|
||||
});
|
||||
|
||||
this.get('/fruits/:id', function() {
|
||||
return response({
|
||||
__rest_serializer: "1",
|
||||
fruit: {id: 1, name: 'apple', farmer_id: 1},
|
||||
farmers: [{id: 1, name: 'Evil Trout'}]
|
||||
});
|
||||
const fruit = fruits[0];
|
||||
|
||||
return response({ __rest_serializer: "1", fruit, farmers: [farmers[0]] });
|
||||
});
|
||||
|
||||
this.get('/fruits', function() {
|
||||
return response({ __rest_serializer: "1", fruits, farmers });
|
||||
});
|
||||
|
||||
this.get('/widgets/:widget_id', function(request) {
|
||||
|
||||
@@ -93,6 +93,15 @@ test('find embedded', function() {
|
||||
const store = createStore();
|
||||
store.find('fruit', 1).then(function(f) {
|
||||
ok(f.get('farmer'), 'it has the embedded object');
|
||||
ok(f.get('category'), 'categories are found automatically');
|
||||
});
|
||||
});
|
||||
|
||||
test('findAll embedded', function() {
|
||||
const store = createStore();
|
||||
store.findAll('fruit').then(function(fruits) {
|
||||
equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald');
|
||||
equal(fruits.objectAt(0).get('farmer'), fruits.objectAt(1).get('farmer'), 'points at the same object');
|
||||
equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user