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
不要怂,就是干,撸起袖子干!
You need to sign in or sign up before continuing.
Commit 3836db40
authored
Feb 18, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for enums
1 parent
c2166c5a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
5 deletions
lib/dialects/postgres/query-generator.js
spec/dao-factory.spec.js
spec/sequelize.spec.js
lib/dialects/postgres/query-generator.js
View file @
3836db4
...
...
@@ -36,8 +36,13 @@ function pgEscape(val) {
return
"'"
+
val
+
"'"
;
}
function
pgEscapeAndQuote
(
val
)
{
return
addQuotes
(
removeQuotes
(
pgEscape
(
val
),
"'"
))
}
function
pgEnum
(
tableName
,
attr
,
dataType
)
{
return
"CREATE TYPE "
+
Utils
.
escape
(
"enum_"
+
tableName
+
"_"
+
attr
)
+
" AS "
+
dataType
.
match
(
/^ENUM
\(
.+
\)
/
)[
0
]
+
"; "
var
enumName
=
pgEscapeAndQuote
(
"enum_"
+
tableName
+
"_"
+
attr
)
return
"DROP TYPE IF EXISTS "
+
enumName
+
"; CREATE TYPE "
+
enumName
+
" AS "
+
dataType
.
match
(
/^ENUM
\(
.+
\)
/
)[
0
]
+
"; "
}
function
padInt
(
i
)
{
...
...
@@ -70,7 +75,7 @@ function pgDataTypeMapping(tableName, attr, dataType) {
}
if
(
dataType
.
match
(
/^ENUM
\(
/
))
{
dataType
=
dataType
.
replace
(
/^ENUM
\(
.+
\)
/
,
Utils
.
escap
e
(
"enum_"
+
tableName
+
"_"
+
attr
))
dataType
=
dataType
.
replace
(
/^ENUM
\(
.+
\)
/
,
pgEscapeAndQuot
e
(
"enum_"
+
tableName
+
"_"
+
attr
))
}
return
dataType
...
...
@@ -95,7 +100,7 @@ module.exports = (function() {
attrStr
.
push
(
addQuotes
(
attr
)
+
" "
+
dataType
)
if
(
attributes
[
attr
].
match
(
/^ENUM
\(
/
))
{
query
=
pgEnum
(
tableName
,
attr
,
attributes
[
attr
])
)
+
query
;
query
=
pgEnum
(
tableName
,
attr
,
attributes
[
attr
])
+
query
;
}
}
...
...
spec/dao-factory.spec.js
View file @
3836db4
...
...
@@ -795,8 +795,6 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}.
bind
(
this
))
//- sequelize.sync
})
})
})
//- describe: find
describe
(
'findAll'
,
function
findAll
()
{
...
...
spec/sequelize.spec.js
View file @
3836db4
...
...
@@ -114,4 +114,32 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}.
bind
(
this
))
})
})
describe
(
'define'
,
function
()
{
describe
(
'enum'
,
function
()
{
before
(
function
(
done
)
{
this
.
Review
=
this
.
sequelize
.
define
(
'review'
,
{
status
:
{
type
:
Helpers
.
Sequelize
.
ENUM
,
values
:
[
'scheduled'
,
'active'
,
'finished'
]}
})
this
.
Review
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
'correctly stores values'
,
function
(
done
)
{
this
.
Review
.
create
({
status
:
'active'
}).
success
(
function
(
review
)
{
expect
(
review
.
status
).
toEqual
(
'active'
)
done
()
})
})
it
(
'correctly loads values'
,
function
(
done
)
{
this
.
Review
.
create
({
status
:
'active'
}).
success
(
function
()
{
this
.
Review
.
findAll
().
success
(
function
(
reviews
)
{
expect
(
reviews
[
0
].
status
).
toEqual
(
'active'
)
done
()
})
}.
bind
(
this
))
})
})
})
})
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