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 46b0e5b9
authored
Dec 19, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved specs
1 parent
f37fce43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
65 deletions
spec/model.spec.js
test/Model/update-attributes.js
spec/model.spec.js
View file @
46b0e5b
...
...
@@ -367,4 +367,83 @@ describe('Model', function() {
})
})
})
describe
(
'updateAttributes'
,
function
()
{
it
(
"updates attributes in the database"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'user'
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'user'
)
user
.
updateAttributes
({
username
:
'person'
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'person'
)
done
()
})
})
})
})
it
(
"ignores unknown attributes"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
username
:
'user'
}).
success
(
function
(
user
)
{
user
.
updateAttributes
({
username
:
'person'
,
foo
:
'bar'
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'person'
)
expect
(
user
.
foo
).
toBeUndefined
()
done
()
})
})
})
})
it
(
"doesn't update primary keys or timestamps"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
,
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
sync
({
force
:
true
}).
success
(
done
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
name
:
'snafu'
,
identifier
:
'identifier'
}).
success
(
function
(
user
)
{
var
oldCreatedAt
=
user
.
createdAt
,
oldIdentifier
=
user
.
identifier
user
.
updateAttributes
({
name
:
'foobar'
,
createdAt
:
new
Date
(
2000
,
1
,
1
),
identifier
:
'another identifier'
}).
success
(
function
(
user
)
{
expect
(
user
.
createdAt
).
toEqual
(
oldCreatedAt
)
expect
(
user
.
identifier
).
toEqual
(
oldIdentifier
)
done
()
})
})
})
})
it
(
"uses primary keys in where clause"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
,
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
})
Helpers
.
async
(
function
(
done
)
{
User
.
sync
({
force
:
true
}).
success
(
done
)
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
name
:
'snafu'
,
identifier
:
'identifier'
}).
success
(
function
(
user
)
{
var
emitter
=
user
.
updateAttributes
({
name
:
'foobar'
})
emitter
.
success
(
function
()
{
expect
(
emitter
.
query
.
sql
).
toMatch
(
/WHERE `identifier`..identifier./
)
done
()
})
})
})
})
})
})
test/Model/update-attributes.js
deleted
100644 → 0
View file @
f37fce4
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}})
,
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
module
.
exports
=
{
'it should update the attributes'
:
function
(
exit
)
{
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'snafu'
}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
name
,
'snafu'
)
user
.
updateAttributes
({
name
:
'foobar'
}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
name
,
'foobar'
)
exit
(
function
(){})
})
})
})
},
'it should not set attributes which were not defined'
:
function
(
exit
)
{
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'snafu'
}).
on
(
'success'
,
function
(
user
)
{
user
.
updateAttributes
({
name
:
'foobar'
,
foo
:
'bar'
}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
name
,
'foobar'
)
assert
.
isUndefined
(
user
.
foo
)
exit
(
function
(){})
})
})
})
},
'it should not set primary keys or timestamps'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
,
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'snafu'
,
identifier
:
'identifier'
}).
on
(
'success'
,
function
(
user
)
{
var
oldCreatedAt
=
user
.
createdAt
,
oldIdentifier
=
user
.
identifier
user
.
updateAttributes
({
name
:
'foobar'
,
createdAt
:
new
Date
(
2000
,
1
,
1
),
identifier
:
'another identifier'
}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
createdAt
,
oldCreatedAt
)
assert
.
eql
(
user
.
identifier
,
oldIdentifier
)
exit
(
function
(){})
})
})
})
},
"it should use the primary keys in the where clause"
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
,
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'snafu'
,
identifier
:
'identifier'
}).
on
(
'success'
,
function
(
user
)
{
var
emitter
=
user
.
updateAttributes
({
name
:
'foobar'
})
emitter
.
success
(
function
()
{
assert
.
match
(
emitter
.
query
.
sql
,
/WHERE `identifier`..identifier./
)
})
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