Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets-error-binder
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
8b43b4d6
authored
2014-04-14 16:08:32 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Test cases work now; this also fixes one unbind bug.
1 parent
219d150c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
2 deletions
Gruntfile.js
bower.json
src/scripts/Backbone.js
src/scripts/config.js
src/scripts/rivets-error-binder.js
test/specs/rivets-error-binder.spec.js
Gruntfile.js
View file @
8b43b4d
...
...
@@ -206,6 +206,7 @@ module.exports = function (grunt) {
specs
:
{
options
:
{
globals
:
{
afterEach
:
false
,
beforeEach
:
false
,
define
:
false
,
describe
:
false
,
...
...
bower.json
View file @
8b43b4d
...
...
@@ -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"
}
}
...
...
src/scripts/Backbone.js
0 → 100644
View file @
8b43b4d
define
([
'backbone'
],
function
(
Backbone
)
{
'use strict'
;
return
Backbone
;
});
src/scripts/config.js
View file @
8b43b4d
...
...
@@ -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'
}
};
...
...
src/scripts/rivets-error-binder.js
View file @
8b43b4d
...
...
@@ -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
)
{
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
;
if
(
obj
)
{
obj
.
on
(
'validated'
,
holder
.
validated
);
}
});
rivetsBinderCall
(
this
,
this
.
args
[
0
],
'routine'
,
arguments
);
}
...
...
test/specs/rivets-error-binder.spec.js
View file @
8b43b4d
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
);
});
});
});
...
...
Please
register
or
sign in
to post a comment