discourse/test/javascripts/models/model-test.js.es6

27 lines
907 B
Plaintext
Raw Normal View History

2015-04-09 02:17:21 +08:00
import Presence from 'discourse/mixins/presence';
import Model from 'discourse/models/model';
2013-09-27 01:03:43 +08:00
module("Discourse.Model");
2015-04-09 02:17:21 +08:00
test("mixes in Presence", function() {
ok(Presence.detect(Model.create()));
2013-09-27 01:03:43 +08:00
});
test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() {
var firstObject = {id: "id_1", foo: "foo_1"};
var secondObject = {id: "id_2", foo: "foo_2"};
2015-04-09 02:17:21 +08:00
var actual = Model.extractByKey([firstObject, secondObject], Ember.Object);
2013-09-27 01:03:43 +08:00
var expected = {
id_1: Ember.Object.create(firstObject),
id_2: Ember.Object.create(secondObject)
};
ok(_.isEqual(actual, expected));
});
test("extractByKey: returns an empty hash if there isn't anything to convert", function() {
2015-04-09 02:17:21 +08:00
deepEqual(Model.extractByKey(), {}, "when called without parameters");
deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
2013-09-27 01:03:43 +08:00
});