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 f3b924d5
authored
Dec 06, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(validations): add basic schema validation to STRING(N) and TEXT aswell, closes #2631
1 parent
b987ae4a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletions
lib/instance-validator.js
test/dao.validations.test.js
lib/instance-validator.js
View file @
f3b924d
...
@@ -364,7 +364,7 @@ InstanceValidator.prototype._validateSchema = function(rawAttribute, field, valu
...
@@ -364,7 +364,7 @@ InstanceValidator.prototype._validateSchema = function(rawAttribute, field, valu
this
.
errors
.
push
(
error
);
this
.
errors
.
push
(
error
);
}
}
if
(
rawAttribute
.
type
===
DataTypes
.
STRING
)
{
if
(
rawAttribute
.
type
===
DataTypes
.
STRING
||
rawAttribute
.
type
instanceof
DataTypes
.
STRING
||
rawAttribute
.
type
===
DataTypes
.
TEXT
)
{
if
(
Array
.
isArray
(
value
)
||
(
_
.
isObject
(
value
)
&&
!
value
.
_isSequelizeMethod
))
{
if
(
Array
.
isArray
(
value
)
||
(
_
.
isObject
(
value
)
&&
!
value
.
_isSequelizeMethod
))
{
error
=
new
sequelizeError
.
ValidationErrorItem
(
field
+
' cannot be an array or an object'
,
'string violation'
,
field
,
value
);
error
=
new
sequelizeError
.
ValidationErrorItem
(
field
+
' cannot be an array or an object'
,
'string violation'
,
field
,
value
);
this
.
errors
.
push
(
error
);
this
.
errors
.
push
(
error
);
...
...
test/dao.validations.test.js
View file @
f3b924d
...
@@ -825,6 +825,36 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -825,6 +825,36 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
})
})
it
(
'raises an error for array on a STRING(20)'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
type
:
Sequelize
.
STRING
(
20
)
}
})
User
.
build
({
email
:
[
'iama'
,
'dummy.com'
]
}).
validate
().
success
(
function
(
errors
)
{
expect
(
errors
).
to
.
be
.
an
.
instanceof
(
Sequelize
.
ValidationError
)
done
()
})
})
it
(
'raises an error for array on a TEXT'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
type
:
Sequelize
.
TEXT
}
})
User
.
build
({
email
:
[
'iama'
,
'dummy.com'
]
}).
validate
().
success
(
function
(
errors
)
{
expect
(
errors
).
to
.
be
.
an
.
instanceof
(
Sequelize
.
ValidationError
)
done
()
})
})
it
(
'raises an error for {} on a STRING'
,
function
(
done
)
{
it
(
'raises an error for {} on a STRING'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
'email'
:
{
...
@@ -840,6 +870,36 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -840,6 +870,36 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
})
})
it
(
'raises an error for {} on a STRING(20)'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
type
:
Sequelize
.
STRING
(
20
)
}
})
User
.
build
({
email
:
{
lol
:
true
}
}).
validate
().
success
(
function
(
errors
)
{
expect
(
errors
).
to
.
be
.
an
.
instanceof
(
Sequelize
.
ValidationError
)
done
()
})
})
it
(
'raises an error for {} on a TEXT'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
type
:
Sequelize
.
TEXT
}
})
User
.
build
({
email
:
{
lol
:
true
}
}).
validate
().
success
(
function
(
errors
)
{
expect
(
errors
).
to
.
be
.
an
.
instanceof
(
Sequelize
.
ValidationError
)
done
()
})
})
it
(
'does not raise an error for null on a STRING (where null is allowed)'
,
function
(
done
)
{
it
(
'does not raise an error for null on a STRING (where null is allowed)'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'email'
:
{
'email'
:
{
...
...
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