Provide group name if not provided and save

This commit is contained in:
Blade Barringer
2015-08-22 08:40:16 -05:00
parent 1f86babad3
commit 1ff597e944
2 changed files with 32 additions and 2 deletions

View File

@@ -45,10 +45,33 @@ describe('Invite to Group Controller', function() {
describe('inviteNewUsers', function() { describe('inviteNewUsers', function() {
beforeEach(function() { beforeEach(function() {
scope.group = specHelper.newGroup(); scope.group = specHelper.newGroup({
$save: sinon.stub().returns({
then: function(cb) { cb(); }
})
});
sandbox.stub(groups.Group, 'invite'); sandbox.stub(groups.Group, 'invite');
}); });
context('pre-invite', function() {
it('saves the group', function() {
scope.inviteNewUsers('uuid');
expect(scope.group.$save).to.be.calledOnce;
});
it('uses provided name', function() {
scope.group.name = 'test party';
scope.inviteNewUsers('uuid');
expect(group.name).to.eql('test party');
});
it('names the group if no name is provided', function() {
scope.group.name = '';
scope.inviteNewUsers('uuid');
expect(group.name).to.eql(env.t('possessiveParty', {name: user.profile.name}));
});
});
context('email', function() { context('email', function() {
it('invites user with emails', function() { it('invites user with emails', function() {
scope.emails = [ scope.emails = [

View File

@@ -15,7 +15,14 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', 'User', 'Groups', 'injectedG
}; };
$scope.inviteNewUsers = function(inviteMethod) { $scope.inviteNewUsers = function(inviteMethod) {
if (!$scope.group.name) {
$scope.group.name = env.t('possessiveParty', {name: User.user.profile.name});
}
$scope.group.$save()
.then(function(res) {
_inviteByMethod(inviteMethod); _inviteByMethod(inviteMethod);
});
}; };
function _inviteByMethod(inviteMethod) { function _inviteByMethod(inviteMethod) {