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) {
specs: {
options: {
globals: {
afterEach: false,
beforeEach: false,
define: false,
describe: false,
......
......@@ -15,6 +15,7 @@
"test"
],
"dependencies": {
"backbone-seen": "git@gitlab.brainfood.com:brainfood/backbone-seen.git",
"backbone": "~1.1.0",
"backbone-validation": "0.9.1",
"bootstrap": "~3.1.0",
......@@ -22,5 +23,8 @@
"requirejs": "~2.1.10",
"rivets": "~0.6.6",
"underscore": "~1.6.0"
},
"devDependencies": {
"rivets-backbone-adapter": "~1.1.1"
}
}
......
define(['backbone'], function(Backbone) {
'use strict';
return Backbone;
});
......@@ -10,6 +10,11 @@ require = (function() {
deps: [
'jquery'
]
},
rivets: {
deps: [
'jquery'
]
}
},
paths: {
......@@ -18,7 +23,9 @@ require = (function() {
underscore: '../lib/underscore/underscore',
rivets: '../lib/rivets/dist/rivets',
bootstrap: '../lib/bootstrap/dist/js/bootstrap',
jquery: '../lib/jquery/dist/jquery'
jquery: '../lib/jquery/dist/jquery',
'rivets-backbone-adapter': '../lib/rivets-backbone-adapter/rivets-backbone',
'backbone-seen': '../lib/backbone-seen/src/scripts/backbone-seen'
}
};
......
......@@ -85,8 +85,10 @@ define(['rivets', 'bootstrap'], function(rivets) {
var holder = this.validationHolder;
$(this.validationHolder.marker).after(el).remove();
$(el).off('focus', holder.focus).off('blur', holder.blur);
diveIntoObject(this.model, this.keypath, function(obj) {
obj.off('validated', holder.validated);
diveIntoObject(this.observer.target, this.observer.key.path, function(obj) {
if (obj) {
obj.off('validated', holder.validated);
}
});
delete this.validationHolder;
rivetsBinderCall(this, this.args[0], 'unbind', arguments);
......@@ -99,7 +101,9 @@ define(['rivets', 'bootstrap'], function(rivets) {
diveIntoObject(this.observer.target, this.observer.key.path, function(obj, id) {
holder.lastObj = obj;
holder.lastId = id;
obj.on('validated', holder.validated);
if (obj) {
obj.on('validated', holder.validated);
}
});
rivetsBinderCall(this, this.args[0], 'routine', arguments);
}
......
define(function(require) {
'use strict';
var $ = require('jquery');
window.jQuery = $;
var RivetsErrorBinder = require('rivets-error-binder');
var _ = require('underscore');
var Backbone = require('backbone');
var rivets = require('rivets');
require('backbone-validation');
var BackboneSeen = require('backbone-seen');
require('rivets-backbone-adapter');
_.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
//rivets.config.rootInterface = ':';
describe('RivetsErrorBinder', function() {
it('exists', function() {
expect(RivetsErrorBinder).toBeUndefined();
});
});
describe('RivetsErrorBinder', function() {
var Model, Collection;
var scope;
var test;
var view;
beforeEach(function() {
jasmine.Clock.useMock();
Model = BackboneSeen.mixin(Backbone.Model.extend());
Collection = Backbone.Collection.extend({model: Model});
scope = new Model({
test: test = new Model({
constant: 'CONSTANT'
})
});
scope.toString = function() {
return '[Model: test-scope]';
};
test.validation = {
constant: {required: true}
};
});
afterEach(function() {
view.unbind();
});
it('existing', function() {
var $node = $($.parseHTML('<div><form><input id="_1" rv-error-value="test:constant" /></form></div>'));
$(document).find('body').append($node[0]);
var $1 = $node.find('#_1');
expect($1.length).toEqual(1);
expect($1.val()).toEqual('');
view = rivets.bind($node, scope.attributes);
expect(view).toBeTruthy();
expect($1.val()).toEqual('CONSTANT');
//expect($node.html()).toBe('');
test.set('constant', 'one');
expect($1.val()).toEqual('one');
test.set('constant', '');
expect($1.val()).toEqual('');
test.set('constant', 'CONSTANT');
expect($1.val()).toEqual('CONSTANT');
$1.focus().val('one').change().blur();
jasmine.Clock.tick(1);
expect(test.get('constant')).toEqual('one');
$1.focus().val('').change().blur();
jasmine.Clock.tick(1);
expect(test.get('constant')).toEqual('');
jasmine.Clock.tick(1);
});
it('missing', function() {
var $node = $($.parseHTML('<div><form><input id="_1" rv-error-value="test:missing:child" /></form></div>'));
$(document).find('body').append($node[0]);
var $1 = $node.find('#_1');
expect($1.length).toEqual(1);
expect($1.val()).toEqual('');
view = rivets.bind($node, scope.attributes);
expect(view).toBeTruthy();
expect($1.val()).toEqual('');
$1.focus().val('one').change().blur();
jasmine.Clock.tick(1);
});
});
});
......