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 a048f1d2
authored
Aug 02, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved Sequelize instantiation to global variable + tests for sqlQueryFor
1 parent
0034cb9f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
8 deletions
test/SequelizeTest.js
test/SequelizeTest.js
View file @
a048f1d
require
(
__dirname
+
"/../sequelize"
)
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
module
.
exports
=
{
'test constants'
:
function
(
assert
)
{
assert
.
isNotUndefined
(
Sequelize
.
STRING
)
...
...
@@ -10,41 +12,64 @@ module.exports = {
assert
.
isNotNull
(
Sequelize
.
INTEGER
)
},
'the constructor sets config correctly'
:
function
(
assert
){
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
equal
(
s
.
config
.
database
,
'sequelize_test'
)
assert
.
equal
(
s
.
config
.
username
,
'test'
)
assert
.
equal
(
s
.
config
.
password
,
'test'
)
},
'the constructor initializes empty tables hash'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
isNotUndefined
(
s
.
tables
)
assert
.
isNotNull
(
s
.
tables
)
assert
.
eql
(
s
.
tables
,
{})
},
'define should return a function'
:
function
(
assert
){
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
equal
(
typeof
Day
,
'function'
)
},
'define should store attributes'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
isNotUndefined
(
Day
.
attributes
)
assert
.
isNotNull
(
Day
.
attributes
)
assert
.
eql
(
Day
.
attributes
,
{
name
:
Sequelize
.
TEXT
,
createdAt
:
"DATETIME NOT NULL"
,
updatedAt
:
"DATETIME NOT NULL"
})
},
'define should add new table to tables'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
includes
(
SequelizeHelper
.
Hash
.
keys
(
Day
.
sequelize
.
tables
),
'Day'
)
},
'tableNames should be an empty array if no tables are specified'
:
function
(
assert
){
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
deepEqual
(
s
.
tableNames
,
[])
var
s
2
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
deepEqual
(
s
2
.
tableNames
,
[])
},
'tableNames should be no empty array if tables are specified'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
deepEqual
(
s
.
tableNames
,
[
'Days'
])
},
'sqlQueryFor: create'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'create'
,
{
table
:
'Foo'
,
fields
:
'a INT'
})
assert
.
equal
(
query
,
"CREATE TABLE IF NOT EXISTS Foo (a INT)"
)
},
'sqlQueryFor: drop'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'drop'
,
{
table
:
'Foo'
})
assert
.
equal
(
query
,
"DROP TABLE IF EXISTS Foo"
)
},
'sqlQueryFor: select'
:
function
(
assert
)
{
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
}),
"SELECT * FROM Foo"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
fields
:
'id'
}),
"SELECT id FROM Foo"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
where
:
'id = 1'
}),
"SELECT * FROM Foo WHERE id = 1"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
order
:
'id DESC'
}),
"SELECT * FROM Foo ORDER BY id DESC"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
group
:
'name'
}),
"SELECT * FROM Foo GROUP BY name"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
limit
:
1
}),
"SELECT * FROM Foo LIMIT 1"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
offset
:
10
,
limit
:
1
}),
"SELECT * FROM Foo LIMIT 10, 1"
)
},
'sqlQueryFor: insert'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
'Foo'
,
fields
:
'foo'
,
values
:
"'bar'"
})
assert
.
equal
(
query
,
"INSERT INTO Foo (foo) VALUES ('bar')"
)
},
'sqlQueryFor: update'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'update'
,
{
table
:
'Foo'
,
values
:
"foo=1"
,
id
:
2
})
assert
.
equal
(
query
,
"UPDATE Foo SET foo=1 WHERE id = 2"
)
},
'sqlQueryFor: delete'
:
function
(
assert
)
{
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
id
:
2
})
assert
.
equal
(
query
,
"DELETE FROM Foo WHERE id = 2 LIMIT 1"
)
}
}
\ No newline at end of file
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