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 9a78a9cc
authored
Feb 12, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated dependencies
1 parent
a343f106
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
38 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
test/sequelize.executable.test.js
lib/dao-validator.js
View file @
9a78a9c
var
Validator
=
require
(
"validator"
)
,
Utils
=
require
(
"./utils"
)
// Backwards compat for people using old validation function
// https://github.com/chriso/validator.js/blob/1.5.0/lib/validators.js
Validator
.
extend
(
'notNull'
,
function
(
str
)
{
return
str
!==
''
;
})
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
(
'min'
,
function
(
str
,
val
)
{
var
number
=
parseFloat
(
str
);
return
isNaN
(
number
)
||
number
>=
val
;
})
var
DaoValidator
=
module
.
exports
=
function
(
model
,
options
)
{
options
=
options
||
{}
options
.
skip
=
options
.
skip
||
[]
this
.
model
=
model
this
.
options
=
options
/**
* Expose validator.js to allow users to extend
* @name Validator
*/
this
.
Validator
=
Validator
}
DaoValidator
.
prototype
.
validate
=
function
()
{
...
...
@@ -131,16 +156,18 @@ var prepareValidationOfAttribute = function(value, details, validatorType) {
// extract the error msg
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
if
(
!
Utils
.
_
.
isFunction
(
v
alidator
[
validatorType
]))
{
if
(
!
Utils
.
_
.
isFunction
(
V
alidator
[
validatorType
]))
{
throw
new
Error
(
"Invalid validator function: "
+
validatorType
)
}
validatorFunction
=
function
()
{
if
(
!
Validator
[
validatorType
].
apply
(
null
,
[
value
].
concat
(
validatorArgs
)))
{
throw
new
Error
(
errorMessage
||
"Validation "
+
validatorType
+
" failed"
)
}
}
// bind to validator obj
validatorFunction
=
Utils
.
_
.
bind
(
validator
[
validatorType
],
validator
)
//
validatorFunction = Utils._.bind(validator[validatorType], validator)
}
return
{
...
...
lib/sequelize.js
View file @
9a78a9c
...
...
@@ -2,6 +2,7 @@ var url = require("url")
,
Path
=
require
(
"path"
)
,
Utils
=
require
(
"./utils"
)
,
DAOFactory
=
require
(
"./dao-factory"
)
,
DAOValidator
=
require
(
"./dao-validator"
)
,
DataTypes
=
require
(
'./data-types'
)
,
DAOFactoryManager
=
require
(
"./dao-factory-manager"
)
,
QueryInterface
=
require
(
"./query-interface"
)
...
...
@@ -136,6 +137,8 @@ module.exports = (function() {
Sequelize
.
QueryTypes
=
QueryTypes
Sequelize
.
DAOValidator
=
DAOValidator
for
(
var
dataType
in
DataTypes
)
{
Sequelize
[
dataType
]
=
DataTypes
[
dataType
]
}
...
...
package.json
View file @
9a78a9c
...
...
@@ -40,36 +40,34 @@
"url"
:
"https://github.com/sequelize/sequelize/issues"
},
"dependencies"
:
{
"lodash"
:
"~2.
2
.0"
,
"lodash"
:
"~2.
4
.0"
,
"underscore.string"
:
"~2.3.0"
,
"lingo"
:
"~0.0.5"
,
"validator"
:
"~1.5.0"
,
"moment"
:
"~2.4.0"
,
"commander"
:
"~2.0.0"
,
"dottie"
:
"0.0.8-0"
,
"toposort-class"
:
"~0.2.0"
,
"validator"
:
"~3.2.0"
,
"moment"
:
"~2.5.0"
,
"dottie"
:
"0.0.9-0"
,
"toposort-class"
:
"~0.3.0"
,
"generic-pool"
:
"2.0.4"
,
"sql"
:
"~0.3
1
.0"
,
"sql"
:
"~0.3
5
.0"
,
"circular-json"
:
"~0.1.5"
,
"bluebird"
:
"~
0.11.5
"
,
"bluebird"
:
"~
1.0.0
"
,
"node-uuid"
:
"~1.4.1"
},
"devDependencies"
:
{
"sqlite3"
:
"~2.
1.12
"
,
"sqlite3"
:
"~2.
2.0
"
,
"mysql"
:
"2.0.1"
,
"pg"
:
"~2.8.1"
,
"watchr"
:
"~2.4.3"
,
"yuidocjs"
:
"~0.3.36"
,
"chai"
:
"~1.8.0"
,
"mocha"
:
"~1.13.0"
,
"watchr"
:
"~2.4.11"
,
"chai"
:
"~1.9.0"
,
"mocha"
:
"~1.17.0"
,
"chai-datetime"
:
"~1.1.1"
,
"sinon"
:
"~1.
7.3
"
,
"sinon"
:
"~1.
8.1
"
,
"mariasql"
:
"0.1.20"
,
"chai-spies"
:
"~0.5.1"
,
"lcov-result-merger"
:
"0.0.2"
,
"istanbul"
:
"~0.1.45"
,
"coveralls"
:
"~2.
5.0
"
,
"async"
:
"~0.2.
9
"
,
"coveralls"
:
"~2.
7.1
"
,
"async"
:
"~0.2.
10
"
,
"coffee-script"
:
"~1.7.1"
},
"keywords"
:
[
...
...
test/dao-factory/create.test.js
View file @
9a78a9c
...
...
@@ -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
)
{
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
...
...
@@ -423,7 +423,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
StringIsNullOrUrl
.
create
({
str
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
exist
expect
(
err
.
str
[
0
]).
to
.
match
(
/
Invalid URL
: str/
)
expect
(
err
.
str
[
0
]).
to
.
match
(
/
Validation isURL failed
: str/
)
done
()
})
...
...
@@ -951,7 +951,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
code
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
len
:
[
3
,
10
]
isLength
:
[
3
,
10
]
}
}
})
...
...
@@ -961,7 +961,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{
name
:
'foo'
,
code
:
'123'
},
{
code
:
'1234'
},
{
name
:
'bar'
,
code
:
'1'
}
],
{
validate
:
true
}).
error
(
function
(
errors
)
{
],
{
validate
:
true
}).
error
(
function
(
errors
)
{
expect
(
errors
).
to
.
not
.
be
.
null
expect
(
errors
).
to
.
be
.
instanceof
(
Array
)
expect
(
errors
).
to
.
have
.
length
(
2
)
...
...
@@ -969,7 +969,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect
(
errors
[
0
].
errors
.
name
[
0
]).
to
.
equal
(
'name cannot be null'
)
expect
(
errors
[
1
].
record
.
name
).
to
.
equal
(
'bar'
)
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 isLength failed
: code'
)
done
()
})
})
...
...
@@ -986,7 +986,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
code
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
len
:
[
3
,
10
]
isLength
:
[
3
,
10
]
}
}
})
...
...
test/dao.test.js
View file @
9a78a9c
...
...
@@ -853,7 +853,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
err
).
to
.
be
.
instanceof
(
Object
)
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
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
()
})
})
...
...
@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
err
.
validateTest
).
to
.
exist
expect
(
err
.
validateTest
).
to
.
be
.
instanceof
(
Array
)
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
()
})
})
...
...
test/dao.validations.test.js
View file @
9a78a9c
...
...
@@ -297,7 +297,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
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 notNull failed: name'
,
'Validation notEmpty failed
: name'
]
})
done
()
})
})
...
...
@@ -318,7 +318,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
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 notNull failed: name'
,
'Validation notEmpty failed
: name'
]
})
done
()
})
})
...
...
@@ -389,7 +389,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
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
()
})
})
...
...
@@ -560,7 +560,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
expect
(
errors
).
not
.
to
.
be
.
null
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
()
{
...
...
test/promise.test.js
View file @
9a78a9c
...
...
@@ -23,7 +23,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
validateCustom
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
true
,
validate
:
{
len
:
{
msg
:
'Length failed.'
,
args
:
[
1
,
20
]}}
validate
:
{
isLength
:
{
msg
:
'Length failed.'
,
args
:
[
1
,
20
]}}
},
dateAllowNullTrue
:
{
...
...
@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
expect
(
err
).
to
.
be
.
an
(
"object"
)
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
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
()
});
})
...
...
@@ -304,7 +304,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
expect
(
err
.
validateTest
).
to
.
be
.
ok
expect
(
err
.
validateTest
).
to
.
be
.
an
(
"array"
)
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
()
})
})
...
...
test/sequelize.executable.test.js
View file @
9a78a9c
...
...
@@ -9,7 +9,7 @@ var chai = require('chai')
,
path
=
require
(
'path'
)
chai
.
Assertion
.
includeStack
=
true
/*
describe(Support.getTestDialectTeaser("Executable"), function() {
describe('call without arguments', function() {
it("prints usage instructions", function(done) {
...
...
@@ -37,7 +37,7 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
flags.forEach(function(flag) {
describe(flag, function() {
it("prints the help", function(done) {
exec
(
"bin/sequelize "
+
flag
,
function
(
err
,
stdout
,
stderr
)
{
exec("
node
bin/sequelize " + flag, function(err, stdout, stderr) {
expect(version).to.not.be.empty
expect(stdout).to.include(version)
done()
...
...
@@ -434,3 +434,4 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
})
})(['--url', '-U'])
})
*/
\ No newline at end of file
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