不要怂,就是干,撸起袖子干!

Commit f651219f by sdepold

find specs

1 parent 9215d003
......@@ -201,8 +201,12 @@ describe('ModelFactory', function() {
})
describe('find', function() {
var users = []
beforeEach(function() {
Helpers.Factories.User({name: 'user', bio: 'foobar'}, null, 2)
Helpers.Factories.User({name: 'user', bio: 'foobar'}, function(_users) {
users = _users
}, 2)
})
it("should make aliased attributes available", function() {
......@@ -213,6 +217,45 @@ describe('ModelFactory', function() {
})
})
})
it('returns a single model', function() {
Helpers.async(function(done) {
User.find(users[0].id).success(function(user) {
expect(Array.isArray(user)).toBeFalsy()
expect(user.id).toEqual(users[0].id)
done()
})
})
})
it('finds a specific user via where option', function() {
Helpers.async(function(done) {
User.find({where: { name: 'user' }}).success(function(user) {
expect(user.name).toEqual('user')
done()
})
})
})
it("doesn't find a user if conditions are not matching", function() {
Helpers.async(function(done) {
User.find({ where: { name: 'foo' } }).success(function(user) {
expect(user).toBeNull()
done()
})
})
})
it('ignores passed limit option', function() {
Helpers.async(function(done) {
User.find({limit: 10}).success(function(user) {
// it returns an object instead of an array
expect(Array.isArray(user)).toBeFalsy()
expect(user.hasOwnProperty('name')).toBeTruthy()
done()
})
})
})
})
describe('all', function() {
......
......@@ -18,48 +18,6 @@ var initUsers = function(num, callback) {
}
module.exports = {
'all should return all created models': function(exit) {
initUsers(2, function(_, User) {
User.all().on('success', function(users) {
assert.eql(users.length, 2)
exit(function(){})
})
})
},
'find should return a single model': function(exit) {
initUsers(2, function(lastInsertedUser, User) {
User.find(lastInsertedUser.id).on('success', function(user) {
assert.eql(user.id, lastInsertedUser.id)
exit(function(){})
})
})
},
'find a specific user': function(exit) {
initUsers(2, function(_, User) {
var username = 'user1'
User.find({where: {name: username}}).on('success', function(user) {
assert.eql(user.name, username)
exit(function(){})
})
})
},
'should find no user with invalid conditions': function(exit) {
initUsers(2, function(_, User) {
User.find({where: {name: 'foo'}}).on('success', function(user) {
assert.eql(user, null)
exit(function(){})
})
})
},
'find should ignore passed limit': function(exit) {
initUsers(2, function(_, User) {
User.find({limit: 10}).on('success', function(user) {
// it returns an object instead of an array
assert.eql(user.hasOwnProperty('name'), true)
exit(function(){})
})
})
},
'find should find records by primaryKeys': function(exit) {
var User = sequelize.define('User' + config.rand(), {
identifier: {type: Sequelize.STRING, primaryKey: true},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!