Skip to content

Commit

Permalink
Merge pull request #5213 from pangratz/promise-array-meta
Browse files Browse the repository at this point in the history
[BUGFIX beta] proxy `meta` on PromiseArray
  • Loading branch information
bmac authored Oct 9, 2017
2 parents 0d0fbf9 + 7ac68ad commit fe4ac46
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addon/-private/system/promise-proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ember from 'ember';
import { assert } from '@ember/debug';

const { get , RSVP: { Promise }} = Ember;
const { computed: { reads } } = Ember;

/**
A `PromiseArray` is an object that acts like both an `Ember.Array`
Expand Down Expand Up @@ -32,7 +33,9 @@ const { get , RSVP: { Promise }} = Ember;
@extends Ember.ArrayProxy
@uses Ember.PromiseProxyMixin
*/
export const PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);
export const PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin, {
meta: reads('content.meta')
});

/**
A `PromiseObject` is an object that acts like both an `Ember.Object`
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/store/query-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import setupStore from 'dummy/tests/helpers/store';
import Ember from 'ember';
import RSVP from 'rsvp';

import { module, test } from 'qunit';

import DS from 'ember-data';

var Person, store, env;
var run = Ember.run;

module("integration/store/query", {
beforeEach() {
Person = DS.Model.extend();

env = setupStore({
person: Person
});

store = env.store;
},

afterEach() {
run(store, 'destroy');
}
});

test("meta is proxied correctly on the PromiseArray", function(assert) {
let defered = RSVP.defer();

env.registry.register('adapter:person', DS.Adapter.extend({
query(store, type, query) {
return defered.promise;
}
}));

let result;
run(function() {
result = store.query('person', {});
});

assert.equal(result.get('meta.foo'), undefined);

run(function() {
defered.resolve({ data: [], meta: { foo: 'bar' } });
});

assert.equal(result.get('meta.foo'), 'bar');
});

0 comments on commit fe4ac46

Please sign in to comment.