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 99a77f05
authored
Sep 22, 2014
by
overlookmotel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for Sequelize#define hooks
1 parent
b1875abb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
test/hooks.test.js
test/hooks.test.js
View file @
99a77f0
...
...
@@ -4322,6 +4322,50 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
});
});
describe
(
'#define'
,
function
()
{
before
(
function
(
done
)
{
this
.
sequelize
.
addHook
(
'beforeDefine'
,
function
(
attributes
,
options
)
{
options
.
modelName
=
'bar'
;
options
.
name
.
plural
=
'barrs'
;
attributes
.
type
=
DataTypes
.
STRING
;
});
this
.
sequelize
.
addHook
(
'afterDefine'
,
function
(
factory
)
{
factory
.
options
.
name
.
singular
=
'barr'
;
});
this
.
model
=
this
.
sequelize
.
define
(
'foo'
,
{
name
:
DataTypes
.
STRING
});
done
();
});
it
(
'beforeDefine hook can change model name'
,
function
(
done
)
{
expect
(
this
.
model
.
name
).
to
.
equal
(
'bar'
);
done
();
});
it
(
'beforeDefine hook can alter options'
,
function
(
done
)
{
expect
(
this
.
model
.
options
.
name
.
plural
).
to
.
equal
(
'barrs'
);
done
();
});
it
(
'beforeDefine hook can alter attributes'
,
function
(
done
)
{
expect
(
this
.
model
.
rawAttributes
.
type
).
to
.
be
.
ok
;
done
();
});
it
(
'afterDefine hook can alter options'
,
function
(
done
)
{
expect
(
this
.
model
.
options
.
name
.
singular
).
to
.
equal
(
'barr'
);
done
();
});
after
(
function
(
done
)
{
this
.
sequelize
.
options
.
hooks
=
{};
this
.
sequelize
.
modelManager
.
removeDAO
(
this
.
model
);
done
();
});
});
describe
(
'universal'
,
function
()
{
beforeEach
(
function
(
done
)
{
this
.
sequelize
.
addHook
(
'beforeFind'
,
function
(
options
)
{
...
...
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