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 071485f4
authored
May 11, 2015
by
Manuel Darveau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Promise-CLS shim for 'each', 'map', 'reduce' and 'filter'.
1 parent
db627a3b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
5 deletions
lib/promise.js
test/integration/cls.test.js
lib/promise.js
View file @
071485f
...
...
@@ -11,8 +11,10 @@ function shimCLS(object, functionName, fnArgs){
if
(
Promise
.
Sequelize
&&
Promise
.
Sequelize
.
cls
)
{
var
ns
=
Promise
.
Sequelize
.
cls
;
for
(
var
x
=
0
;
x
<
fnArgs
.
length
;
x
++
)
{
var
argIndex
=
x
<
0
?
arguments
.
length
+
x
:
x
;
if
(
argIndex
<
arguments
.
length
&&
typeof
arguments
[
argIndex
]
===
'function'
)
arguments
[
argIndex
]
=
ns
.
bind
(
arguments
[
argIndex
]
);
var
argIndex
=
fnArgs
[
x
]
<
0
?
arguments
.
length
+
fnArgs
[
x
]
:
fnArgs
[
x
];
if
(
argIndex
<
arguments
.
length
&&
typeof
arguments
[
argIndex
]
===
'function'
)
{
arguments
[
argIndex
]
=
ns
.
bind
(
arguments
[
argIndex
]
);
}
}
}
...
...
@@ -23,8 +25,6 @@ function shimCLS(object, functionName, fnArgs){
// Core
shimCLS
(
Promise
,
'join'
,
[
-
1
]);
shimCLS
(
Promise
,
'try'
,
[
0
]);
shimCLS
(
Promise
,
'method'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'then'
,
[
0
,
1
,
2
]);
shimCLS
(
Promise
.
prototype
,
'spread'
,
[
0
,
1
]);
shimCLS
(
Promise
.
prototype
,
'catch'
,
[
-
1
]);
...
...
@@ -40,5 +40,4 @@ shimCLS(Promise.prototype, 'each', [0]);
// Utility
shimCLS
(
Promise
.
prototype
,
'tap'
,
[
0
]);
module
.
exports
=
Promise
;
test/integration/cls.test.js
View file @
071485f
...
...
@@ -138,5 +138,155 @@ if (current.dialect.supports.transactions) {
});
});
});
describe
(
'bluebird shims'
,
function
()
{
beforeEach
(
function
()
{
// Make sure we have some data so the each, map, filter, ... actually run and validate asserts
return
this
.
sequelize
.
Promise
.
all
([
this
.
User
.
create
({
name
:
'bob'
}),
this
.
User
.
create
({
name
:
'joe'
})]);
});
it
(
'join'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
sequelize
.
Promise
.
join
(
self
.
User
.
findAll
(),
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'then fulfilled'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
then
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'then rejected'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
sequelize
.
Promise
.
reject
(
'test rejection handler'
).
then
(
null
,
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'spread'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
spread
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
},
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'catch'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
sequelize
.
Promise
.
try
(
function
()
{
throw
new
Error
(
'To test catch'
);
}).
catch
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'error'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
sequelize
.
Promise
.
try
(
function
()
{
throw
new
self
.
sequelize
.
Promise
.
OperationalError
(
'To test catch'
);
}).
error
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'finally'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
finally
(
function
(){
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'map'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
map
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'reduce'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
reduce
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'filter'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
filter
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'each'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
each
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
it
(
'tap'
,
function
()
{
var
self
=
this
;
return
this
.
sequelize
.
transaction
(
function
()
{
var
tid
=
self
.
ns
.
get
(
'transaction'
).
id
;
return
self
.
User
.
findAll
().
tap
(
function
()
{
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
be
.
ok
;
expect
(
self
.
ns
.
get
(
'transaction'
).
id
).
to
.
equal
(
tid
);
});
});
});
});
});
}
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