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 161c429e
authored
Dec 05, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec fix
1 parent
e7b06830
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
25 deletions
lib/migrator.js
spec/config/helpers.js
spec/migration.spec.js
spec/migrator.spec.js
lib/migrator.js
View file @
161c429
...
...
@@ -102,19 +102,23 @@ module.exports = (function() {
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
SequelizeMeta
=
self
.
sequelize
.
modelManager
.
getModel
(
'SequelizeMeta'
)
var
storedModel
=
self
.
sequelize
.
modelManager
.
getModel
(
'SequelizeMeta'
)
,
SequelizeMeta
=
storedModel
if
(
SequelizeMeta
)
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
}
else
{
if
(
!
storedModel
)
{
SequelizeMeta
=
self
.
sequelize
.
define
(
'SequelizeMeta'
,
{
lastMigrationId
:
DataTypes
.
STRING
})
}
// force sync when model has newly created or if syncOptions are passed
if
(
!
storedModel
||
syncOptions
)
{
SequelizeMeta
.
sync
(
syncOptions
||
{})
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}
else
{
emitter
.
emit
(
'success'
,
SequelizeMeta
)
}
}).
run
()
}
...
...
spec/config/helpers.js
View file @
161c429
...
...
@@ -25,6 +25,18 @@ Helpers.prototype.drop = function() {
})
}
Helpers
.
prototype
.
dropAllTables
=
function
()
{
var
self
=
this
this
.
async
(
function
(
done
)
{
self
.
sequelize
.
getQueryInterface
()
.
dropAllTables
()
.
success
(
done
)
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
}
Helpers
.
prototype
.
async
=
function
(
fct
)
{
var
done
=
false
runs
(
function
()
{
...
...
spec/migration.spec.js
View file @
161c429
...
...
@@ -26,21 +26,19 @@ describe('Migration', function() {
},
{
topic
:
function
(
migration
,
DataTypes
)
{
migration
.
createTable
()
migration
.
createTable
()
},
expectation
:
true
},
{
topic
:
function
(
migration
,
DataTypes
)
{
migration
.
createTable
()
migration
.
createTable
()
},
expectation
:
true
},
{
topic
:
function
(
migration
,
DataTypes
)
{
migration
.
createTable
()
migration
.
createTable
()
},
expectation
:
true
}
...
...
spec/migrator.spec.js
View file @
161c429
...
...
@@ -16,15 +16,22 @@ describe('Migrator', function() {
},
_options
||
{})
migrator
=
new
Migrator
(
sequelize
,
options
)
migrator
.
findOrCreateSequelizeMetaModel
({
force
:
true
}).
success
(
function
(
_SequelizeMeta
)
{
SequelizeMeta
=
_SequelizeMeta
done
()
})
migrator
.
findOrCreateSequelizeMetaModel
({
force
:
true
})
.
success
(
function
(
_SequelizeMeta
)
{
SequelizeMeta
=
_SequelizeMeta
done
()
})
})
}
beforeEach
(
function
()
{
migrator
=
null
})
afterEach
(
function
()
{
migrator
=
null
})
var
reset
=
function
()
{
migrator
=
null
Helpers
.
dropAllTables
()
}
beforeEach
(
reset
)
afterEach
(
reset
)
describe
(
'getUndoneMigrations'
,
function
()
{
it
(
"returns no files if timestamps are after the files timestamp"
,
function
()
{
...
...
@@ -103,17 +110,10 @@ describe('Migrator', function() {
})
})
afterEach
(
function
()
{
migrator
=
null
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
dropAllTables
().
success
(
done
).
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
})
it
(
"executes migration #20111117063700 and correctly creates the table"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
slice
(
'SequelizeMeta'
,
1
)
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
}
)
expect
(
tableNames
.
length
).
toEqual
(
1
)
expect
(
tableNames
[
0
]).
toEqual
(
'Person'
)
done
()
...
...
@@ -124,7 +124,7 @@ describe('Migrator', function() {
it
(
"executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
slice
(
'SequelizeMeta'
,
1
)
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
}
)
expect
(
tableNames
.
length
).
toEqual
(
1
)
done
()
})
...
...
@@ -133,7 +133,7 @@ describe('Migrator', function() {
Helpers
.
async
(
function
(
done
)
{
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
slice
(
'SequelizeMeta'
,
1
)
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
}
)
expect
(
tableNames
.
length
).
toEqual
(
0
)
done
()
}).
error
(
function
(
err
){
console
.
log
(
err
);
done
()
})
...
...
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