Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Complete Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Apr 2, 2014
1 parent c11c428 commit d7fb398
Show file tree
Hide file tree
Showing 23 changed files with 312 additions and 309 deletions.
9 changes: 6 additions & 3 deletions app/routes/articles.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

module.exports = function(app) {
var users = require('../../app/controllers/users');
var articles = require('../../app/controllers/articles');
/**
* Module dependencies.
*/
var users = require('../../app/controllers/users'),
articles = require('../../app/controllers/articles');

module.exports = function(app) {
// Article Routes
app.get('/articles', articles.list);
app.post('/articles', users.requiresLogin, articles.create);
Expand Down
3 changes: 3 additions & 0 deletions app/routes/users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

/**
* Module dependencies.
*/
var passport = require('passport');

module.exports = function(app) {
Expand Down
81 changes: 41 additions & 40 deletions app/tests/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,57 @@ var should = require('should'),
User = mongoose.model('User'),
Article = mongoose.model('Article');

//Globals
var user;
var article;

//The tests
describe('<Unit Test>', function() {
describe('Model Article:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password'
});
/**
* Globals
*/
var user, article;

user.save(function() {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
});
/**
* Unit tests
*/
describe('Article Model Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password'
});

done();
user.save(function() {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
});

done();
});
});

describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return article.save(function(err) {
should.not.exist(err);
done();
});
describe('Method Save', function() {
it('should be able to save without problems', function(done) {
return article.save(function(err) {
should.not.exist(err);
done();
});
});

it('should be able to show an error when try to save without title', function(done) {
article.title = '';
it('should be able to show an error when try to save without title', function(done) {
article.title = '';

return article.save(function(err) {
should.exist(err);
done();
});
return article.save(function(err) {
should.exist(err);
done();
});
});
});

afterEach(function(done) {
Article.remove().exec();
User.remove().exec();
done();
});
afterEach(function(done) {
Article.remove().exec();
User.remove().exec();
done();
});
});
102 changes: 52 additions & 50 deletions app/tests/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,69 @@ var should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User');

//Globals
/**
* Globals
*/
var user, user2;

//The tests
describe('<Unit Test>', function() {
describe('Model User:', function() {
before(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password',
provider: 'local'
});
user2 = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password',
provider: 'local'
});

done();
/**
* Unit tests
*/
describe('User Model Unit Tests:', function() {
before(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password',
provider: 'local'
});
user2 = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password',
provider: 'local'
});

describe('Method Save', function() {
it('should begin with no users', function(done) {
User.find({}, function(err, users) {
users.should.have.length(0);
done();
});
});
done();
});

it('should be able to save whithout problems', function(done) {
user.save(done);
describe('Method Save', function() {
it('should begin with no users', function(done) {
User.find({}, function(err, users) {
users.should.have.length(0);
done();
});
});

it('should fail to save an existing user again', function(done) {
user.save();
return user2.save(function(err) {
should.exist(err);
done();
});
});
it('should be able to save whithout problems', function(done) {
user.save(done);
});

it('should be able to show an error when try to save without first name', function(done) {
user.firstName = '';
return user.save(function(err) {
should.exist(err);
done();
});
it('should fail to save an existing user again', function(done) {
user.save();
return user2.save(function(err) {
should.exist(err);
done();
});
});

after(function(done) {
User.remove().exec();
done();
it('should be able to show an error when try to save without first name', function(done) {
user.firstName = '';
return user.save(function(err) {
should.exist(err);
done();
});
});
});

after(function(done) {
User.remove().exec();
done();
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"grunt-env": "~0.4.1",
"grunt-node-inspector": "~0.1.3",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-jshint": "~0.9.2",
"grunt-contrib-jshint": "~0.10.0",
"grunt-nodemon": "~0.2.0",
"grunt-concurrent": "~0.5.0",
"grunt-mocha-test": "~0.10.0",
Expand Down
2 changes: 1 addition & 1 deletion public/modules/articles/articles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('mean.articles');
ApplicationConfiguration.registerModule('articles');
4 changes: 2 additions & 2 deletions public/modules/articles/config/routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

//Setting up route
angular.module('mean.articles').config(['$stateProvider',
// Setting up route
angular.module('articles').config(['$stateProvider',
function($stateProvider) {
// Articles state routing
$stateProvider.
Expand Down
2 changes: 1 addition & 1 deletion public/modules/articles/controllers/articles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('mean.articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles',
angular.module('articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles',
function($scope, $stateParams, $location, Authentication, Articles) {
$scope.authentication = Authentication;

Expand Down
4 changes: 2 additions & 2 deletions public/modules/articles/services/articles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

//Articles service used for articles REST endpoint
angular.module('mean.articles').factory('Articles', ['$resource', function($resource) {
//Articles service used for communicating with the articles REST endpoints
angular.module('articles').factory('Articles', ['$resource', function($resource) {
return $resource('articles/:articleId', {
articleId: '@_id'
}, {
Expand Down
Loading

0 comments on commit d7fb398

Please sign in to comment.