From 1ff597e944fce924e5b585b59bc952649efe0665 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 22 Aug 2015 08:40:16 -0500 Subject: [PATCH] Provide group name if not provided and save --- .../spec/controllers/inviteToGroupCtrlSpec.js | 25 ++++++++++++++++++- .../js/controllers/inviteToGroupCtrl.js | 9 ++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/spec/controllers/inviteToGroupCtrlSpec.js b/test/spec/controllers/inviteToGroupCtrlSpec.js index 5aeded8c98..fef3382564 100644 --- a/test/spec/controllers/inviteToGroupCtrlSpec.js +++ b/test/spec/controllers/inviteToGroupCtrlSpec.js @@ -45,10 +45,33 @@ describe('Invite to Group Controller', function() { describe('inviteNewUsers', function() { beforeEach(function() { - scope.group = specHelper.newGroup(); + scope.group = specHelper.newGroup({ + $save: sinon.stub().returns({ + then: function(cb) { cb(); } + }) + }); 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() { it('invites user with emails', function() { scope.emails = [ diff --git a/website/public/js/controllers/inviteToGroupCtrl.js b/website/public/js/controllers/inviteToGroupCtrl.js index 1e38b9332e..7d95c543b9 100644 --- a/website/public/js/controllers/inviteToGroupCtrl.js +++ b/website/public/js/controllers/inviteToGroupCtrl.js @@ -15,7 +15,14 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', 'User', 'Groups', 'injectedG }; $scope.inviteNewUsers = function(inviteMethod) { - _inviteByMethod(inviteMethod); + if (!$scope.group.name) { + $scope.group.name = env.t('possessiveParty', {name: User.user.profile.name}); + } + + $scope.group.$save() + .then(function(res) { + _inviteByMethod(inviteMethod); + }); }; function _inviteByMethod(inviteMethod) {