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 2dec5888
authored
Jul 05, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring + tests for escaping
1 parent
439b0929
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
53 deletions
spec/dao-factory.spec.js
spec/dao-factory.spec.js
View file @
2dec588
...
@@ -12,100 +12,93 @@ dialects.forEach(function(dialect) {
...
@@ -12,100 +12,93 @@ dialects.forEach(function(dialect) {
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
this
.
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
logging
:
false
this
.
sequelize
.
getQueryInterface
()
.
dropAllTables
()
.
success
(
function
()
{
self
.
sequelize
.
daoFactoryManager
.
daos
=
[]
done
()
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
})
describe
(
'create'
,
function
()
{
before
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
,
username
:
Sequelize
.
STRING
,
secretValue
:
Sequelize
.
STRING
secretValue
:
Sequelize
.
STRING
,
data
:
Sequelize
.
STRING
})
})
self
.
sequelize
this
.
User
.
getQueryInterface
()
.
dropAllTables
()
.
success
(
function
()
{
self
.
sequelize
.
daoFactoryManager
.
daos
=
[]
self
.
User
.
sync
({
force
:
true
})
.
sync
({
force
:
true
})
.
success
(
done
)
.
success
(
done
)
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
})
describe
(
'create with whitelist'
,
function
()
{
before
(
function
()
{
this
.
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
})
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
var
self
=
this
;
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
this
.
User
.
create
(
this
.
data
,
[
'username'
]).
success
(
function
(
user
)
{
this
.
User
.
create
(
data
,
[
'username'
]).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
self
.
data
.
username
);
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
not
.
toEqual
(
self
.
data
.
secretValue
);
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
expect
(
_user
.
secretValue
).
toEqual
(
null
)
;
expect
(
_user
.
secretValue
).
toEqual
(
null
)
done
()
;
done
()
})
})
})
})
})
})
it
(
'should store all values if no whitelist is specified'
,
function
(
done
)
{
it
(
'should store all values if no whitelist is specified'
,
function
(
done
)
{
var
self
=
this
;
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
this
.
User
.
create
(
this
.
data
).
success
(
function
(
user
)
{
this
.
User
.
create
(
data
).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
self
.
data
.
username
);
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
toEqual
(
self
.
data
.
secretValue
);
expect
(
_user
.
secretValue
).
toEqual
(
data
.
secretValue
)
done
()
;
done
()
})
})
})
})
})
})
describe
(
'handle quoted data'
,
function
()
{
it
(
'saves data with single quote'
,
function
(
done
)
{
it
(
'saves data with single quote'
,
function
()
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
var
quote
=
"single'quote"
var
quote
=
"single'quote"
Helpers
.
async
(
function
(
done
)
{
,
self
=
this
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory single quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'memory single quote'
)
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
done
()
done
()
})
})
})
})
})
})
})
it
(
'saves data with double quote'
,
function
()
{
it
(
'saves data with double quote'
,
function
(
done
)
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
var
quote
=
'double"quote'
var
quote
=
'double"quote'
Helpers
.
async
(
function
(
done
)
{
,
self
=
this
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory double quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'memory double quote'
)
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
done
()
done
()
})
})
})
})
})
})
})
it
(
'saves stringified JSON data'
,
function
()
{
it
(
'saves stringified JSON data'
,
function
(
done
)
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
var
json
=
JSON
.
stringify
({
key
:
'value'
})
var
json
=
JSON
.
stringify
({
key
:
'value'
})
Helpers
.
async
(
function
(
done
)
{
,
self
=
this
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'memory data'
)
expect
(
user
.
data
).
toEqual
(
json
,
'memory data'
)
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'SQL data'
)
expect
(
user
.
data
).
toEqual
(
json
,
'SQL data'
)
done
()
done
()
})
})
...
@@ -113,6 +106,4 @@ dialects.forEach(function(dialect) {
...
@@ -113,6 +106,4 @@ dialects.forEach(function(dialect) {
})
})
})
})
})
})
})
})
})
})
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