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 bb8033d9
authored
Sep 30, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more buster tests
1 parent
914f1ab5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
111 deletions
spec-jasmine/dao-factory.spec.js
spec/associations/belongs-to.spec.js
spec/buster-helpers.js
spec/dao-factory.spec.js
spec-jasmine/dao-factory.spec.js
View file @
bb8033d
...
@@ -42,114 +42,6 @@ describe('DAOFactory', function() {
...
@@ -42,114 +42,6 @@ describe('DAOFactory', function() {
beforeEach
(
function
()
{
setup
()
})
beforeEach
(
function
()
{
setup
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
describe
(
'create'
,
function
()
{
it
(
"doesn't allow duplicated records with unique:true"
,
function
()
{
setup
({
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
/.*Duplicate
\
entry.*/
,
postgres
:
/.*duplicate
\
key
\
value.*/
})
done
()
})
})
})
})
it
(
"raises an error if created object breaks definition contraints"
,
function
()
{
setup
({
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Column 'smth' cannot be null"
,
postgres
:
/.*column "smth" violates not-null.*/
})
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
checkMatchForDialects
(
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Duplicate entry 'foo' for key 'username'"
,
postgres
:
/.*duplicate key value violates unique constraint.*/
})
done
()
})
})
})
})
})
it
(
'sets auto increment fields'
,
function
()
{
setup
({
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
done
()
})
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
})
})
it
(
'allows the usage of options as attribute'
,
function
()
{
setup
({
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
Helpers
.
async
(
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
User
.
create
({
name
:
'John Doe'
,
options
:
options
})
.
success
(
function
(
user
)
{
expect
(
user
.
options
).
toEqual
(
options
)
done
()
})
})
})
it
(
'allows sql logging'
,
function
()
{
setup
({
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
})
})
describe
(
'destroy'
,
function
()
{
describe
(
'destroy'
,
function
()
{
it
(
'deletes a record from the database if dao is not paranoid'
,
function
()
{
it
(
'deletes a record from the database if dao is not paranoid'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
...
...
spec/associations/belongs-to.spec.js
View file @
bb8033d
...
@@ -9,10 +9,10 @@ buster.testRunner.timeout = 500
...
@@ -9,10 +9,10 @@ buster.testRunner.timeout = 500
describe
(
'BelongsTo'
,
function
()
{
describe
(
'BelongsTo'
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
onComplete
:
done
})
})
})
})
...
...
spec/buster-helpers.js
View file @
bb8033d
...
@@ -48,5 +48,13 @@ var BusterHelpers = module.exports = {
...
@@ -48,5 +48,13 @@ var BusterHelpers = module.exports = {
return
fs
.
readdirSync
(
__dirname
+
'/../lib/dialects'
).
filter
(
function
(
file
)
{
return
fs
.
readdirSync
(
__dirname
+
'/../lib/dialects'
).
filter
(
function
(
file
)
{
return
(
file
.
indexOf
(
'.js'
)
===
-
1
)
return
(
file
.
indexOf
(
'.js'
)
===
-
1
)
})
})
},
checkMatchForDialects
:
function
(
dialect
,
value
,
expectations
)
{
if
(
!!
expectations
[
dialect
])
{
expect
(
value
).
toMatch
(
expectations
[
dialect
])
}
else
{
throw
new
Error
(
'Undefined expectation for "'
+
dialect
+
'"!'
)
}
}
}
}
}
spec/dao-factory.spec.js
View file @
bb8033d
...
@@ -94,6 +94,113 @@ dialects.forEach(function(dialect) {
...
@@ -94,6 +94,113 @@ dialects.forEach(function(dialect) {
})
})
describe
(
'create'
,
function
()
{
describe
(
'create'
,
function
()
{
it
(
"doesn't allow duplicated records with unique:true"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueUsername'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
/.*Duplicate
\
entry.*/
,
postgres
:
/.*duplicate
\
key
\
value.*/
})
done
()
})
})
})
})
it
(
"raises an error if created object breaks definition contraints"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Column 'smth' cannot be null"
,
postgres
:
/.*column "smth" violates not-null.*/
})
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Duplicate entry 'foo' for key 'username'"
,
postgres
:
/.*duplicate key value violates unique constraint.*/
})
done
()
})
})
})
})
})
it
(
'sets auto increment fields'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithAutoIncrementField'
,
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
})
})
})
it
(
'allows the usage of options as attribute'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNameAndOptions'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'John Doe'
,
options
:
options
})
.
success
(
function
(
user
)
{
expect
(
user
.
options
).
toEqual
(
options
)
done
()
})
})
})
it
(
'allows sql logging'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueNameAndNonNullSmth'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
})
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
...
...
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