8b43b4d6 by Adam Heath

Test cases work now; this also fixes one unbind bug.

1 parent 219d150c
...@@ -206,6 +206,7 @@ module.exports = function (grunt) { ...@@ -206,6 +206,7 @@ module.exports = function (grunt) {
206 specs: { 206 specs: {
207 options: { 207 options: {
208 globals: { 208 globals: {
209 afterEach: false,
209 beforeEach: false, 210 beforeEach: false,
210 define: false, 211 define: false,
211 describe: false, 212 describe: false,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "test" 15 "test"
16 ], 16 ],
17 "dependencies": { 17 "dependencies": {
18 "backbone-seen": "git@gitlab.brainfood.com:brainfood/backbone-seen.git",
18 "backbone": "~1.1.0", 19 "backbone": "~1.1.0",
19 "backbone-validation": "0.9.1", 20 "backbone-validation": "0.9.1",
20 "bootstrap": "~3.1.0", 21 "bootstrap": "~3.1.0",
...@@ -22,5 +23,8 @@ ...@@ -22,5 +23,8 @@
22 "requirejs": "~2.1.10", 23 "requirejs": "~2.1.10",
23 "rivets": "~0.6.6", 24 "rivets": "~0.6.6",
24 "underscore": "~1.6.0" 25 "underscore": "~1.6.0"
26 },
27 "devDependencies": {
28 "rivets-backbone-adapter": "~1.1.1"
25 } 29 }
26 } 30 }
......
1 define(['backbone'], function(Backbone) {
2 'use strict';
3 return Backbone;
4 });
...@@ -10,6 +10,11 @@ require = (function() { ...@@ -10,6 +10,11 @@ require = (function() {
10 deps: [ 10 deps: [
11 'jquery' 11 'jquery'
12 ] 12 ]
13 },
14 rivets: {
15 deps: [
16 'jquery'
17 ]
13 } 18 }
14 }, 19 },
15 paths: { 20 paths: {
...@@ -18,7 +23,9 @@ require = (function() { ...@@ -18,7 +23,9 @@ require = (function() {
18 underscore: '../lib/underscore/underscore', 23 underscore: '../lib/underscore/underscore',
19 rivets: '../lib/rivets/dist/rivets', 24 rivets: '../lib/rivets/dist/rivets',
20 bootstrap: '../lib/bootstrap/dist/js/bootstrap', 25 bootstrap: '../lib/bootstrap/dist/js/bootstrap',
21 jquery: '../lib/jquery/dist/jquery' 26 jquery: '../lib/jquery/dist/jquery',
27 'rivets-backbone-adapter': '../lib/rivets-backbone-adapter/rivets-backbone',
28 'backbone-seen': '../lib/backbone-seen/src/scripts/backbone-seen'
22 } 29 }
23 }; 30 };
24 31
......
...@@ -85,8 +85,10 @@ define(['rivets', 'bootstrap'], function(rivets) { ...@@ -85,8 +85,10 @@ define(['rivets', 'bootstrap'], function(rivets) {
85 var holder = this.validationHolder; 85 var holder = this.validationHolder;
86 $(this.validationHolder.marker).after(el).remove(); 86 $(this.validationHolder.marker).after(el).remove();
87 $(el).off('focus', holder.focus).off('blur', holder.blur); 87 $(el).off('focus', holder.focus).off('blur', holder.blur);
88 diveIntoObject(this.model, this.keypath, function(obj) { 88 diveIntoObject(this.observer.target, this.observer.key.path, function(obj) {
89 if (obj) {
89 obj.off('validated', holder.validated); 90 obj.off('validated', holder.validated);
91 }
90 }); 92 });
91 delete this.validationHolder; 93 delete this.validationHolder;
92 rivetsBinderCall(this, this.args[0], 'unbind', arguments); 94 rivetsBinderCall(this, this.args[0], 'unbind', arguments);
...@@ -99,7 +101,9 @@ define(['rivets', 'bootstrap'], function(rivets) { ...@@ -99,7 +101,9 @@ define(['rivets', 'bootstrap'], function(rivets) {
99 diveIntoObject(this.observer.target, this.observer.key.path, function(obj, id) { 101 diveIntoObject(this.observer.target, this.observer.key.path, function(obj, id) {
100 holder.lastObj = obj; 102 holder.lastObj = obj;
101 holder.lastId = id; 103 holder.lastId = id;
104 if (obj) {
102 obj.on('validated', holder.validated); 105 obj.on('validated', holder.validated);
106 }
103 }); 107 });
104 rivetsBinderCall(this, this.args[0], 'routine', arguments); 108 rivetsBinderCall(this, this.args[0], 'routine', arguments);
105 } 109 }
......
1 define(function(require) { 1 define(function(require) {
2 'use strict'; 2 'use strict';
3 3
4 var $ = require('jquery');
5 window.jQuery = $;
4 var RivetsErrorBinder = require('rivets-error-binder'); 6 var RivetsErrorBinder = require('rivets-error-binder');
7 var _ = require('underscore');
8 var Backbone = require('backbone');
9 var rivets = require('rivets');
5 require('backbone-validation'); 10 require('backbone-validation');
11 var BackboneSeen = require('backbone-seen');
12 require('rivets-backbone-adapter');
13 _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
14 //rivets.config.rootInterface = ':';
6 15
7 describe('RivetsErrorBinder', function() { 16 describe('RivetsErrorBinder', function() {
8 it('exists', function() { 17 it('exists', function() {
9 expect(RivetsErrorBinder).toBeUndefined(); 18 expect(RivetsErrorBinder).toBeUndefined();
10 }); 19 });
11 }); 20 });
21 describe('RivetsErrorBinder', function() {
22 var Model, Collection;
23 var scope;
24 var test;
25 var view;
26 beforeEach(function() {
27 jasmine.Clock.useMock();
28 Model = BackboneSeen.mixin(Backbone.Model.extend());
29 Collection = Backbone.Collection.extend({model: Model});
30
31 scope = new Model({
32 test: test = new Model({
33 constant: 'CONSTANT'
34 })
35 });
36 scope.toString = function() {
37 return '[Model: test-scope]';
38 };
39 test.validation = {
40 constant: {required: true}
41 };
42 });
43 afterEach(function() {
44 view.unbind();
45 });
46
47
48 it('existing', function() {
49 var $node = $($.parseHTML('<div><form><input id="_1" rv-error-value="test:constant" /></form></div>'));
50 $(document).find('body').append($node[0]);
51 var $1 = $node.find('#_1');
52 expect($1.length).toEqual(1);
53 expect($1.val()).toEqual('');
54 view = rivets.bind($node, scope.attributes);
55 expect(view).toBeTruthy();
56 expect($1.val()).toEqual('CONSTANT');
57 //expect($node.html()).toBe('');
58 test.set('constant', 'one');
59 expect($1.val()).toEqual('one');
60 test.set('constant', '');
61 expect($1.val()).toEqual('');
62 test.set('constant', 'CONSTANT');
63 expect($1.val()).toEqual('CONSTANT');
64
65 $1.focus().val('one').change().blur();
66 jasmine.Clock.tick(1);
67 expect(test.get('constant')).toEqual('one');
68
69 $1.focus().val('').change().blur();
70 jasmine.Clock.tick(1);
71 expect(test.get('constant')).toEqual('');
72 jasmine.Clock.tick(1);
73 });
74 it('missing', function() {
75 var $node = $($.parseHTML('<div><form><input id="_1" rv-error-value="test:missing:child" /></form></div>'));
76 $(document).find('body').append($node[0]);
77 var $1 = $node.find('#_1');
78 expect($1.length).toEqual(1);
79 expect($1.val()).toEqual('');
80 view = rivets.bind($node, scope.attributes);
81 expect(view).toBeTruthy();
82 expect($1.val()).toEqual('');
83
84 $1.focus().val('one').change().blur();
85 jasmine.Clock.tick(1);
86 });
87 });
12 }); 88 });
......