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 00de8764
authored
Aug 09, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into milestones/2.0.0
2 parents
fcbac2fb
65fe70fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
31 deletions
test/dao.validations.test.js
test/dao.validations.test.js
View file @
00de876
...
...
@@ -261,46 +261,110 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
}
describe
(
'#create'
,
function
()
{
beforeEach
(
function
(
done
)
{
var
self
=
this
var
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
defaultValue
:
'unknown'
,
validate
:
{
isIn
:
[[
'unknown'
,
'hello'
,
'test'
]]
describe
(
'generic'
,
function
()
{
beforeEach
(
function
(
done
)
{
var
self
=
this
var
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
defaultValue
:
'unknown'
,
validate
:
{
isIn
:
[[
'unknown'
,
'hello'
,
'test'
]]
}
}
}
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
something
:
Sequelize
.
INTEGER
})
Project
.
hasOne
(
Task
)
Task
.
hasOne
(
Project
)
Project
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
Project
=
Project
self
.
Task
=
Task
done
()
})
})
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
something
:
Sequelize
.
INTEGER
it
(
'correctly validates using create method '
,
function
(
done
)
{
var
self
=
this
this
.
Project
.
create
({}).
success
(
function
(
project
)
{
self
.
Task
.
create
({
something
:
1
}).
success
(
function
(
task
)
{
project
.
setTask
(
task
).
success
(
function
(
task
)
{
expect
(
task
.
ProjectId
).
to
.
not
.
be
.
null
task
.
setProject
(
project
).
success
(
function
(
project
)
{
expect
(
project
.
ProjectId
).
to
.
not
.
be
.
null
done
()
})
})
})
})
})
})
describe
(
'explicitly validating id/primary/auto incremented columns'
,
function
()
{
it
(
'should emit an error when we try to enter in a string for the id key without validation arguments'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserId'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
validate
:
{
isInt
:
true
}
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
id
:
[
'Invalid integer: id'
]})
done
()
})
})
})
Project
.
hasOne
(
Task
)
Task
.
hasOne
(
Project
)
it
(
'should emit an error when we try to enter in a string for the id key with validation arguments'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserId'
,
{
id
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
validate
:
{
isInt
:
{
args
:
true
,
msg
:
'ID must be an integer!'
}
}
}
})
Project
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
sync
({
force
:
true
}).
success
(
function
(
)
{
self
.
Project
=
Project
self
.
Task
=
Task
done
(
)
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
id
:
[
'ID must be an integer!'
]})
done
()
}
)
})
})
})
it
(
'correctly validates using create method '
,
function
(
done
)
{
var
self
=
this
this
.
Project
.
create
({}).
success
(
function
(
project
)
{
self
.
Task
.
create
({
something
:
1
}).
success
(
function
(
task
)
{
project
.
setTask
(
task
).
success
(
function
(
task
)
{
expect
(
task
.
ProjectId
).
to
.
not
.
be
.
null
task
.
setProject
(
project
).
success
(
function
(
project
)
{
expect
(
project
.
ProjectId
).
to
.
not
.
be
.
null
done
()
})
it
(
'should emit an error when we try to enter in a string for an auto increment key (not named id)'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserId'
,
{
username
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
validate
:
{
isInt
:
{
args
:
true
,
msg
:
'Username must be an integer!'
}
}
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'helloworldhelloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
username
:
[
'Username must be an integer!'
]})
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