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 12e0033b
authored
Dec 15, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more jasmine tests
1 parent
3cb68c64
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
52 deletions
spec/model-factory.spec.js
test/Model/create.js
spec/model-factory.spec.js
View file @
12e0033
...
@@ -82,6 +82,69 @@ describe('ModelFactory', function() {
...
@@ -82,6 +82,69 @@ describe('ModelFactory', function() {
})
})
})
})
describe
(
'create'
,
function
()
{
var
setup
=
function
(
userOptions
)
{
Helpers
.
dropAllTables
()
Helpers
.
async
(
function
(
done
)
{
User
=
sequelize
.
define
(
'User'
,
userOptions
)
User
.
sync
({
force
:
true
}).
success
(
done
)
})
}
it
(
"doesn't allow duplicated records with unique:true"
,
function
()
{
setup
({
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Duplicate entry 'foo' for key 'username'"
)
done
()
})
})
})
})
it
(
"raises an error if created object breaks definition contraints"
,
function
()
{
setup
({
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Column 'smth' cannot be null"
)
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
expect
(
err
.
message
).
toEqual
(
"Duplicate entry 'foo' for key 'username'"
)
done
()
})
})
})
})
})
it
(
'sets auto increment fields'
,
function
()
{
setup
({
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
done
()
})
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
})
})
})
describe
(
'find'
,
function
()
{
describe
(
'find'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
...
...
test/Model/create.js
deleted
100644 → 0
View file @
3cb68c6
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}})
var
initUsers
=
function
(
num
,
callback
)
{
return
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
}
module
.
exports
=
{
'do not allow duplicated records with unique:true'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'foo'
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'foo'
}).
on
(
'failure'
,
function
(
err
)
{
assert
.
eql
(
err
.
message
,
"Duplicate entry 'foo' for key 'username'"
)
exit
(
function
(){})
})
})
})
},
'it should raise an error if created object breaks definition constraints'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
on
(
'failure'
,
function
(
err
)
{
assert
.
eql
(
err
.
message
,
"Column 'smth' cannot be null"
)
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
on
(
'failure'
,
function
(
err
)
{
assert
.
eql
(
err
.
message
,
"Duplicate entry 'foo' for key 'username'"
)
exit
(
function
(){})
})
})
})
})
},
'it should set the auto increment field to the insert id'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
userid
,
1
)
exit
(
function
(){})
})
})
}
}
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