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 c2a52990
authored
Dec 21, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test sqlite specific specs also via file storage
1 parent
5c0733bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
95 deletions
spec/sqlite/model-factory.spec.js
spec/sqlite/model-factory.spec.js
View file @
c2a5299
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
dialect
:
'sqlite'
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
dbFile
=
__dirname
+
'/test.sqlite'
,
storages
=
[
':memory:'
,
dbFile
]
describe
(
'ModelFactory'
,
function
()
{
var
User
=
null
storages
.
forEach
(
function
(
storage
)
{
describe
(
'with storage "'
+
storage
+
'"'
,
function
()
{
var
User
=
null
,
sequelize
=
null
,
Helpers
=
null
beforeEach
(
function
()
{
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
dialect
:
'sqlite'
,
storage
:
storage
})
beforeEach
(
function
()
{
User
=
sequelize
.
define
(
'User'
,
{
age
:
Sequelize
.
INTEGER
,
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
Helpers
.
sync
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
describe
(
'create'
,
function
()
{
it
(
'creates a table entry'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
age
:
21
,
name
:
'John Wayne'
,
bio
:
'noot noot'
})
.
success
(
done
)
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
User
=
sequelize
.
define
(
'User'
,
{
age
:
Sequelize
.
INTEGER
,
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
Helpers
.
sync
()
})
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
success
(
function
(
users
)
{
var
usernames
=
users
.
map
(
function
(
user
)
{
return
user
.
name
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
if
(
storage
==
dbFile
)
{
Helpers
.
async
(
function
(
done
)
{
require
(
"fs"
).
unlink
(
__dirname
+
'/test.sqlite'
,
done
)
})
expect
(
usernames
).
toEqual
([
'John Wayne'
])
done
()
}).
error
(
function
(
err
){
console
.
log
(
err
)
})
}
})
})
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
var
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
describe
(
'create'
,
function
()
{
it
(
'creates a table entry'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
age
:
21
,
name
:
'John Wayne'
,
bio
:
'noot noot'
})
.
success
(
done
)
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
Helpers
.
async
(
function
(
done
)
{
Person
.
sync
({
force
:
true
}).
success
(
done
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
success
(
function
(
users
)
{
var
usernames
=
users
.
map
(
function
(
user
)
{
return
user
.
name
})
expect
(
usernames
).
toEqual
([
'John Wayne'
])
done
()
}).
error
(
function
(
err
){
console
.
log
(
err
)
})
})
})
Helpers
.
async
(
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
Helpers
.
Factories
.
Model
(
'Person'
,
{
name
:
'John Doe'
,
options
:
options
},
function
(
people
)
{
expect
(
people
[
0
].
options
).
toEqual
(
options
)
done
()
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
var
Person
=
sequelize
.
define
(
'Person'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
Helpers
.
async
(
function
(
done
)
{
Person
.
sync
({
force
:
true
}).
success
(
done
)
})
Helpers
.
async
(
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
Helpers
.
Factories
.
Model
(
'Person'
,
{
name
:
'John Doe'
,
options
:
options
},
function
(
people
)
{
expect
(
people
[
0
].
options
).
toEqual
(
options
)
done
()
})
})
})
})
})
})
////////// find //////////////
////////// find //////////////
describe
(
'.find'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
})
describe
(
'.find'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
})
it
(
"finds normal lookups"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'user'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'user'
)
done
()
it
(
"finds normal lookups"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'user'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'user'
)
done
()
})
})
})
})
})
it
(
"should make aliased attributes available"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'user'
},
attributes
:
[
'id'
,
[
'name'
,
'username'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'user'
)
done
()
it
(
"should make aliased attributes available"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'user'
},
attributes
:
[
'id'
,
[
'name'
,
'username'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'user'
)
done
()
})
})
})
})
})
})
////////// all //////////////
////////// all //////////////
describe
(
'.all'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
})
describe
(
'.all'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
})
it
(
"should return all users"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
done
()
expect
(
users
.
length
).
toEqual
(
2
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
it
(
"should return all users"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
done
()
expect
(
users
.
length
).
toEqual
(
2
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
})
////////// min //////////////
////////// min //////////////
describe
(
'.min'
,
function
()
{
it
(
"should return the min value"
,
function
()
{
for
(
var
i
=
2
;
i
<
5
;
i
++
)
Helpers
.
Factories
.
User
({
age
:
i
})
describe
(
'.min'
,
function
()
{
it
(
"should return the min value"
,
function
()
{
for
(
var
i
=
2
;
i
<
5
;
i
++
)
Helpers
.
Factories
.
User
({
age
:
i
})
Helpers
.
async
(
function
(
done
)
{
User
.
min
(
'age'
).
on
(
'success'
,
function
(
min
)
{
expect
(
min
).
toEqual
(
2
);
done
()
Helpers
.
async
(
function
(
done
)
{
User
.
min
(
'age'
).
on
(
'success'
,
function
(
min
)
{
expect
(
min
).
toEqual
(
2
);
done
()
})
})
})
})
})
})
////////// max //////////////
////////// max //////////////
describe
(
'.max'
,
function
()
{
it
(
"should return the max value"
,
function
()
{
for
(
var
i
=
2
;
i
<=
5
;
i
++
)
Helpers
.
Factories
.
User
({
age
:
i
})
describe
(
'.max'
,
function
()
{
it
(
"should return the max value"
,
function
()
{
for
(
var
i
=
2
;
i
<=
5
;
i
++
)
Helpers
.
Factories
.
User
({
age
:
i
})
Helpers
.
async
(
function
(
done
)
{
User
.
max
(
'age'
).
on
(
'success'
,
function
(
min
)
{
expect
(
min
).
toEqual
(
5
);
done
()
Helpers
.
async
(
function
(
done
)
{
User
.
max
(
'age'
).
on
(
'success'
,
function
(
min
)
{
expect
(
min
).
toEqual
(
5
);
done
()
})
})
})
})
})
...
...
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