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 914f1ab5
authored
Sep 30, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved some tests from jasmine to buster
1 parent
fe50595e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
74 deletions
spec-jasmine/dao-factory.spec.js
spec/dao-factory.spec.js
spec/sequelize.spec.js
spec-jasmine/dao-factory.spec.js
View file @
914f1ab
...
...
@@ -42,68 +42,6 @@ describe('DAOFactory', function() {
beforeEach
(
function
()
{
setup
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
describe
(
'constructor'
,
function
()
{
it
(
"uses the passed dao name as tablename if freezeTableName"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
,
{},
{
freezeTableName
:
true
})
expect
(
User
.
tableName
).
toEqual
(
'User'
)
})
it
(
"uses the pluralized daoname as tablename unless freezeTableName"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
,
{},
{
freezeTableName
:
false
})
expect
(
User
.
tableName
).
toEqual
(
'Users'
)
})
it
(
"attaches class and instance methods"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
,
{},
{
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
expect
(
User
.
doSmth
).
toBeDefined
()
expect
(
User
.
doSmth
()).
toEqual
(
1
)
expect
(
User
.
makeItSo
).
toBeUndefined
()
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
})
it
(
"throws an error if 2 autoIncrements are passed"
,
function
()
{
expect
(
function
()
{
var
User
=
sequelize
.
define
(
'User'
,
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
userscore
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
})
}).
toThrow
(
'Invalid DAO definition. Only one autoincrement field allowed.'
)
})
})
describe
(
'build'
,
function
()
{
it
(
"doesn't create database entries"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
build
({
name
:
'John Wayne'
,
bio
:
'noot'
})
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
done
()
})
})
})
it
(
"fills the objects with default values"
,
function
()
{
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
bar
:
{
type
:
Sequelize
.
DATE
},
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
})
expect
(
Task
.
build
().
title
).
toEqual
(
'a task!'
)
expect
(
Task
.
build
().
foo
).
toEqual
(
2
)
expect
(
Task
.
build
().
bar
).
toEqual
(
null
)
expect
(
Task
.
build
().
foobar
).
toEqual
(
'asd'
)
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
})
describe
(
'create'
,
function
()
{
it
(
"doesn't allow duplicated records with unique:true"
,
function
()
{
setup
({
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
...
...
spec/dao-factory.spec.js
View file @
914f1ab
...
...
@@ -10,24 +10,89 @@ buster.spec.expose()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'DAOFactory@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
this
.
sequelize
=
sequelize
this
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
data
:
DataTypes
.
STRING
})
},
}
.
bind
(
this
)
,
onComplete
:
function
(
sequelize
)
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}.
bind
(
this
)
})
})
describe
(
'constructor'
,
function
()
{
it
(
"uses the passed dao name as tablename if freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'FrozenUser'
,
{},
{
freezeTableName
:
true
})
expect
(
User
.
tableName
).
toEqual
(
'FrozenUser'
)
})
it
(
"uses the pluralized dao name as tablename unless freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'SuperUser'
,
{},
{
freezeTableName
:
false
})
expect
(
User
.
tableName
).
toEqual
(
'SuperUsers'
)
})
it
(
"attaches class and instance methods"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserWithClassAndInstanceMethods'
,
{},
{
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
expect
(
User
.
doSmth
).
toBeDefined
()
expect
(
User
.
doSmth
()).
toEqual
(
1
)
expect
(
User
.
makeItSo
).
not
.
toBeDefined
()
expect
(
User
.
build
().
doSmth
).
not
.
toBeDefined
()
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
})
it
(
"throws an error if 2 autoIncrements are passed"
,
function
()
{
try
{
var
User
=
this
.
sequelize
.
define
(
'UserWithTwoAutoIncrements'
,
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
userscore
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
}
})
// the parse shouldn't execute the following line
// this tests needs to be refactored...
// we need to use expect.toThrow when a later version than 0.6 was released
expect
(
1
).
toEqual
(
2
)
}
catch
(
e
)
{
expect
(
e
.
message
).
toEqual
(
'Invalid DAO definition. Only one autoincrement field allowed.'
)
}
})
})
describe
(
'build'
,
function
()
{
it
(
"doesn't create database entries"
,
function
(
done
)
{
this
.
User
.
build
({
username
:
'John Wayne'
})
this
.
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
done
()
})
})
it
(
"fills the objects with default values"
,
function
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
bar
:
{
type
:
Sequelize
.
DATE
},
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
})
expect
(
Task
.
build
().
title
).
toEqual
(
'a task!'
)
expect
(
Task
.
build
().
foo
).
toEqual
(
2
)
expect
(
Task
.
build
().
bar
).
toEqual
(
null
)
expect
(
Task
.
build
().
foobar
).
toEqual
(
'asd'
)
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
})
describe
(
'create'
,
function
()
{
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
var
self
=
this
...
...
spec/sequelize.spec.js
View file @
914f1ab
...
...
@@ -15,12 +15,6 @@ describe('Sequelize', function() {
})
})
describe
(
'query'
,
function
()
{
it
(
"returns the expected results as json"
,
function
()
{
expect
(
1
).
toEqual
(
1
)
})
})
describe
(
'isDefined'
,
function
()
{
it
(
"returns false if the dao wasn't defined before"
,
function
()
{
expect
(
this
.
sequelize
.
isDefined
(
'Project'
)).
toBeFalse
()
...
...
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