9542d73d by Adam Heath

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

1 parent 476e2d53
define(function(require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var Ordering = Backbone.Model.extend({
constructor: function(data, options) {
options = _.extend({}, options, {parse: true});
return Backbone.Model.call(this, data, options);
},
defaults: function defaults() {
return {
value: null,
......
......@@ -7,9 +7,33 @@ define(function(require) {
it('loads', function() {
expect(Ordering).toBeDefined();
});
it('items are different instances', function() {
var o1 = new Ordering(), o2 = new Ordering();
expect(o1.get('items')).not.toBe(o2.get('items'));
describe(':items', function() {
var items = [
{value: 'a', label: 'A'},
{value: 'b', label: 'B'},
{value: 'c', label: 'C'},
];
it('default value is not shared globally', function() {
var o1 = new Ordering(), o2 = new Ordering();
expect(o1.get('items')).not.toBe(o2.get('items'));
});
it('array is converted to collection without specifying parse', function() {
var o = new Ordering({items: items});
expect(o.get('items')).not.toBe(items);
});
it('same passed value is not shared globally', function() {
var o1 = new Ordering({items: items}, {parse: false});
var o2 = new Ordering({items: items}, {parse: false});
expect(o1.get('items')).not.toBe(o2.get('items'));
});
it(':value is first item', function() {
var o = new Ordering({items: items});
expect(o.get('value')).toBe('a');
});
it(':value is not changed', function() {
var o = new Ordering({items: items, value: '1'});
expect(o.get('value')).toBe('1');
});
});
});
});
......