diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..c83be70aa9 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,41 @@ +// 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. +} diff --git a/.slugignore b/.slugignore new file mode 100644 index 0000000000..32bcdf1ac6 --- /dev/null +++ b/.slugignore @@ -0,0 +1 @@ +/test \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 87f8cd91a5..0abd7e4bb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: node_js node_js: - - "0.10" \ No newline at end of file + - "0.10" +env: + - NODE_ENV=travis +services: + - mongodb \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..9ac702f6a7 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +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: + @if [ ! -n "$(NODE_ENV)" ]; then NODE_ENV=development NODE_PATH=lib ./node_modules/grunt-nodemon/node_modules/.bin/nodemon server.js $(NODEARGS) ; else NODE_PATH=lib ./node_modules/.bin/foreman start; fi + +mocha: + NODE_PATH=lib ./node_modules/.bin/mocha -R $(REPORTER) -t 15000 --recursive test $(NODEARGS) + +repl: + @NODE_ENV=development NODE_PATH=lib node --debug $(NODEARGS) + +webtest: + @NODE_ENV=test NODE_PATH=lib ./node_modules/.bin/web-mocha test $(NODEARGS) + +.PHONY: jshint test repl webtest mocha diff --git a/README.md b/README.md index 2da17c30b5..bda2a98e1a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,10 @@ MEAN is a boilerplate that provides a nice starting point for [MongoDB](http://w $ npm install - We recommend using [Grunt](https://github.com/gruntjs/grunt-cli) to start the server: + Export the node Path to load your lib into project (default in HEROKU) + $ export NODE_PATH=lib + We recommend using [Grunt](https://github.com/gruntjs/grunt-cli) to start the server: $ grunt When not using grunt you can use: diff --git a/app/models/article.js b/app/models/article.js index 9c5299d953..0d56c12051 100644 --- a/app/models/article.js +++ b/app/models/article.js @@ -2,8 +2,7 @@ * Module dependencies. */ var mongoose = require('mongoose'), - env = process.env.NODE_ENV || 'development', - config = require('../../config/config')[env], + config = require('../../config/config'), Schema = mongoose.Schema; diff --git a/config/config.js b/config/config.js index a1c4b9ee06..18f307ff18 100644 --- a/config/config.js +++ b/config/config.js @@ -1,86 +1,7 @@ -var path = require('path'), - rootPath = path.normalize(__dirname + '/..'); +var _ = require('underscore'); -module.exports = { - development: { - db: 'mongodb://localhost/mean-dev', - root: rootPath, - app: { - name: 'MEAN - A Modern Stack - Development' - }, - facebook: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/facebook/callback" - }, - twitter: { - clientID: "CONSUMER_KEY", - clientSecret: "CONSUMER_SECRET", - callbackURL: "http://localhost:3000/auth/twitter/callback" - }, - github: { - clientID: 'APP_ID', - clientSecret: 'APP_SECRET', - callbackURL: 'http://localhost:3000/auth/github/callback' - }, - google: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/google/callback" - } - }, - test: { - db: 'mongodb://localhost/mean-test', - root: rootPath, - app: { - name: 'MEAN - A Modern Stack - Test' - }, - facebook: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/facebook/callback" - }, - twitter: { - clientID: "CONSUMER_KEY", - clientSecret: "CONSUMER_SECRET", - callbackURL: "http://localhost:3000/auth/twitter/callback" - }, - github: { - clientID: 'APP_ID', - clientSecret: 'APP_SECRET', - callbackURL: 'http://localhost:3000/auth/github/callback' - }, - google: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/google/callback" - } - }, - production: { - db: 'mongodb://localhost/mean', - root: rootPath, - app: { - name: 'MEAN - A Modern Stack - Production' - }, - facebook: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/facebook/callback" - }, - twitter: { - clientID: "CONSUMER_KEY", - clientSecret: "CONSUMER_SECRET", - callbackURL: "http://localhost:3000/auth/twitter/callback" - }, - github: { - clientID: 'APP_ID', - clientSecret: 'APP_SECRET', - callbackURL: 'http://localhost:3000/auth/github/callback' - }, - google: { - clientID: "APP_ID", - clientSecret: "APP_SECRET", - callbackURL: "http://localhost:3000/auth/google/callback" - } - } -}; \ No newline at end of file +// Load app configuration + +module.exports = _.extend( + require(__dirname + '/../config/env/all.js'), + require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.json') || {}) ; diff --git a/config/env/all.js b/config/env/all.js new file mode 100644 index 0000000000..fd5f16fabd --- /dev/null +++ b/config/env/all.js @@ -0,0 +1,8 @@ +var path = require('path'), +rootPath = path.normalize(__dirname + '/../..'); + +module.exports = { + root: rootPath, + port: process.env.PORT || 3000, + db: process.env.MONGOHQ_URL +} diff --git a/config/env/development.json b/config/env/development.json new file mode 100644 index 0000000000..cc3055f415 --- /dev/null +++ b/config/env/development.json @@ -0,0 +1,26 @@ +{ + "db": "mongodb://localhost/mean-dev", + "app": { + "name": "MEAN - A Modern Stack - Development" + }, + "facebook": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/facebook/callback" + }, + "twitter": { + "clientID": "CONSUMER_KEY", + "clientSecret": "CONSUMER_SECRET", + "callbackURL": "http://localhost:3000/auth/twitter/callback" + }, + "github": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/github/callback" + }, + "google": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/google/callback" + } +} \ No newline at end of file diff --git a/config/env/production.json b/config/env/production.json new file mode 100644 index 0000000000..f12ffb51e0 --- /dev/null +++ b/config/env/production.json @@ -0,0 +1,26 @@ +{ + "db": "mongodb://localhost/mean", + "app": { + "name": "MEAN - A Modern Stack - Production" + }, + "facebook": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/facebook/callback" + }, + "twitter": { + "clientID": "CONSUMER_KEY", + "clientSecret": "CONSUMER_SECRET", + "callbackURL": "http://localhost:3000/auth/twitter/callback" + }, + "github": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/github/callback" + }, + "google": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/google/callback" + } +} \ No newline at end of file diff --git a/config/env/test.json b/config/env/test.json new file mode 100644 index 0000000000..9fa16467ce --- /dev/null +++ b/config/env/test.json @@ -0,0 +1,27 @@ +{ + "db": "mongodb://localhost/mean-test", + "port": 3001, + "app": { + "name": "MEAN - A Modern Stack - Test" + }, + "facebook": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/facebook/callback" + }, + "twitter": { + "clientID": "CONSUMER_KEY", + "clientSecret": "CONSUMER_SECRET", + "callbackURL": "http://localhost:3000/auth/twitter/callback" + }, + "github": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/github/callback" + }, + "google": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/google/callback" + } +} \ No newline at end of file diff --git a/config/env/travis.json b/config/env/travis.json new file mode 100644 index 0000000000..2a2ccc980c --- /dev/null +++ b/config/env/travis.json @@ -0,0 +1,27 @@ +{ + "db": "mongodb://localhost/mean-travis", + "port": 3001, + "app": { + "name": "MEAN - A Modern Stack - Test on travis" + }, + "facebook": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/facebook/callback" + }, + "twitter": { + "clientID": "CONSUMER_KEY", + "clientSecret": "CONSUMER_SECRET", + "callbackURL": "http://localhost:3000/auth/twitter/callback" + }, + "github": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/github/callback" + }, + "google": { + "clientID": "APP_ID", + "clientSecret": "APP_SECRET", + "callbackURL": "http://localhost:3000/auth/google/callback" + } +} \ No newline at end of file diff --git a/config/express.js b/config/express.js index 93ee9a19ac..0a2d2a291b 100755 --- a/config/express.js +++ b/config/express.js @@ -4,9 +4,10 @@ var express = require('express'), mongoStore = require('connect-mongo')(express), flash = require('connect-flash'), - helpers = require('view-helpers'); + helpers = require('view-helpers'), + config = require('./config'); -module.exports = function(app, config, passport) { +module.exports = function(app, passport) { app.set('showStackError', true); //Should be placed before express.static diff --git a/config/passport.js b/config/passport.js index ddf3e04c94..7a1461e6d2 100755 --- a/config/passport.js +++ b/config/passport.js @@ -3,11 +3,12 @@ var mongoose = require('mongoose'), TwitterStrategy = require('passport-twitter').Strategy, FacebookStrategy = require('passport-facebook').Strategy, GitHubStrategy = require('passport-github').Strategy, - GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, - User = mongoose.model('User'); + GoogleStrategy = require('passport-google-oauth').Strategy, + User = mongoose.model('User'), + config = require('./config'); -module.exports = function(passport, config) { +module.exports = function(passport) { //Serialize sessions passport.serializeUser(function(user, done) { done(null, user.id); @@ -142,8 +143,8 @@ module.exports = function(passport, config) { //Use google strategy passport.use(new GoogleStrategy({ - clientID: config.google.clientID, - clientSecret: config.google.clientSecret, + consumerKey: config.google.clientID, + consumerSecret: config.google.clientSecret, callbackURL: config.google.callbackURL }, function(accessToken, refreshToken, profile, done) { diff --git a/gruntfile.js b/gruntfile.js index 02938b3651..bc099b5eed 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -66,7 +66,7 @@ module.exports = function(grunt) { }, exec: { options: { - exec: 'less' + exec: 'less' } } }, diff --git a/package.json b/package.json index 8116f84d8c..18e0b5c05d 100755 --- a/package.json +++ b/package.json @@ -1,46 +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": "NODE_ENV=development ./node_modules/.bin/forever -m 5 server.js", - "test": "NODE_ENV=test ./node_modules/.bin/mocha --reporter spec test/test-*.js", - "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" - }, - "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" - } -} \ No newline at end of file + "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" + } +} diff --git a/server.js b/server.js index c50ae94ad9..d17ed0f0f4 100755 --- a/server.js +++ b/server.js @@ -13,8 +13,8 @@ var express = require('express'), //Load configurations //if test env, load example file -var env = process.env.NODE_ENV || 'development', - config = require('./config/config')[env], +var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development', + config = require('./config/config'), auth = require('./config/middlewares/authorization'), mongoose = require('mongoose'); @@ -28,18 +28,18 @@ fs.readdirSync(models_path).forEach(function(file) { }); //bootstrap passport config -require('./config/passport')(passport, config); +require('./config/passport')(passport); var app = express(); //express settings -require('./config/express')(app, config, passport); +require('./config/express')(app, passport); //Bootstrap routes require('./config/routes')(app, passport, auth); //Start the app by listening on -var port = process.env.PORT || 3000; +var port = config.port; app.listen(port); console.log('Express app started on port ' + port); diff --git a/test/unit/user/model.test.js b/test/unit/user/model.test.js new file mode 100644 index 0000000000..528bc5b3c7 --- /dev/null +++ b/test/unit/user/model.test.js @@ -0,0 +1,51 @@ +var + should = require('should'), + app = require('../../../server'), + mongoose = require('mongoose'); + +describe('', function() { + + describe('Model User:', function() { + var User = mongoose.model('User'), + user; + + beforeEach(function (done) { + user = new User({ + name: 'Full name', + email: 'test@test.com', + username: 'user', + password: 'password' + }); + done(); + }); + + afterEach(function (done) { + + done(); + + }); + + describe('Method Save', function() { + + it('should be able to save whithout problems', function (done) { + + return user.save(function (err) { + should.not.exist(err); + done(); + }); + + }); + + it('should be able to show an erro when try to save witout name', function (done) { + user.name = ''; + return user.save(function (err) { + should.exist(err); + done(); + }); + }); + + }); + + }); + +});