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 95af31e9
authored
Sep 04, 2014
by
overlookmotel
Committed by
Jan Aagaard Meier
Sep 13, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for foreign key constraint violation
1 parent
07998023
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
test/associations/belongs-to.test.js
test/associations/has-many.test.js
test/associations/has-one.test.js
test/associations/belongs-to.test.js
View file @
95af31e
...
@@ -374,6 +374,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -374,6 +374,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
it
(
"can restrict deletes"
,
function
(
done
)
{
it
(
"can restrict deletes"
,
function
(
done
)
{
var
self
=
this
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
...
@@ -384,7 +385,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -384,7 +385,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
setUser
(
user
).
success
(
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
user
.
destroy
().
catch
(
function
(
err
)
{
user
.
destroy
().
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
(
err
)
{
expect
(
err
).
to
.
be
.
ok
;
expect
(
err
).
to
.
be
.
ok
;
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
expect
(
tasks
).
to
.
have
.
length
(
1
)
...
@@ -428,6 +429,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -428,6 +429,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
it
(
"can restrict updates"
,
function
(
done
)
{
it
(
"can restrict updates"
,
function
(
done
)
{
var
self
=
this
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
...
@@ -444,7 +446,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -444,7 +446,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
error
(
function
()
{
.
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
expect
(
tasks
).
to
.
have
.
length
(
1
)
...
...
test/associations/has-many.test.js
View file @
95af31e
...
@@ -1935,6 +1935,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1935,6 +1935,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
});
});
it
(
"can restrict deletes"
,
function
()
{
it
(
"can restrict deletes"
,
function
()
{
var
self
=
this
;
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
...
@@ -1950,7 +1951,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1950,7 +1951,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this
.
task
=
task
;
this
.
task
=
task
;
return
user
.
setTasks
([
task
]);
return
user
.
setTasks
([
task
]);
}).
then
(
function
()
{
}).
then
(
function
()
{
return
this
.
user
.
destroy
().
catch
(
function
()
{
return
this
.
user
.
destroy
().
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
()
{
// Should fail due to FK violation
// Should fail due to FK violation
return
Task
.
findAll
();
return
Task
.
findAll
();
});
});
...
@@ -1988,6 +1989,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1988,6 +1989,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
});
});
it
(
"can restrict updates"
,
function
()
{
it
(
"can restrict updates"
,
function
()
{
var
self
=
this
;
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
...
@@ -2006,7 +2008,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -2006,7 +2008,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
// `WHERE` clause
// `WHERE` clause
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
);
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
);
return
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
).
catch
(
function
()
{
return
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
()
{
// Should fail due to FK violation
// Should fail due to FK violation
return
Task
.
findAll
();
return
Task
.
findAll
();
});
});
...
@@ -2086,8 +2089,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -2086,8 +2089,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
]);
]);
}).
then
(
function
()
{
}).
then
(
function
()
{
return
Promise
.
all
([
return
Promise
.
all
([
this
.
user1
.
destroy
().
catch
(
spy
),
// Fails because of RESTRICT constraint
this
.
user1
.
destroy
().
catch
(
s
elf
.
sequelize
.
ForeignKeyConstraintError
,
s
py
),
// Fails because of RESTRICT constraint
this
.
task2
.
destroy
().
catch
(
spy
)
this
.
task2
.
destroy
().
catch
(
s
elf
.
sequelize
.
ForeignKeyConstraintError
,
s
py
)
]);
]);
}).
then
(
function
()
{
}).
then
(
function
()
{
expect
(
spy
).
to
.
have
.
been
.
calledTwice
;
expect
(
spy
).
to
.
have
.
been
.
calledTwice
;
...
@@ -2119,7 +2122,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -2119,7 +2122,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
]);
]);
}).
then
(
function
()
{
}).
then
(
function
()
{
return
Promise
.
all
([
return
Promise
.
all
([
this
.
user1
.
destroy
().
catch
(
spy
),
// Fails because of RESTRICT constraint
this
.
user1
.
destroy
().
catch
(
s
elf
.
sequelize
.
ForeignKeyConstraintError
,
s
py
),
// Fails because of RESTRICT constraint
this
.
task2
.
destroy
()
this
.
task2
.
destroy
()
]);
]);
}).
then
(
function
()
{
}).
then
(
function
()
{
...
...
test/associations/has-one.test.js
View file @
95af31e
...
@@ -331,6 +331,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -331,6 +331,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
it
(
"can restrict deletes"
,
function
(
done
)
{
it
(
"can restrict deletes"
,
function
(
done
)
{
var
self
=
this
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
...
@@ -341,7 +342,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -341,7 +342,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
user
.
setTask
(
task
).
success
(
function
()
{
user
.
destroy
().
error
(
function
()
{
user
.
destroy
().
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
expect
(
tasks
).
to
.
have
.
length
(
1
)
...
@@ -388,6 +389,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -388,6 +389,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
it
(
"can restrict updates"
,
function
(
done
)
{
it
(
"can restrict updates"
,
function
(
done
)
{
var
self
=
this
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
...
@@ -405,7 +407,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -405,7 +407,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
var
tableName
=
user
.
QueryInterface
.
QueryGenerator
.
addSchema
(
user
.
Model
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
user
.
QueryInterface
.
update
(
user
,
tableName
,
{
id
:
999
},
user
.
id
)
.
error
(
function
()
{
.
catch
(
self
.
sequelize
.
ForeignKeyConstraintError
,
function
()
{
// Should fail due to FK restriction
// Should fail due to FK restriction
Task
.
findAll
().
success
(
function
(
tasks
)
{
Task
.
findAll
().
success
(
function
(
tasks
)
{
expect
(
tasks
).
to
.
have
.
length
(
1
)
expect
(
tasks
).
to
.
have
.
length
(
1
)
...
...
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