spec/javascripts/TransistorBackboneCollectionSpec.js in transistor-0.1.8 vs spec/javascripts/TransistorBackboneCollectionSpec.js in transistor-0.1.9
- old
+ new
@@ -43,17 +43,32 @@
expect(function () {
collection.set({})
}).toThrow(new Error('BackboneCollection is not mutable by user.'));
});
+
+ it('fails also on a model', function () {
+ radio.trigger('news', 'init', [{id: 100, a:2, b:3}, {id: 101, a:12, b:23}]);
+
+ var model = collection.get(100);
+
+ expect(function () {
+ model.set('a', 0);
+ }).toThrow(new Error('BackboneCollection is not mutable by user. The model with id 100 has been changed'));
+
+ assertEqual(2, collection.get(100)get('a'));
+ });
});
describe('write access via control', function () {
beforeEach(function () {
control = (function () {
var calls = [],
- record = function (call, args) { calls.push([call, args]) };
+ record = function (call, args) {
+ console.log('call', call, args)
+ calls.push([call, args])
+ };
return {
set: function () { record("set", arguments); },
insert: function () { record("insert", arguments); },
update: function () { record("update", arguments); },
remove: function () { record("remove", arguments); },
@@ -102,9 +117,21 @@
assertEqual(control.calls, [
['set', ['news', [{a: 12}, {b: 13}]]]
]);
});
+
+ it('delegates model change events to update', function () {
+ radio.trigger('news', 'init', [{id: 100, a:2, b:3}, {id: 101, a:12, b:23}]);
+
+ var model = collection.get(101);
+
+ model.set('a', 24);
+
+ assertEqual(control.calls, [
+ ['update', ['news', 101, {a: 24, b:23}]]
+ ]);
+ })
});
describe("init event", function () {
it("maps arg 'array' to a clear and set", function () {
radio.trigger('news', 'init', [{a:2, b:3}, {a:12, b:23}]);