Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 5677d65f
authored
Feb 19, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1387 from janmeier/depsUpdate
Updated dependencies
2 parents
ff4f76f1
1d88b608
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
185 additions
and
109 deletions
lib/dao-validator.js
lib/sequelize.js
package.json
test/dao-factory/create.test.js
test/dao.test.js
test/dao.validations.test.js
test/promise.test.js
lib/dao-validator.js
View file @
5677d65
var
Validator
=
require
(
"validator"
)
var
Validator
=
require
(
"validator"
)
,
Utils
=
require
(
"./utils"
)
,
Utils
=
require
(
"./utils"
)
// Backwards compat for people using old validation function
// We cannot use .extend, since it coerces the first arg to string
Validator
.
notNull
=
function
(
val
)
{
return
[
null
,
undefined
].
indexOf
(
val
)
===
-
1
}
// https://github.com/chriso/validator.js/blob/1.5.0/lib/validators.js
Validator
.
extend
(
'notEmpty'
,
function
(
str
)
{
return
!
str
.
match
(
/^
[\s\t\r\n]
*$/
);
})
Validator
.
extend
(
'len'
,
function
(
str
,
min
,
max
)
{
return
this
.
isLength
(
str
,
min
,
max
)
})
Validator
.
extend
(
'isUrl'
,
function
(
str
)
{
return
this
.
isURL
(
str
)
})
Validator
.
extend
(
'isIPv6'
,
function
(
str
)
{
return
this
.
isIP
(
str
,
6
)
})
Validator
.
extend
(
'isIPv4'
,
function
(
str
)
{
return
this
.
isIP
(
str
,
4
)
})
Validator
.
extend
(
'notIn'
,
function
(
str
,
values
)
{
return
!
this
.
isIn
(
str
,
values
)
})
Validator
.
extend
(
'regex'
,
function
(
str
,
pattern
,
modifiers
)
{
str
+=
''
;
if
(
Object
.
prototype
.
toString
.
call
(
pattern
).
slice
(
8
,
-
1
)
!==
'RegExp'
)
{
pattern
=
new
RegExp
(
pattern
,
modifiers
);
}
return
str
.
match
(
pattern
);
})
Validator
.
extend
(
'notRegex'
,
function
(
str
,
pattern
,
modifiers
)
{
return
!
this
.
regex
(
str
,
pattern
,
modifiers
);
})
Validator
.
extend
(
'isDecimal'
,
function
(
str
)
{
return
str
!==
''
&&
str
.
match
(
/^
(?:
-
?(?:[
0-9
]
+
))?(?:\.[
0-9
]
*
)?(?:[
eE
][\+\-]?(?:[
0-9
]
+
))?
$/
);
})
Validator
.
extend
(
'min'
,
function
(
str
,
val
)
{
var
number
=
parseFloat
(
str
);
return
isNaN
(
number
)
||
number
>=
val
;
})
Validator
.
extend
(
'max'
,
function
(
str
,
val
)
{
var
number
=
parseFloat
(
str
);
return
isNaN
(
number
)
||
number
<=
val
;
})
Validator
.
extend
(
'not'
,
function
(
str
,
pattern
,
modifiers
)
{
return
this
.
notRegex
(
str
,
pattern
,
modifiers
);
})
Validator
.
extend
(
'contains'
,
function
(
str
,
elem
)
{
return
str
.
indexOf
(
elem
)
>=
0
&&
!!
elem
;
})
Validator
.
extend
(
'notContains'
,
function
(
str
,
elem
)
{
return
!
this
.
contains
(
str
,
elem
);
})
Validator
.
extend
(
'is'
,
function
(
str
,
pattern
,
modifiers
)
{
return
this
.
regex
(
str
,
pattern
,
modifiers
);
})
var
DaoValidator
=
module
.
exports
=
function
(
model
,
options
)
{
var
DaoValidator
=
module
.
exports
=
function
(
model
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
options
.
skip
=
options
.
skip
||
[]
options
.
skip
=
options
.
skip
||
[]
this
.
model
=
model
this
.
model
=
model
this
.
options
=
options
this
.
options
=
options
/**
* Expose validator.js to allow users to extend
* @name Validator
*/
this
.
Validator
=
Validator
}
}
DaoValidator
.
prototype
.
validate
=
function
()
{
DaoValidator
.
prototype
.
validate
=
function
()
{
...
@@ -131,16 +211,16 @@ var prepareValidationOfAttribute = function(value, details, validatorType) {
...
@@ -131,16 +211,16 @@ var prepareValidationOfAttribute = function(value, details, validatorType) {
// extract the error msg
// extract the error msg
errorMessage
=
details
.
hasOwnProperty
(
"msg"
)
?
details
.
msg
:
undefined
errorMessage
=
details
.
hasOwnProperty
(
"msg"
)
?
details
.
msg
:
undefined
// check method exists
var
validator
=
Validator
.
check
(
value
,
errorMessage
)
// check if Validator knows that kind of validation test
// check if Validator knows that kind of validation test
if
(
!
Utils
.
_
.
isFunction
(
v
alidator
[
validatorType
]))
{
if
(
!
Utils
.
_
.
isFunction
(
V
alidator
[
validatorType
]))
{
throw
new
Error
(
"Invalid validator function: "
+
validatorType
)
throw
new
Error
(
"Invalid validator function: "
+
validatorType
)
}
}
// bind to validator obj
validatorFunction
=
function
()
{
validatorFunction
=
Utils
.
_
.
bind
(
validator
[
validatorType
],
validator
)
if
(
!
Validator
[
validatorType
].
apply
(
null
,
[
value
].
concat
(
validatorArgs
)))
{
throw
new
Error
(
errorMessage
||
"Validation "
+
validatorType
+
" failed"
)
}
}
}
}
return
{
return
{
...
...
lib/sequelize.js
View file @
5677d65
...
@@ -2,6 +2,7 @@ var url = require("url")
...
@@ -2,6 +2,7 @@ var url = require("url")
,
Path
=
require
(
"path"
)
,
Path
=
require
(
"path"
)
,
Utils
=
require
(
"./utils"
)
,
Utils
=
require
(
"./utils"
)
,
DAOFactory
=
require
(
"./dao-factory"
)
,
DAOFactory
=
require
(
"./dao-factory"
)
,
DAOValidator
=
require
(
"./dao-validator"
)
,
DataTypes
=
require
(
'./data-types'
)
,
DataTypes
=
require
(
'./data-types'
)
,
DAOFactoryManager
=
require
(
"./dao-factory-manager"
)
,
DAOFactoryManager
=
require
(
"./dao-factory-manager"
)
,
QueryInterface
=
require
(
"./query-interface"
)
,
QueryInterface
=
require
(
"./query-interface"
)
...
@@ -136,6 +137,8 @@ module.exports = (function() {
...
@@ -136,6 +137,8 @@ module.exports = (function() {
Sequelize
.
QueryTypes
=
QueryTypes
Sequelize
.
QueryTypes
=
QueryTypes
Sequelize
.
DAOValidator
=
DAOValidator
for
(
var
dataType
in
DataTypes
)
{
for
(
var
dataType
in
DataTypes
)
{
Sequelize
[
dataType
]
=
DataTypes
[
dataType
]
Sequelize
[
dataType
]
=
DataTypes
[
dataType
]
}
}
...
...
package.json
View file @
5677d65
...
@@ -40,36 +40,35 @@
...
@@ -40,36 +40,35 @@
"url"
:
"https://github.com/sequelize/sequelize/issues"
"url"
:
"https://github.com/sequelize/sequelize/issues"
},
},
"dependencies"
:
{
"dependencies"
:
{
"lodash"
:
"~2.2.0"
,
"commander"
:
"~2.1.0"
,
"lodash"
:
"~2.4.0"
,
"underscore.string"
:
"~2.3.0"
,
"underscore.string"
:
"~2.3.0"
,
"lingo"
:
"~0.0.5"
,
"lingo"
:
"~0.0.5"
,
"validator"
:
"~1.5.0"
,
"validator"
:
"~3.2.0"
,
"moment"
:
"~2.4.0"
,
"moment"
:
"~2.5.0"
,
"commander"
:
"~2.0.0"
,
"dottie"
:
"0.0.9-0"
,
"dottie"
:
"0.0.8-0"
,
"toposort-class"
:
"~0.3.0"
,
"toposort-class"
:
"~0.2.0"
,
"generic-pool"
:
"2.0.4"
,
"generic-pool"
:
"2.0.4"
,
"sql"
:
"~0.3
1
.0"
,
"sql"
:
"~0.3
5
.0"
,
"circular-json"
:
"~0.1.5"
,
"circular-json"
:
"~0.1.5"
,
"bluebird"
:
"~
0.11.5
"
,
"bluebird"
:
"~
1.0.0
"
,
"node-uuid"
:
"~1.4.1"
"node-uuid"
:
"~1.4.1"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"sqlite3"
:
"~2.1.12"
,
"sqlite3"
:
"~2.1.12"
,
"mysql"
:
"2.0.1"
,
"mysql"
:
"2.0.1"
,
"pg"
:
"~2.8.1"
,
"pg"
:
"~2.8.1"
,
"watchr"
:
"~2.4.3"
,
"watchr"
:
"~2.4.11"
,
"yuidocjs"
:
"~0.3.36"
,
"chai"
:
"~1.9.0"
,
"chai"
:
"~1.8.0"
,
"mocha"
:
"~1.17.0"
,
"mocha"
:
"~1.13.0"
,
"chai-datetime"
:
"~1.1.1"
,
"chai-datetime"
:
"~1.1.1"
,
"sinon"
:
"~1.
7.3
"
,
"sinon"
:
"~1.
8.1
"
,
"mariasql"
:
"0.1.20"
,
"mariasql"
:
"0.1.20"
,
"chai-spies"
:
"~0.5.1"
,
"chai-spies"
:
"~0.5.1"
,
"lcov-result-merger"
:
"0.0.2"
,
"lcov-result-merger"
:
"0.0.2"
,
"istanbul"
:
"~0.1.45"
,
"istanbul"
:
"~0.1.45"
,
"coveralls"
:
"~2.
5.0
"
,
"coveralls"
:
"~2.
7.1
"
,
"async"
:
"~0.2.
9
"
,
"async"
:
"~0.2.
10
"
,
"coffee-script"
:
"~1.7.1"
"coffee-script"
:
"~1.7.1"
},
},
"keywords"
:
[
"keywords"
:
[
...
...
test/dao-factory/create.test.js
View file @
5677d65
...
@@ -409,7 +409,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -409,7 +409,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it
(
"raises an error if saving an empty string into a column allowing null or URL"
,
function
(
done
)
{
it
(
"raises an error if saving an empty string into a column allowing null or URL"
,
function
(
done
)
{
var
StringIsNullOrUrl
=
this
.
sequelize
.
define
(
'StringIsNullOrUrl'
,
{
var
StringIsNullOrUrl
=
this
.
sequelize
.
define
(
'StringIsNullOrUrl'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
true
,
validate
:
{
isU
rl
:
true
}
}
str
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
true
,
validate
:
{
isU
RL
:
true
}
}
})
})
this
.
sequelize
.
options
.
omitNull
=
false
this
.
sequelize
.
options
.
omitNull
=
false
...
@@ -423,7 +423,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -423,7 +423,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
StringIsNullOrUrl
.
create
({
str
:
''
}).
error
(
function
(
err
)
{
StringIsNullOrUrl
.
create
({
str
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
exist
expect
(
err
).
to
.
exist
expect
(
err
.
str
[
0
]).
to
.
match
(
/
Invalid URL
: str/
)
expect
(
err
.
str
[
0
]).
to
.
match
(
/
Validation isURL failed
: str/
)
done
()
done
()
})
})
...
@@ -961,7 +961,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -961,7 +961,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{
name
:
'foo'
,
code
:
'123'
},
{
name
:
'foo'
,
code
:
'123'
},
{
code
:
'1234'
},
{
code
:
'1234'
},
{
name
:
'bar'
,
code
:
'1'
}
{
name
:
'bar'
,
code
:
'1'
}
],
{
validate
:
true
}).
error
(
function
(
errors
)
{
],
{
validate
:
true
}).
error
(
function
(
errors
)
{
expect
(
errors
).
to
.
not
.
be
.
null
expect
(
errors
).
to
.
not
.
be
.
null
expect
(
errors
).
to
.
be
.
instanceof
(
Array
)
expect
(
errors
).
to
.
be
.
instanceof
(
Array
)
expect
(
errors
).
to
.
have
.
length
(
2
)
expect
(
errors
).
to
.
have
.
length
(
2
)
...
@@ -969,7 +969,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -969,7 +969,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect
(
errors
[
0
].
errors
.
name
[
0
]).
to
.
equal
(
'name cannot be null'
)
expect
(
errors
[
0
].
errors
.
name
[
0
]).
to
.
equal
(
'name cannot be null'
)
expect
(
errors
[
1
].
record
.
name
).
to
.
equal
(
'bar'
)
expect
(
errors
[
1
].
record
.
name
).
to
.
equal
(
'bar'
)
expect
(
errors
[
1
].
record
.
code
).
to
.
equal
(
'1'
)
expect
(
errors
[
1
].
record
.
code
).
to
.
equal
(
'1'
)
expect
(
errors
[
1
].
errors
.
code
[
0
]).
to
.
equal
(
'
String is not in range
: code'
)
expect
(
errors
[
1
].
errors
.
code
[
0
]).
to
.
equal
(
'
Validation len failed
: code'
)
done
()
done
()
})
})
})
})
...
...
test/dao.test.js
View file @
5677d65
...
@@ -853,7 +853,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -853,7 +853,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
err
).
to
.
be
.
instanceof
(
Object
)
expect
(
err
).
to
.
be
.
instanceof
(
Object
)
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
expect
(
err
.
validateTest
[
0
]).
to
.
exist
expect
(
err
.
validateTest
[
0
]).
to
.
exist
expect
(
err
.
validateTest
[
0
]
.
indexOf
(
'Invalid integer'
)).
to
.
be
.
above
(
-
1
)
expect
(
err
.
validateTest
[
0
]
).
to
.
equal
(
'Validation isInt failed: validateTest'
)
done
()
done
()
})
})
})
})
...
@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
err
.
validateTest
).
to
.
exist
expect
(
err
.
validateTest
).
to
.
exist
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
expect
(
err
.
validateTest
[
0
]).
to
.
exist
expect
(
err
.
validateTest
[
0
]).
to
.
exist
expect
(
err
.
validateTest
[
0
]
.
indexOf
(
'Invalid integer:'
)).
to
.
be
.
above
(
-
1
)
expect
(
err
.
validateTest
[
0
]
).
to
.
equal
(
'Validation isInt failed: validateTest'
)
done
()
done
()
})
})
})
})
...
...
test/dao.validations.test.js
View file @
5677d65
...
@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -69,7 +69,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
}
,
notNull
:
{
,
notNull
:
{
fail
:
null
,
fail
:
null
,
pass
:
0
pass
:
''
}
}
,
isNull
:
{
,
isNull
:
{
fail
:
0
,
fail
:
0
,
...
@@ -104,6 +104,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -104,6 +104,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
fail
:
"a"
,
fail
:
"a"
,
pass
:
"0"
pass
:
"0"
}
}
,
isLength
:
{
spec
:
{
args
:
[
2
,
4
]
},
fail
:
[
"1"
,
"12345"
],
pass
:
[
"12"
,
"123"
,
"1234"
],
raw
:
true
}
,
len
:
{
,
len
:
{
spec
:
{
args
:
[
2
,
4
]
},
spec
:
{
args
:
[
2
,
4
]
},
fail
:
[
"1"
,
"12345"
],
fail
:
[
"1"
,
"12345"
],
...
@@ -128,12 +134,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -128,12 +134,12 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
,
isAfter
:
{
,
isAfter
:
{
spec
:
{
args
:
"2011-11-05"
},
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-04"
,
fail
:
"2011-11-04"
,
pass
:
"2011-11-0
5
"
pass
:
"2011-11-0
6
"
}
}
,
isBefore
:
{
,
isBefore
:
{
spec
:
{
args
:
"2011-11-05"
},
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-06"
,
fail
:
"2011-11-06"
,
pass
:
"2011-11-0
5
"
pass
:
"2011-11-0
4
"
}
}
,
isIn
:
{
,
isIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
spec
:
{
args
:
"abcdefghijk"
},
...
@@ -150,106 +156,94 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -150,106 +156,94 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
fail
:
"24"
,
fail
:
"24"
,
pass
:
"23"
pass
:
"23"
}
}
,
max
$
:
{
spec
:
23
,
fail
:
"24"
,
pass
:
"23"
}
,
min
:
{
,
min
:
{
spec
:
{
args
:
23
},
spec
:
{
args
:
23
},
fail
:
"22"
,
fail
:
"22"
,
pass
:
"23"
pass
:
"23"
}
}
,
min
$
:
{
spec
:
23
,
fail
:
"22"
,
pass
:
"23"
}
,
isArray
:
{
fail
:
22
,
pass
:
[
22
]
}
,
isCreditCard
:
{
,
isCreditCard
:
{
fail
:
"401288888888188f"
,
fail
:
"401288888888188f"
,
pass
:
"4012888888881881"
pass
:
"4012888888881881"
}
}
}
}
for
(
var
validator
in
checks
)
{
var
checkValidator
=
function
(
validator
,
validatorDetails
)
{
if
(
checks
.
hasOwnProperty
(
validator
))
{
validator
=
validator
.
replace
(
/
\$
$/
,
''
)
validator
=
validator
.
replace
(
/
\$
$/
,
''
)
var
validatorDetails
=
checks
[
validator
]
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
}
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
//////////////////////////
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
// test the error cases //
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
//////////////////////////
}
for
(
var
i
=
0
;
i
<
validatorDetails
.
fail
.
length
;
i
++
)
{
var
failingValue
=
validatorDetails
.
fail
[
i
]
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
(
done
)
{
var
validations
=
{}
,
message
=
validator
+
"("
+
failingValue
+
")"
//////////////////////////
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
// test the error cases //
validations
[
validator
]
=
validatorDetails
.
spec
//////////////////////////
}
else
{
for
(
var
i
=
0
;
i
<
validatorDetails
.
fail
.
length
;
i
++
)
{
validations
[
validator
]
=
{}
var
failingValue
=
validatorDetails
.
fail
[
i
]
}
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
(
done
)
{
validations
[
validator
].
msg
=
message
var
validations
=
{}
,
message
=
validator
+
"("
+
failingValue
+
")"
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
validations
[
validator
]
=
validatorDetails
.
spec
name
:
{
}
else
{
type
:
Sequelize
.
STRING
,
validat
ions
[
validator
]
=
{}
validat
e
:
validations
}
}
})
validations
[
validator
].
msg
=
message
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
,
errors
=
failingUser
.
validate
()
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
{
expect
(
errors
).
not
.
to
.
be
.
null
type
:
Sequelize
.
STRING
,
expect
(
errors
).
to
.
eql
({
name
:
[
message
]
})
validate
:
validations
done
()
}
})
})
}
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
////////////////////////////
,
errors
=
failingUser
.
validate
()
// test the success cases //
////////////////////////////
expect
(
errors
).
not
.
to
.
be
.
null
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
expect
(
errors
).
to
.
eql
({
name
:
[
message
]
})
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
done
()
})
}
////////////////////////////
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
(
done
)
{
// test the success cases //
var
validations
=
{}
////////////////////////////
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
(
done
)
{
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
var
validations
=
{}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
validations
[
validator
]
=
validatorDetails
.
spec
name
:
{
}
else
{
type
:
Sequelize
.
STRING
,
validat
ions
[
validator
]
=
{}
validat
e
:
validations
}
}
})
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
expect
(
successfulUser
.
validate
()).
to
.
be
.
null
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
done
()
name
:
{
})
type
:
Sequelize
.
STRING
,
}
validate
:
validations
}
}
})
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
for
(
var
validator
in
checks
)
{
expect
(
successfulUser
.
validate
()).
to
.
be
.
null
if
(
checks
.
hasOwnProperty
(
validator
))
{
done
()
checkValidator
(
validator
,
checks
[
validator
])
})
}
}
}
}
}
...
@@ -297,7 +291,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -297,7 +291,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'
String is empty: name'
,
'String is empty
: name'
]
})
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'
Validation notEmpty failed
: name'
]
})
done
()
done
()
})
})
})
})
...
@@ -318,7 +312,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -318,7 +312,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'
String is empty: name'
,
'String is empty
: name'
]
})
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'
Validation notEmpty failed
: name'
]
})
done
()
done
()
})
})
})
})
...
@@ -389,7 +383,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -389,7 +383,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
id
:
[
'
Invalid integer
: id'
]})
expect
(
err
).
to
.
deep
.
equal
({
id
:
[
'
Validation isInt failed
: id'
]})
done
()
done
()
})
})
})
})
...
@@ -560,7 +554,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -560,7 +554,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
expect
(
errors
).
not
.
to
.
be
.
null
expect
(
errors
).
not
.
to
.
be
.
null
expect
(
errors
.
field
).
to
.
have
.
length
(
1
)
expect
(
errors
.
field
).
to
.
have
.
length
(
1
)
expect
(
errors
.
field
[
0
]).
to
.
equal
(
"
Unexpected value or invalid argument
: field"
)
expect
(
errors
.
field
[
0
]).
to
.
equal
(
"
Validation isIn failed
: field"
)
})
})
it
(
'skips validations for the given fields'
,
function
()
{
it
(
'skips validations for the given fields'
,
function
()
{
...
...
test/promise.test.js
View file @
5677d65
...
@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
expect
(
err
).
to
.
be
.
an
(
"object"
)
expect
(
err
).
to
.
be
.
an
(
"object"
)
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
expect
(
err
.
validateTest
[
0
]).
to
.
be
.
ok
expect
(
err
.
validateTest
[
0
]).
to
.
be
.
ok
expect
(
err
.
validateTest
[
0
]
.
indexOf
(
'Invalid integer'
)).
to
.
be
.
greaterThan
(
-
1
)
expect
(
err
.
validateTest
[
0
]
).
to
.
equal
(
'Validation isInt failed: validateTest'
)
done
()
done
()
});
});
})
})
...
@@ -304,7 +304,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -304,7 +304,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
expect
(
err
.
validateTest
).
to
.
be
.
ok
expect
(
err
.
validateTest
).
to
.
be
.
ok
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
expect
(
err
.
validateTest
[
0
]).
to
.
be
.
ok
expect
(
err
.
validateTest
[
0
]).
to
.
be
.
ok
expect
(
err
.
validateTest
[
0
]
.
indexOf
(
'Invalid integer:'
)).
to
.
be
.
greaterThan
(
-
1
)
expect
(
err
.
validateTest
[
0
]
).
to
.
equal
(
'Validation isInt failed: validateTest'
)
done
()
done
()
})
})
})
})
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment