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 7ec7f8a6
authored
Nov 15, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transaction tests for create and all
1 parent
8cab571a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
28 deletions
test/dao-factory.test.js
test/dao-factory.test.js
View file @
7ec7f8a
...
@@ -429,6 +429,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -429,6 +429,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe
(
'findOrCreate'
,
function
()
{
describe
(
'findOrCreate'
,
function
()
{
it
(
"supports transactions"
,
function
(
done
)
{
var
self
=
this
Support
.
prepareTransactionTest
(
dialect
,
this
.
sequelize
,
function
(
sequelize
)
{
var
User
=
sequelize
.
define
(
'user_with_transaction'
,
{
username
:
Sequelize
.
STRING
,
data
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
})
.
success
(
function
()
{
sequelize
.
transaction
(
function
(
t
)
{
User
.
findOrCreate
({
username
:
'Username'
},
{
data
:
'some data'
},
{
transaction
:
t
}).
complete
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
null
User
.
count
().
success
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
0
)
t
.
commit
().
success
(
function
()
{
User
.
count
().
success
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
})
})
it
(
"returns instance if already existent. Single find field."
,
function
(
done
)
{
it
(
"returns instance if already existent. Single find field."
,
function
(
done
)
{
var
self
=
this
,
var
self
=
this
,
data
=
{
data
=
{
...
@@ -480,34 +508,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -480,34 +508,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
done
()
done
()
})
})
})
})
it
(
"supports transactions"
,
function
(
done
)
{
var
self
=
this
Support
.
prepareTransactionTest
(
dialect
,
this
.
sequelize
,
function
(
sequelize
)
{
var
User
=
sequelize
.
define
(
'user_with_transaction'
,
{
username
:
Sequelize
.
STRING
,
data
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
})
.
success
(
function
()
{
sequelize
.
transaction
(
function
(
t
)
{
User
.
findOrCreate
({
username
:
'Username'
},
{
data
:
'some data'
},
{
transaction
:
t
}).
complete
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
null
User
.
count
().
success
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
0
)
t
.
commit
().
success
(
function
()
{
User
.
count
().
success
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
})
})
})
})
describe
(
'create'
,
function
()
{
describe
(
'create'
,
function
()
{
...
@@ -3204,6 +3204,27 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -3204,6 +3204,27 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
dialect
,
this
.
sequelize
,
function
(
sequelize
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
sequelize
.
transaction
(
function
(
t
)
{
User
.
create
({
username
:
'foo'
},
{
transaction
:
t
}).
success
(
function
()
{
User
.
findAndCountAll
().
success
(
function
(
info1
)
{
User
.
findAndCountAll
({
transaction
:
t
}).
success
(
function
(
info2
)
{
expect
(
info1
.
count
).
to
.
equal
(
0
)
expect
(
info2
.
count
).
to
.
equal
(
1
)
t
.
rollback
().
success
(
done
)
})
})
})
})
})
})
})
it
(
"handles where clause [only]"
,
function
(
done
)
{
it
(
"handles where clause [only]"
,
function
(
done
)
{
this
.
User
.
findAndCountAll
({
where
:
"id != "
+
this
.
users
[
0
].
id
}).
success
(
function
(
info
)
{
this
.
User
.
findAndCountAll
({
where
:
"id != "
+
this
.
users
[
0
].
id
}).
success
(
function
(
info
)
{
expect
(
info
.
count
).
to
.
equal
(
2
)
expect
(
info
.
count
).
to
.
equal
(
2
)
...
@@ -3271,6 +3292,26 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -3271,6 +3292,26 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
dialect
,
this
.
sequelize
,
function
(
sequelize
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
sequelize
.
transaction
(
function
(
t
)
{
User
.
create
({
username
:
'foo'
},
{
transaction
:
t
}).
success
(
function
()
{
User
.
all
().
success
(
function
(
users1
)
{
User
.
all
({
transaction
:
t
}).
success
(
function
(
users2
)
{
expect
(
users1
.
length
).
to
.
equal
(
0
)
expect
(
users2
.
length
).
to
.
equal
(
1
)
t
.
rollback
().
success
(
done
)
})
})
})
})
})
})
})
it
(
"should return all users"
,
function
(
done
)
{
it
(
"should return all users"
,
function
(
done
)
{
this
.
User
.
all
().
on
(
'success'
,
function
(
users
)
{
this
.
User
.
all
().
on
(
'success'
,
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
2
)
expect
(
users
.
length
).
to
.
equal
(
2
)
...
...
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