-
Notifications
You must be signed in to change notification settings - Fork 301
/
mixin.js
81 lines (65 loc) · 2.17 KB
/
mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
buster.testCase("Mixin validation", {
setUp: function() {
this.origPrototype = _.clone(Backbone.Model.prototype);
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
var Model = Backbone.Model.extend({
validation: {
name: function(val) {
if(!val) {
return 'error';
}
}
}
});
this.model = new Model();
},
tearDown: function() {
Backbone.Model.prototype = this.origPrototype;
},
"isValid is undefined when no validation has occurred": function() {
refute.defined(this.model.isValid());
},
"isValid is false when model is invalid": function() {
assert.equals(false, this.model.isValid(true));
},
"isValid is true when model is valid": function() {
this.model.set({name: 'name'},{silent:true});
assert.equals(true, this.model.isValid(true));
},
"refutes setting invalid value": function() {
refute(this.model.set({name: ''}));
},
"succeeds setting valid value": function() {
assert(this.model.set({name: 'name'}));
},
"when forcing update succeeds setting invalid value": function() {
if(Backbone.VERSION === '0.5.3') {
refute(this.model.set({name:''}, {forceUpdate: true}));
} else {
assert(this.model.set({name:''}, {forceUpdate: true}));
}
},
"when forcing update globally": {
setUp: function() {
Backbone.Validation.configure({
forceUpdate: true
});
},
tearDown: function() {
Backbone.Validation.configure({
forceUpdate: false
});
},
"succeeds setting invalid value when forcing update globally": function() {
assert(this.model.set({name:''}));
}
},
"when setting attribute on model without validation": {
setUp: function(){
this.model = new Backbone.Model();
},
"it should not complain": function() {
assert(this.model.set({someAttr: 'someValue'}));
}
}
});