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 ba7d7fc3
authored
Mar 16, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix poorly written sql checking tests
1 parent
cafa41dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
68 deletions
test/integration/model.test.js
test/integration/support.js
test/integration/model.test.js
View file @
ba7d7fc
...
@@ -299,7 +299,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -299,7 +299,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
bCol
:
{
type
:
Sequelize
.
STRING
,
unique
:
'a_and_b'
}
bCol
:
{
type
:
Sequelize
.
STRING
,
unique
:
'a_and_b'
}
});
});
return
User
.
sync
({
force
:
true
,
loging
:
_
.
after
(
2
,
_
.
once
(
function
(
sql
)
{
return
User
.
sync
({
force
:
true
,
log
g
ing
:
_
.
after
(
2
,
_
.
once
(
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
expect
(
sql
).
to
.
match
(
/CONSTRAINT
\s
*
([
`"
\[]?
user_and_email
[
`"
\]]?)?\s
*UNIQUE
\s
*
\([
`"
\[]?
username
[
`"
\]]?
,
[
`"
\[]?
email
[
`"
\]]?\)
/
);
expect
(
sql
).
to
.
match
(
/CONSTRAINT
\s
*
([
`"
\[]?
user_and_email
[
`"
\]]?)?\s
*UNIQUE
\s
*
\([
`"
\[]?
username
[
`"
\]]?
,
[
`"
\[]?
email
[
`"
\]]?\)
/
);
expect
(
sql
).
to
.
match
(
/CONSTRAINT
\s
*
([
`"
\[]?
a_and_b
[
`"
\]]?)?\s
*UNIQUE
\s
*
\([
`"
\[]?
aCol
[
`"
\]]?
,
[
`"
\[]?
bCol
[
`"
\]]?\)
/
);
expect
(
sql
).
to
.
match
(
/CONSTRAINT
\s
*
([
`"
\[]?
a_and_b
[
`"
\]]?)?\s
*UNIQUE
\s
*
\([
`"
\[]?
aCol
[
`"
\]]?
,
[
`"
\[]?
bCol
[
`"
\]]?\)
/
);
...
@@ -1422,32 +1422,31 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1422,32 +1422,31 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'supports table schema/prefix'
,
function
(
done
)
{
it
(
'supports table schema/prefix'
,
function
()
{
var
self
=
this
var
self
=
this
,
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
},
,
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
},
{
username
:
'Paul'
,
secretValue
:
'42'
},
{
username
:
'Paul'
,
secretValue
:
'42'
},
{
username
:
'Bob'
,
secretValue
:
'43'
}]
{
username
:
'Bob'
,
secretValue
:
'43'
}]
,
prefixUser
=
self
.
User
.
schema
(
'prefix'
);
,
prefixUser
=
self
.
User
.
schema
(
'prefix'
);
var
run
=
function
()
{
prefixUser
.
sync
({
force
:
true
}).
success
(
function
()
{
prefixUser
.
bulkCreate
(
data
).
success
(
function
()
{
prefixUser
.
destroy
({
where
:
{
secretValue
:
'42'
}})
.
success
(
function
()
{
prefixUser
.
findAll
({
order
:
'id'
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
1
);
expect
(
users
[
0
].
username
).
to
.
equal
(
'Bob'
);
done
();
});
});
});
});
};
this
.
sequelize
.
queryInterface
.
createSchema
(
'prefix'
).
success
(
function
()
{
run
.
call
(
self
);
});
var
run
=
function
()
{
return
prefixUser
.
sync
({
force
:
true
}).
then
(
function
()
{
return
prefixUser
.
bulkCreate
(
data
).
then
(
function
()
{
return
prefixUser
.
destroy
({
where
:
{
secretValue
:
'42'
}}).
then
(
function
()
{
return
prefixUser
.
findAll
({
order
:
'id'
}).
then
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
1
);
expect
(
users
[
0
].
username
).
to
.
equal
(
'Bob'
);
});
});
});
});
};
return
this
.
sequelize
.
queryInterface
.
dropAllSchemas
().
then
(
function
()
{
return
self
.
sequelize
.
queryInterface
.
createSchema
(
'prefix'
).
then
(
function
()
{
return
run
.
call
(
self
);
});
});
});
});
});
});
...
@@ -2021,7 +2020,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2021,7 +2020,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'should be able to reference a table with a schema set'
,
function
(
done
)
{
it
(
'should be able to reference a table with a schema set'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
var
UserPub
=
this
.
sequelize
.
define
(
'UserPub'
,
{
var
UserPub
=
this
.
sequelize
.
define
(
'UserPub'
,
{
...
@@ -2037,8 +2036,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2037,8 +2036,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
var
run
=
function
()
{
var
run
=
function
()
{
UserPub
.
sync
({
force
:
true
}).
success
(
function
()
{
return
UserPub
.
sync
({
force
:
true
}).
then
(
function
()
{
ItemPub
.
sync
({
force
:
true
}).
on
(
'sql'
,
_
.
after
(
2
,
_
.
once
(
function
(
sql
)
{
return
ItemPub
.
sync
({
force
:
true
,
logging
:
_
.
after
(
2
,
_
.
once
(
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+"prefix"
\.
"UserPubs"
\(
"id"
\)
/
);
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+"prefix"
\.
"UserPubs"
\(
"id"
\)
/
);
}
else
if
(
dialect
===
'mssql'
)
{
}
else
if
(
dialect
===
'mssql'
)
{
...
@@ -2046,17 +2045,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2046,17 +2045,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+`prefix
\.
UserPubs`
\(
`id`
\)
/
);
expect
(
sql
).
to
.
match
(
/REFERENCES
\s
+`prefix
\.
UserPubs`
\(
`id`
\)
/
);
}
}
done
();
})));
}))
}
);
});
});
};
};
if
(
dialect
===
'postgres'
)
{
if
(
dialect
===
'postgres'
)
{
this
.
sequelize
.
queryInterface
.
createSchema
(
'prefix'
).
success
(
function
()
{
return
this
.
sequelize
.
queryInterface
.
dropAllSchemas
().
then
(
function
()
{
run
.
call
(
self
);
return
self
.
sequelize
.
queryInterface
.
createSchema
(
'prefix'
).
then
(
function
()
{
return
run
.
call
(
self
);
});
});
});
}
else
{
}
else
{
run
.
call
(
self
);
r
eturn
r
un
.
call
(
self
);
}
}
});
});
...
@@ -2126,7 +2127,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2126,7 +2127,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'uses an existing dao factory and references the author table'
,
function
(
done
)
{
it
(
'uses an existing dao factory and references the author table'
,
function
()
{
var
self
=
this
var
self
=
this
,
Post
=
this
.
sequelize
.
define
(
'post'
,
{
,
Post
=
this
.
sequelize
.
define
(
'post'
,
{
title
:
Sequelize
.
STRING
,
title
:
Sequelize
.
STRING
,
...
@@ -2141,7 +2142,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2141,7 +2142,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
Post
.
belongsTo
(
this
.
Author
);
Post
.
belongsTo
(
this
.
Author
);
// The posts table gets dropped in the before filter.
// The posts table gets dropped in the before filter.
Post
.
sync
().
on
(
'sql'
,
_
.
once
(
function
(
sql
)
{
return
Post
.
sync
({
logging
:
_
.
once
(
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
).
to
.
match
(
/"authorId" INTEGER REFERENCES "authors"
\(
"id"
\)
/
);
expect
(
sql
).
to
.
match
(
/"authorId" INTEGER REFERENCES "authors"
\(
"id"
\)
/
);
}
else
if
(
Support
.
dialectIsMySQL
())
{
}
else
if
(
Support
.
dialectIsMySQL
())
{
...
@@ -2153,12 +2154,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2153,12 +2154,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
throw
new
Error
(
'Undefined dialect!'
);
throw
new
Error
(
'Undefined dialect!'
);
}
}
})});
done
();
}));
});
});
it
(
'uses a table name as a string and references the author table'
,
function
(
done
)
{
it
(
'uses a table name as a string and references the author table'
,
function
()
{
var
self
=
this
var
self
=
this
,
Post
=
self
.
sequelize
.
define
(
'post'
,
{
,
Post
=
self
.
sequelize
.
define
(
'post'
,
{
title
:
Sequelize
.
STRING
,
title
:
Sequelize
.
STRING
,
...
@@ -2173,7 +2172,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2173,7 +2172,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
Post
.
belongsTo
(
this
.
Author
);
Post
.
belongsTo
(
this
.
Author
);
// The posts table gets dropped in the before filter.
// The posts table gets dropped in the before filter.
Post
.
sync
().
on
(
'sql'
,
_
.
once
(
function
(
sql
)
{
return
Post
.
sync
({
logging
:
_
.
once
(
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
).
to
.
match
(
/"authorId" INTEGER REFERENCES "authors"
\(
"id"
\)
/
);
expect
(
sql
).
to
.
match
(
/"authorId" INTEGER REFERENCES "authors"
\(
"id"
\)
/
);
}
else
if
(
Support
.
dialectIsMySQL
())
{
}
else
if
(
Support
.
dialectIsMySQL
())
{
...
@@ -2185,9 +2184,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2185,9 +2184,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
throw
new
Error
(
'Undefined dialect!'
);
throw
new
Error
(
'Undefined dialect!'
);
}
}
})});
done
();
}));
});
});
it
(
'emits an error event as the referenced table name is invalid'
,
function
(
done
)
{
it
(
'emits an error event as the referenced table name is invalid'
,
function
(
done
)
{
...
@@ -2237,7 +2234,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2237,7 +2234,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'works with comments'
,
function
(
done
)
{
it
(
'works with comments'
,
function
()
{
// Test for a case where the comment was being moved to the end of the table when there was also a reference on the column, see #1521
// Test for a case where the comment was being moved to the end of the table when there was also a reference on the column, see #1521
var
Member
=
this
.
sequelize
.
define
(
'Member'
,
{})
var
Member
=
this
.
sequelize
.
define
(
'Member'
,
{})
,
Profile
=
this
.
sequelize
.
define
(
'Profile'
,
{
,
Profile
=
this
.
sequelize
.
define
(
'Profile'
,
{
...
@@ -2251,30 +2248,25 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2251,30 +2248,25 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
});
});
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
sequelize
.
sync
({
force
:
true
});
done
();
});
});
});
});
});
describe
(
'blob'
,
function
()
{
describe
(
'blob'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
BlobUser
=
this
.
sequelize
.
define
(
'blobUser'
,
{
this
.
BlobUser
=
this
.
sequelize
.
define
(
'blobUser'
,
{
data
:
Sequelize
.
BLOB
data
:
Sequelize
.
BLOB
});
});
this
.
BlobUser
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
BlobUser
.
sync
({
force
:
true
});
done
();
});
});
});
describe
(
'buffers'
,
function
()
{
describe
(
'buffers'
,
function
()
{
it
(
'should be able to take a buffer as parameter to a BLOB field'
,
function
(
done
)
{
it
(
'should be able to take a buffer as parameter to a BLOB field'
,
function
()
{
this
.
BlobUser
.
create
({
return
this
.
BlobUser
.
create
({
data
:
new
Buffer
(
'Sequelize'
)
data
:
new
Buffer
(
'Sequelize'
)
}).
success
(
function
(
user
)
{
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
;
expect
(
user
).
to
.
be
.
ok
;
done
();
});
});
});
});
...
@@ -2510,40 +2502,37 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -2510,40 +2502,37 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
describe
(
'Unique'
,
function
()
{
describe
(
'Unique'
,
function
()
{
it
(
'should set unique when unique is true'
,
function
(
done
)
{
it
(
'should set unique when unique is true'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
var
uniqueTrue
=
self
.
sequelize
.
define
(
'uniqueTrue'
,
{
var
uniqueTrue
=
self
.
sequelize
.
define
(
'uniqueTrue'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
});
});
uniqueTrue
.
sync
({
force
:
true
}).
on
(
'sql'
,
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
return
uniqueTrue
.
sync
({
force
:
true
,
logging
:
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
expect
(
s
).
to
.
match
(
/UNIQUE/
);
expect
(
s
).
to
.
match
(
/UNIQUE/
);
done
();
}))});
})));
});
});
it
(
'should not set unique when unique is false'
,
function
(
done
)
{
it
(
'should not set unique when unique is false'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
var
uniqueFalse
=
self
.
sequelize
.
define
(
'uniqueFalse'
,
{
var
uniqueFalse
=
self
.
sequelize
.
define
(
'uniqueFalse'
,
{
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
false
}
str
:
{
type
:
Sequelize
.
STRING
,
unique
:
false
}
});
});
uniqueFalse
.
sync
({
force
:
true
}).
on
(
'sql'
,
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
return
uniqueFalse
.
sync
({
force
:
true
,
logging
:
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
);
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
);
done
();
}))});
})));
});
});
it
(
'should not set unique when unique is unset'
,
function
(
done
)
{
it
(
'should not set unique when unique is unset'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
var
uniqueUnset
=
self
.
sequelize
.
define
(
'uniqueUnset'
,
{
var
uniqueUnset
=
self
.
sequelize
.
define
(
'uniqueUnset'
,
{
str
:
{
type
:
Sequelize
.
STRING
}
str
:
{
type
:
Sequelize
.
STRING
}
});
});
uniqueUnset
.
sync
({
force
:
true
}).
on
(
'sql'
,
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
return
uniqueUnset
.
sync
({
force
:
true
,
logging
:
_
.
after
(
2
,
_
.
once
(
function
(
s
)
{
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
);
expect
(
s
).
not
.
to
.
match
(
/UNIQUE/
);
done
();
}))});
})));
});
});
});
});
...
...
test/integration/support.js
View file @
ba7d7fc
...
@@ -25,7 +25,12 @@ beforeEach(function() {
...
@@ -25,7 +25,12 @@ beforeEach(function() {
});
});
afterEach
(
function
()
{
afterEach
(
function
()
{
this
.
sequelize
.
test
.
verifyNoRunningQueries
();
try
{
this
.
sequelize
.
test
.
verifyNoRunningQueries
();
}
catch
(
err
)
{
err
.
message
+=
" in "
+
this
.
currentTest
.
fullTitle
();
throw
err
;
}
});
});
module
.
exports
=
Support
;
module
.
exports
=
Support
;
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