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 2b889ed7
authored
Jan 07, 2015
by
ekmartin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure truncate: true is still allowed in Model.destroy() and add a test for it
1 parent
5c84dc0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
lib/model.js
test/model.test.js
lib/model.js
View file @
2b889ed
...
@@ -1415,8 +1415,8 @@ module.exports = (function() {
...
@@ -1415,8 +1415,8 @@ module.exports = (function() {
var
self
=
this
var
self
=
this
,
instances
;
,
instances
;
if
(
!
options
||
!
options
.
where
)
{
if
(
!
options
||
!
(
options
.
where
||
options
.
truncate
)
)
{
throw
new
Error
(
'Missing where attribute in the options parameter passed to destroy.'
);
throw
new
Error
(
'Missing where
or truncate
attribute in the options parameter passed to destroy.'
);
}
}
options
=
Utils
.
_
.
extend
({
options
=
Utils
.
_
.
extend
({
...
...
test/model.test.js
View file @
2b889ed
...
@@ -1094,6 +1094,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1094,6 +1094,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
describe
(
'destroy'
,
function
()
{
describe
(
'destroy'
,
function
()
{
it
(
'truncate should clear the table'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
}),
data
=
[
{
username
:
'user1'
},
{
username
:
'user2'
}
];
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
bulkCreate
(
data
);
}).
then
(
function
()
{
return
User
.
destroy
({
truncate
:
true
});
}).
then
(
function
()
{
return
expect
(
User
.
findAll
()).
to
.
eventually
.
have
.
length
(
0
);
});
});
it
(
'throws an error if no where clause is given'
,
function
()
{
it
(
'throws an error if no where clause is given'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
...
@@ -1102,7 +1118,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1102,7 +1118,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}).
then
(
function
()
{
}).
then
(
function
()
{
throw
new
Error
(
'Destroy should throw an error if no where clause is given.'
);
throw
new
Error
(
'Destroy should throw an error if no where clause is given.'
);
},
function
(
err
)
{
},
function
(
err
)
{
expect
(
err
.
message
).
to
.
equal
(
'Missing where attribute in the options parameter passed to destroy.'
);
expect
(
err
).
to
.
be
.
an
.
instanceof
(
Error
);
expect
(
err
.
message
).
to
.
equal
(
'Missing where or truncate attribute in the options parameter passed to destroy.'
);
});
});
});
});
...
...
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