mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
parent
f5a3a05951
commit
49660ff703
@ -5,9 +5,11 @@ var testUtils = require('../../utils'),
|
||||
when = require('when'),
|
||||
sinon = require('sinon'),
|
||||
uuid = require('node-uuid'),
|
||||
_ = require('lodash'),
|
||||
|
||||
// Stuff we are testing
|
||||
UserModel = require('../../../server/models').User,
|
||||
RoleModel = require('../../../server/models').Role,
|
||||
context = testUtils.context.admin,
|
||||
sandbox = sinon.sandbox.create();
|
||||
|
||||
@ -125,7 +127,7 @@ describe('User Model', function run() {
|
||||
});
|
||||
|
||||
describe('Basic Operations', function () {
|
||||
beforeEach(testUtils.setup('owner'));
|
||||
beforeEach(testUtils.setup('owner', 'role'));
|
||||
|
||||
it('sets last login time on successful login', function (done) {
|
||||
var userData = testUtils.DataGenerator.forModel.users[0];
|
||||
@ -211,6 +213,28 @@ describe('User Model', function run() {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('can add', function (done) {
|
||||
var userData = testUtils.DataGenerator.forModel.users[2];
|
||||
|
||||
sandbox.stub(UserModel, 'gravatarLookup', function (userData) {
|
||||
return when.resolve(userData);
|
||||
});
|
||||
|
||||
RoleModel.findOne().then(function (role) {
|
||||
userData.roles = [role.toJSON()];
|
||||
|
||||
return UserModel.add(userData, _.extend({}, context));
|
||||
}).then(function (createdUser) {
|
||||
should.exist(createdUser);
|
||||
createdUser.has('uuid').should.equal(true);
|
||||
createdUser.get('password').should.not.equal(userData.password, 'password was hashed');
|
||||
createdUser.get('email').should.eql(userData.email, 'email address correct');
|
||||
createdUser.related('roles').toJSON()[0].name.should.eql('Administrator', 'role set correctly');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('can destroy', function (done) {
|
||||
var firstUser = {id: 1};
|
||||
|
||||
|
@ -414,7 +414,8 @@ DataGenerator.forModel = (function () {
|
||||
|
||||
var posts,
|
||||
tags,
|
||||
users;
|
||||
users,
|
||||
roles;
|
||||
|
||||
posts = _.map(DataGenerator.Content.posts, function (post) {
|
||||
return _.pick(post, 'title', 'markdown');
|
||||
@ -430,10 +431,15 @@ DataGenerator.forModel = (function () {
|
||||
}, user);
|
||||
});
|
||||
|
||||
roles = _.map(DataGenerator.Content.roles, function (role, id) {
|
||||
return _.extend({}, role, {id: id + 1});
|
||||
});
|
||||
|
||||
return {
|
||||
posts: posts,
|
||||
tags: tags,
|
||||
users: users
|
||||
users: users,
|
||||
roles: roles
|
||||
};
|
||||
|
||||
}());
|
||||
|
Loading…
Reference in New Issue
Block a user