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) {
before
(
function
(
done
)
{
var
self
=
this
this
.
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
this
.
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
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'
,
{
username
:
Sequelize
.
STRING
,
secretValue
:
Sequelize
.
STRING
secretValue
:
Sequelize
.
STRING
,
data
:
Sequelize
.
STRING
})
self
.
sequelize
.
getQueryInterface
()
.
dropAllTables
()
.
success
(
function
()
{
self
.
sequelize
.
daoFactoryManager
.
daos
=
[]
self
.
User
this
.
User
.
sync
({
force
:
true
})
.
success
(
done
)
.
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
)
{
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
)
{
expect
(
_user
.
username
).
toEqual
(
self
.
data
.
username
);
expect
(
_user
.
secretValue
).
not
.
toEqual
(
self
.
data
.
secretValue
);
expect
(
_user
.
secretValue
).
toEqual
(
null
)
;
done
()
;
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
expect
(
_user
.
secretValue
).
toEqual
(
null
)
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
)
{
expect
(
_user
.
username
).
toEqual
(
self
.
data
.
username
);
expect
(
_user
.
secretValue
).
toEqual
(
self
.
data
.
secretValue
);
done
()
;
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
toEqual
(
data
.
secretValue
)
done
()
})
})
})
describe
(
'handle quoted data'
,
function
()
{
it
(
'saves data with single quote'
,
function
()
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
it
(
'saves data with single quote'
,
function
(
done
)
{
var
quote
=
"single'quote"
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
,
self
=
this
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
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'
)
done
()
})
})
})
})
it
(
'saves data with double quote'
,
function
()
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
it
(
'saves data with double quote'
,
function
(
done
)
{
var
quote
=
'double"quote'
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
,
self
=
this
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
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'
)
done
()
})
})
})
})
it
(
'saves stringified JSON data'
,
function
()
{
setup
({
data
:
{
type
:
Sequelize
.
STRING
}
})
it
(
'saves stringified JSON data'
,
function
(
done
)
{
var
json
=
JSON
.
stringify
({
key
:
'value'
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
,
self
=
this
this
.
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
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'
)
done
()
})
...
...
@@ -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