9542d73d by Adam Heath

Full test coverage on Ordering, few more bugs found as well.

1 parent 476e2d53
1 define(function(require) { 1 define(function(require) {
2 'use strict'; 2 'use strict';
3 var _ = require('underscore');
3 var Backbone = require('backbone'); 4 var Backbone = require('backbone');
4 5
5 var Ordering = Backbone.Model.extend({ 6 var Ordering = Backbone.Model.extend({
7 constructor: function(data, options) {
8 options = _.extend({}, options, {parse: true});
9 return Backbone.Model.call(this, data, options);
10 },
6 defaults: function defaults() { 11 defaults: function defaults() {
7 return { 12 return {
8 value: null, 13 value: null,
......
...@@ -7,9 +7,33 @@ define(function(require) { ...@@ -7,9 +7,33 @@ define(function(require) {
7 it('loads', function() { 7 it('loads', function() {
8 expect(Ordering).toBeDefined(); 8 expect(Ordering).toBeDefined();
9 }); 9 });
10 it('items are different instances', function() { 10 describe(':items', function() {
11 var o1 = new Ordering(), o2 = new Ordering(); 11 var items = [
12 expect(o1.get('items')).not.toBe(o2.get('items')); 12 {value: 'a', label: 'A'},
13 {value: 'b', label: 'B'},
14 {value: 'c', label: 'C'},
15 ];
16 it('default value is not shared globally', function() {
17 var o1 = new Ordering(), o2 = new Ordering();
18 expect(o1.get('items')).not.toBe(o2.get('items'));
19 });
20 it('array is converted to collection without specifying parse', function() {
21 var o = new Ordering({items: items});
22 expect(o.get('items')).not.toBe(items);
23 });
24 it('same passed value is not shared globally', function() {
25 var o1 = new Ordering({items: items}, {parse: false});
26 var o2 = new Ordering({items: items}, {parse: false});
27 expect(o1.get('items')).not.toBe(o2.get('items'));
28 });
29 it(':value is first item', function() {
30 var o = new Ordering({items: items});
31 expect(o.get('value')).toBe('a');
32 });
33 it(':value is not changed', function() {
34 var o = new Ordering({items: items, value: '1'});
35 expect(o.get('value')).toBe('1');
36 });
13 }); 37 });
14 }); 38 });
15 }); 39 });
......