Skip to content

Commit

Permalink
fix(projects): current user roles were not being shown
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Oct 23, 2013
1 parent aa56367 commit 91b3d13
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 14 deletions.
12 changes: 5 additions & 7 deletions client/src/app/projects/projects-list.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
</thead>
<tbody>
<tr ng-repeat="project in projects">
<td ng-click="manageBacklog(project.$id())">{{project.name}}</td>
<td ng-click="manageBacklog(project.$id())">{{project.desc}}</td>
<td ng-click="manageBacklog(project)">{{project.name}}</td>
<td ng-click="manageBacklog(project)">{{project.desc}}</td>
<td>{{ getMyRoles(project) }}</td>
<td>
{{project.getRoles(authService.currentUser.id)}}
</td>
<td>
<a ng-click="manageBacklog(project.$id())">Product backlog</a>
<a ng-click="manageSprints(project.$id())">Sprints</a>
<a ng-click="manageBacklog(project)">Product backlog</a>
<a ng-click="manageSprints(project)">Sprints</a>
</td>
</tr>
</tbody>
Expand Down
18 changes: 11 additions & 7 deletions client/src/app/projects/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ angular.module('projects', ['resources.projects', 'productbacklog', 'sprints', '
});
}])

.controller('ProjectsViewCtrl', ['$scope', '$location', 'projects', function ($scope, $location, projects) {
.controller('ProjectsViewCtrl', ['$scope', '$location', 'projects', 'security', function ($scope, $location, projects, security) {
$scope.projects = projects;

$scope.viewProject = function (projectId) {
$location.path('/projects/'+projectId);
$scope.viewProject = function (project) {
$location.path('/projects/'+project.$id());
};

$scope.manageBacklog = function (projectId) {
$location.path('/projects/'+projectId+'/productbacklog');
$scope.manageBacklog = function (project) {
$location.path('/projects/'+project.$id()+'/productbacklog');
};

$scope.manageSprints = function (projectId) {
$location.path('/projects/'+projectId+'/sprints');
$scope.manageSprints = function (project) {
$location.path('/projects/'+project.$id()+'/sprints');
};

$scope.getMyRoles = function(project) {
return project.getRoles(security.currentUser.id);
};
}]);
84 changes: 84 additions & 0 deletions client/test/unit/app/projects/projects.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
describe('ProjectsViewCtrl', function() {

beforeEach(module('projects'));

function runController($scope, projects) {
inject(function($controller) {
$controller('ProjectsViewCtrl', { $scope: $scope, projects: projects });
});
}

function createMockProject(id) {
return {
$id: function() { return id; },
getRoles: jasmine.createSpy('getRoles')
};
}

function createMockProjectList() {
return [ createMockProject('project-id') ];
}

it("attaches the list of projects to the scope", function() {
var $scope = {},
projects = createMockProjectList();

runController($scope, projects);
expect($scope.projects).toBe(projects);
});

describe('viewProject(projectId)', function() {
var $scope = {},
projects = createMockProjectList();

it('changes the location', inject(function($location) {
spyOn($location, 'path');
runController($scope, projects);

$scope.viewProject(projects[0]);

expect($location.path).toHaveBeenCalledWith('/projects/project-id');
}));
});

describe('manageBacklog(projectId)', function() {
var $scope = {},
projects = createMockProjectList();

it('changes the location', inject(function($location) {
spyOn($location, 'path');
runController($scope, projects);

$scope.manageBacklog(projects[0]);

expect($location.path).toHaveBeenCalledWith('/projects/project-id/productbacklog');
}));
});

describe('manageSprints(projectId)', function() {
var $scope = {},
projects = createMockProjectList();

it('changes the location', inject(function($location) {
spyOn($location, 'path');
runController($scope, projects);

$scope.manageSprints(projects[0]);

expect($location.path).toHaveBeenCalledWith('/projects/project-id/sprints');
}));
});

describe('getMyRoles(project)', function() {
var $scope = {},
projects = createMockProjectList();

it('calls getRoles on the project with the current user', inject(function(security) {
security.currentUser = { id: 'current-user-id'};
runController($scope, projects);
$scope.getMyRoles(projects[0]);
expect(projects[0].getRoles).toHaveBeenCalledWith('current-user-id');
}));

});
});

0 comments on commit 91b3d13

Please sign in to comment.