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 5cb80fd6
authored
Dec 21, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check specs for every single dialect
1 parent
c7d8063d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
12 deletions
spec/model-factory.spec.js
spec/model-factory.spec.js
View file @
5cb80fd
var
config
=
require
(
"./config/config"
)
var
config
=
require
(
"./config/config"
)
,
Sequelize
=
require
(
"../index"
)
,
Sequelize
=
require
(
"../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
dialects
=
[
'sqlite'
,
'mysql'
]
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
describe
(
'ModelFactory'
,
function
()
{
describe
(
'ModelFactory'
,
function
()
{
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'with dialect "'
+
dialect
+
'"'
,
function
()
{
var
User
=
null
var
User
=
null
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
dialect
:
dialect
})
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
var
setup
=
function
(
options
)
{
var
setup
=
function
(
options
)
{
User
=
sequelize
.
define
(
'User'
,
options
||
{
User
=
sequelize
.
define
(
'User'
,
options
||
{
...
@@ -16,10 +22,17 @@ describe('ModelFactory', function() {
...
@@ -16,10 +22,17 @@ describe('ModelFactory', function() {
Helpers
.
dropAllTables
()
Helpers
.
dropAllTables
()
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
User
.
sync
({
force
:
true
}).
success
(
done
)
User
.
sync
({
force
:
true
}).
success
(
done
).
error
(
function
(
err
)
{
console
.
log
(
err
)
}
)
})
})
}
}
var
checkMatchForDialects
=
function
(
value
,
expectations
)
{
if
(
!!
expectations
[
dialect
])
expect
(
value
).
toMatch
(
expectations
[
dialect
])
else
throw
new
Error
(
'Undefined expectation for "'
+
dialect
+
'"!'
)
}
beforeEach
(
function
()
{
setup
()
})
beforeEach
(
function
()
{
setup
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
...
@@ -92,7 +105,13 @@ describe('ModelFactory', function() {
...
@@ -92,7 +105,13 @@ describe('ModelFactory', function() {
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Duplicate entry 'foo' for key 'username'"
)
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
/.*Duplicate
\
entry.*/
})
done
()
done
()
})
})
})
})
...
@@ -107,11 +126,22 @@ describe('ModelFactory', function() {
...
@@ -107,11 +126,22 @@ describe('ModelFactory', function() {
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Column 'smth' cannot be null"
)
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Column 'smth' cannot be null"
})
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Duplicate entry 'foo' for key 'username'"
)
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Duplicate entry 'foo' for key 'username'"
})
done
()
done
()
})
})
})
})
...
@@ -173,9 +203,9 @@ describe('ModelFactory', function() {
...
@@ -173,9 +203,9 @@ describe('ModelFactory', function() {
User
.
all
().
success
(
function
(
users
)
{
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
expect
(
users
.
length
).
toEqual
(
0
)
done
()
done
()
})
}).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
}).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
}).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
})
})
...
@@ -420,6 +450,8 @@ describe('ModelFactory', function() {
...
@@ -420,6 +450,8 @@ describe('ModelFactory', function() {
})
})
})
})
// sqlite can't handle multiple primary keys
if
(
dialect
!=
'sqlite'
)
{
it
(
"correctly determines equality with multiple primary keys"
,
function
()
{
it
(
"correctly determines equality with multiple primary keys"
,
function
()
{
setup
({
setup
({
foo
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
foo
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
...
@@ -431,14 +463,15 @@ describe('ModelFactory', function() {
...
@@ -431,14 +463,15 @@ describe('ModelFactory', function() {
User
.
create
({
foo
:
'1'
,
bar
:
'2'
,
name
:
'hallo'
,
bio
:
'welt'
}).
success
(
function
(
u
)
{
User
.
create
({
foo
:
'1'
,
bar
:
'2'
,
name
:
'hallo'
,
bio
:
'welt'
}).
success
(
function
(
u
)
{
expect
(
u
.
equals
(
u
)).
toBeTruthy
()
expect
(
u
.
equals
(
u
)).
toBeTruthy
()
done
()
done
()
}).
error
(
function
(
err
)
{
}).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
console
.
log
(
err
)
})
})
})
})
})
}
})
})
describe
(
'equalsOneOf'
,
function
()
{
describe
(
'equalsOneOf'
,
function
()
{
// sqlite can't handle multiple primary keys
if
(
dialect
!=
'sqlite'
)
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
setup
({
setup
({
foo
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
foo
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
...
@@ -464,6 +497,7 @@ describe('ModelFactory', function() {
...
@@ -464,6 +497,7 @@ describe('ModelFactory', function() {
})
})
})
})
})
})
}
})
})
describe
(
'Mixin'
,
function
()
{
describe
(
'Mixin'
,
function
()
{
...
@@ -503,4 +537,6 @@ describe('ModelFactory', function() {
...
@@ -503,4 +537,6 @@ describe('ModelFactory', function() {
})
})
})
})
})
})
})
})
})
})
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