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 53e84f57
authored
Dec 19, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved model specs to jasmine
1 parent
8396641b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
56 deletions
spec/model.spec.js
test/Model/save.js
spec/model.spec.js
View file @
53e84f5
...
@@ -4,6 +4,18 @@ var config = require("./config/config")
...
@@ -4,6 +4,18 @@ var config = require("./config/config")
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
describe
(
'Model'
,
function
()
{
describe
(
'Model'
,
function
()
{
var
User
=
null
var
setup
=
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
done
)
})
}
beforeEach
(
function
()
{
Helpers
.
dropAllTables
();
setup
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
describe
(
'Validations'
,
function
()
{
describe
(
'Validations'
,
function
()
{
var
checks
=
{
var
checks
=
{
is
:
{
is
:
{
...
@@ -249,18 +261,6 @@ describe('Model', function() {
...
@@ -249,18 +261,6 @@ describe('Model', function() {
})
})
describe
(
'isNewRecord'
,
function
()
{
describe
(
'isNewRecord'
,
function
()
{
var
User
=
null
var
setup
=
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
done
)
})
}
beforeEach
(
function
()
{
Helpers
.
dropAllTables
();
setup
()
})
afterEach
(
function
()
{
Helpers
.
dropAllTables
()
})
it
(
'returns true for non-saved objects'
,
function
()
{
it
(
'returns true for non-saved objects'
,
function
()
{
var
user
=
User
.
build
({
username
:
'user'
})
var
user
=
User
.
build
({
username
:
'user'
})
expect
(
user
.
id
).
toBeNull
()
expect
(
user
.
id
).
toBeNull
()
...
@@ -314,4 +314,57 @@ describe('Model', function() {
...
@@ -314,4 +314,57 @@ describe('Model', function() {
})
})
})
})
})
})
describe
(
'save'
,
function
()
{
it
(
"stores an entry in the database"
,
function
()
{
var
username
=
'user'
,
user
=
User
.
build
({
username
:
username
})
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
done
()
})
})
Helpers
.
async
(
function
(
done
)
{
user
.
save
().
success
(
done
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
1
)
expect
(
users
[
0
].
username
).
toEqual
(
username
)
done
()
})
})
})
it
(
"updates the timestamps"
,
function
()
{
var
now
=
Date
.
now
()
,
user
=
null
,
updatedAt
=
null
Helpers
.
async
(
function
(
done
)
{
// timeout is needed, in order to check the update of the timestamp
setTimeout
(
function
()
{
user
=
User
.
build
({
username
:
'user'
})
updatedAt
=
user
.
updatedAt
expect
(
updatedAt
.
getTime
()).
toBeGreaterThan
(
now
)
done
()
},
10
)
})
Helpers
.
async
(
function
(
done
)
{
setTimeout
(
function
()
{
user
.
save
().
success
(
function
()
{
expect
(
updatedAt
.
getTime
()).
toBeLessThan
(
user
.
updatedAt
.
getTime
())
done
()
})
},
10
)
})
})
})
})
})
test/Model/save.js
deleted
100644 → 0
View file @
8396641
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}})
module
.
exports
=
{
'save should add a record to the database'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
u
=
User
.
build
({
name
:
'hallo'
,
bio
:
'welt'
})
User
.
all
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
0
)
u
.
save
().
on
(
'success'
,
function
()
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
1
)
assert
.
eql
(
users
[
0
].
name
,
'hallo'
)
exit
(
function
(){})
})
})
})
})
},
'save should update the timestamp updated_at'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
now
=
Date
.
now
()
// timeout is needed, in order to check the update of the timestamp
setTimeout
(
function
()
{
var
u
=
User
.
build
({
name
:
'foo'
,
bio
:
'bar'
})
,
uNow
=
u
.
updatedAt
assert
.
eql
(
true
,
uNow
.
getTime
()
>
now
)
setTimeout
(
function
()
{
u
.
save
().
on
(
'success'
,
function
()
{
assert
.
eql
(
true
,
uNow
.
getTime
()
<
u
.
updatedAt
.
getTime
())
exit
(
function
(){})
})
},
10
)
},
10
)
})
}
}
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