mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-02-28 01:00:59 +01:00
Fixing style, adding article test
This commit is contained in:
79
.jshintrc
79
.jshintrc
@@ -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
Makefile
1
Makefile
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,13 @@ var ArticleSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Validations
|
||||
*/
|
||||
ArticleSchema.path('title').validate(function(title) {
|
||||
return title.length;
|
||||
}, 'Title cannot be blank');
|
||||
|
||||
/**
|
||||
* Statics
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
94
package.json
94
package.json
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
window.bootstrap = function() {
|
||||
angular.bootstrap(document, ['mean']);
|
||||
}
|
||||
};
|
||||
|
||||
window.init = function() {
|
||||
window.bootstrap();
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
//Fixing facebook bug with redirect
|
||||
|
||||
58
test/article/model.js
Normal file
58
test/article/model.js
Normal file
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,51 +0,0 @@
|
||||
var
|
||||
should = require('should'),
|
||||
app = require('../../../server'),
|
||||
mongoose = require('mongoose');
|
||||
|
||||
describe('<Unit Test>', 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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
47
test/user/model.js
Normal file
47
test/user/model.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var should = require('should'),
|
||||
app = require('../../server'),
|
||||
mongoose = require('mongoose'),
|
||||
User = mongoose.model('User');
|
||||
|
||||
//Globals
|
||||
var user;
|
||||
|
||||
//The tests
|
||||
describe('<Unit Test>', function() {
|
||||
describe('Model User:', function() {
|
||||
before(function(done) {
|
||||
user = new User({
|
||||
name: 'Full name',
|
||||
email: 'test@test.com',
|
||||
username: 'user',
|
||||
password: 'password'
|
||||
});
|
||||
|
||||
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 error when try to save witout name', function(done) {
|
||||
user.name = '';
|
||||
return user.save(function(err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user