Skip to content

Commit

Permalink
Fixing style, adding article test
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Sep 10, 2013
1 parent 014d941 commit c42c8eb
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 148 deletions.
79 changes: 39 additions & 40 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
// http://www.jshint.com/docs/
{
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"browser": true, // Standard browser globals e.g. `window`, `document`.
"es5": true, // Allow EcmaScript 5 syntax.
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
"curly": false, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef": true, // Prohibit variable use before definition.
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"quotmark": "single", // Define quotes to string values.
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
"undef": true, // Require all non-global variables be declared before they are used.
"unused": true, // Warn unused variables.
"strict": false, // Require `use strict` pragma in every file.
"trailing": true, // Prohibit trailing whitespaces.
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
"globals": { // Globals variables.
"angular": false
},
"predef": [ // Extra globals.
"define",
"require",
"exports",
"module",
"describe",
"before",
"beforeEach",
"after",
"afterEach",
"it"
],
"indent": 2, // Specify indentation spacing
"maxlen": 120, // Max line lenght
"devel": false, // Allow development statements e.g. `console.log();`.
"noempty": true // Prohibit use of empty blocks.
}
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"browser": true, // Standard browser globals e.g. `window`, `document`.
"es5": true, // Allow EcmaScript 5 syntax.
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
"curly": false, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef": true, // Prohibit variable use before definition.
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"quotmark": "single", // Define quotes to string values.
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
"undef": true, // Require all non-global variables be declared before they are used.
"unused": true, // Warn unused variables.
"strict": false, // Require `use strict` pragma in every file.
"trailing": true, // Prohibit trailing whitespaces.
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
"globals": { // Globals variables.
"angular": true
},
"predef": [ // Extra globals.
"define",
"require",
"exports",
"module",
"describe",
"before",
"beforeEach",
"after",
"afterEach",
"it"
],
"indent": 4, // Specify indentation spacing
"maxlen": 120, // Max line lenght
"devel": false, // Allow development statements e.g. `console.log();`.
"noempty": true // Prohibit use of empty blocks.
}
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
REPORTER = spec
NODEARGS =
test:
# @./node_modules/grunt-contrib-jshint/node_modules/.bin/jshint ./**/*.js --config .jshintrc &2> /dev/null
@if [ ! -n "$(NODE_ENV)" ]; then NODE_ENV=test NODE_PATH=lib ./node_modules/grunt-nodemon/node_modules/.bin/nodemon -x ./node_modules/.bin/mocha -R $(REPORTER) -t 15000 --recursive test $(NODEARGS); else NODE_PATH=lib ./node_modules/.bin/mocha -R $(REPORTER) -t 15000 --recursive test $(NODEARGS); fi

start:
Expand Down
17 changes: 13 additions & 4 deletions app/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ exports.article = function(req, res, next, id) {
/**
* Create a article
*/
exports.create = function(req, res) {
exports.create = function(req, res) {
var article = new Article(req.body);

article.user = req.user;
article.save();
res.jsonp(article);

article.save(function(err) {
if (err) {
return res.send('users/signup', {
errors: err.errors,
article: article
});
}
else {
res.jsonp(article);
}
});
};

/**
Expand Down
7 changes: 7 additions & 0 deletions app/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ var ArticleSchema = new Schema({
}
});

/**
* Validations
*/
ArticleSchema.path('title').validate(function(title) {
return title.length;
}, 'Title cannot be blank');

/**
* Statics
*/
Expand Down
10 changes: 8 additions & 2 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ module.exports = function(app, passport, auth) {

//Setting up the users api
app.post('/users', users.create);

app.post('/users/session', passport.authenticate('local', {
failureRedirect: '/signin',
failureFlash: 'Invalid email or password.'
}), users.session);

app.get('/users/me', users.me);
app.get('/users/:userId', users.show);

Expand All @@ -21,6 +23,7 @@ module.exports = function(app, passport, auth) {
scope: ['email', 'user_about_me'],
failureRedirect: '/signin'
}), users.signin);

app.get('/auth/facebook/callback', passport.authenticate('facebook', {
failureRedirect: '/signin'
}), users.authCallback);
Expand All @@ -29,6 +32,7 @@ module.exports = function(app, passport, auth) {
app.get('/auth/github', passport.authenticate('github', {
failureRedirect: '/signin'
}), users.signin);

app.get('/auth/github/callback', passport.authenticate('github', {
failureRedirect: '/signin'
}), users.authCallback);
Expand All @@ -37,6 +41,7 @@ module.exports = function(app, passport, auth) {
app.get('/auth/twitter', passport.authenticate('twitter', {
failureRedirect: '/signin'
}), users.signin);

app.get('/auth/twitter/callback', passport.authenticate('twitter', {
failureRedirect: '/signin'
}), users.authCallback);
Expand All @@ -45,10 +50,11 @@ module.exports = function(app, passport, auth) {
app.get('/auth/google', passport.authenticate('google', {
failureRedirect: '/signin',
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
]
}), users.signin);

app.get('/auth/google/callback', passport.authenticate('google', {
failureRedirect: '/signin'
}), users.authCallback);
Expand Down
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function(grunt) {
}
},
jshint: {
all: ['gruntfile.js']
all: ['gruntfile.js', 'public/js/**/*.js', 'test/**/*.js', 'app/**/*.js']
},
compass: { //Task
dist: { //Target
Expand Down
94 changes: 47 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
{
"name": "mean",
"description": "Mongo",
"version": "1.0.0",
"private": false,
"author": "MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).",
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"scripts": {
"start": "make start",
"test": "make test",
"postinstall": "node_modules/bower/bin/bower install"
},
"dependencies": {
"express": "latest",
"jade": "latest",
"mongoose": "latest",
"connect-mongo": "latest",
"connect-flash": "latest",
"passport": "latest",
"passport-local": "latest",
"passport-facebook": "latest",
"passport-twitter": "latest",
"passport-github": "latest",
"passport-google-oauth": "latest",
"underscore": "latest",
"async": "latest",
"view-helpers": "latest",
"mean-logger": "latest",
"bower": "latest",
"forever": "latest",
"foreman": "0.0.25"
},
"devDependencies": {
"supertest": "latest",
"should": "latest",
"mocha": "latest",
"grunt": "~0.4.1",
"grunt-contrib-compass": "~0.3.0",
"grunt-contrib-watch": "~0.4.4",
"grunt-contrib-jshint": "~0.6.0",
"grunt-nodemon": "0.0.8",
"grunt-concurrent": "~0.3.0",
"web-mocha": "0.0.10"
}
}
"name": "mean",
"description": "Mongo",
"version": "1.0.0",
"private": false,
"author": "MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).",
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"scripts": {
"start": "make start",
"test": "make test",
"postinstall": "node_modules/bower/bin/bower install"
},
"dependencies": {
"express": "latest",
"jade": "latest",
"mongoose": "latest",
"connect-mongo": "latest",
"connect-flash": "latest",
"passport": "latest",
"passport-local": "latest",
"passport-facebook": "latest",
"passport-twitter": "latest",
"passport-github": "latest",
"passport-google-oauth": "latest",
"underscore": "latest",
"async": "latest",
"view-helpers": "latest",
"mean-logger": "latest",
"bower": "latest",
"forever": "latest",
"foreman": "0.0.25"
},
"devDependencies": {
"supertest": "latest",
"should": "latest",
"mocha": "latest",
"web-mocha": "0.0.10",
"grunt": "~0.4.1",
"grunt-contrib-compass": "~0.3.0",
"grunt-contrib-watch": "~0.4.4",
"grunt-contrib-jshint": "~0.6.0",
"grunt-nodemon": "0.0.8",
"grunt-concurrent": "~0.3.0"
}
}
4 changes: 2 additions & 2 deletions public/js/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
window.bootstrap = function() {
angular.bootstrap(document, ['mean']);
}
};

window.init = function() {
window.bootstrap();
}
};

$(document).ready(function() {
//Fixing facebook bug with redirect
Expand Down
58 changes: 58 additions & 0 deletions test/article/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Module dependencies.
*/
var should = require('should'),
app = require('../../server'),
mongoose = require('mongoose'),
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({
name: 'Full name',
email: 'test@test.com',
username: 'user',
password: 'password'
});

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

done();
});
});

describe('Method Save', function() {
it('should be able to save whithout 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 witout title', function(done) {
article.title = '';

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

afterEach(function(done) {
done();
});
});
});
Loading

0 comments on commit c42c8eb

Please sign in to comment.