2015-04-08 14:17:21 -04:00
|
|
|
import Model from 'discourse/models/model';
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("model:discourse");
|
2013-09-26 13:03:43 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", assert => {
|
2013-09-26 13:03:43 -04:00
|
|
|
var firstObject = {id: "id_1", foo: "foo_1"};
|
|
|
|
var secondObject = {id: "id_2", foo: "foo_2"};
|
|
|
|
|
2015-04-08 14:17:21 -04:00
|
|
|
var actual = Model.extractByKey([firstObject, secondObject], Ember.Object);
|
2013-09-26 13:03:43 -04:00
|
|
|
var expected = {
|
|
|
|
id_1: Ember.Object.create(firstObject),
|
|
|
|
id_2: Ember.Object.create(secondObject)
|
|
|
|
};
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(_.isEqual(actual, expected));
|
2013-09-26 13:03:43 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("extractByKey: returns an empty hash if there isn't anything to convert", assert => {
|
|
|
|
assert.deepEqual(Model.extractByKey(), {}, "when called without parameters");
|
|
|
|
assert.deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
|
2017-07-14 08:27:28 -04:00
|
|
|
});
|