text:
'use strict';

/*jshint expr:true */

/**
 * Module dependencies.
 */

var should = require('should'),
	mongoose = require('mongoose'),
 	http = require('http'),
 	superagent = require('superagent'),
 	Evnt = mongoose.model('Event'),
 	User = mongoose.model('User'),
 	config = require('../../config/config'),
 	request = require('supertest');

/**
 * Globals
 */
var event1, event2, numEvents = 2, user, userAdmin;
var agent = superagent.agent();
var agentAdmin = superagent.agent();

function arraysEqual(array0,array1) {
    if (array0.length !== array1.length) return false;
    for (var i = 0; i<array0.length; i++) {
        if (array0[i] !== array1[i]) return false;
    }
    return true;
}

/**
 * Unit tests
 */
describe('Event Route Integration Tests:', function() {
	before(function(done) {
		//Remove all data from database so any previous tests that did not do this won't affect these tests.
		User.remove(function() {
			Evnt.remove(function() {
				done();
			});
		});
	});

	beforeEach(function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var startDate = new Date(Date.now() + millisInMonth).getTime();				//Start date for 1 month from now.
		var endDate = new Date(Date.now() + millisInMonth + 86400000).getTime();	//Event lasts 1 day.

		event1 = new Evnt({
			name: 'testing1231',
 			start_date: startDate,
 			end_date: endDate,
 			location: 'UF',
 			schedule: 'www.google.com',
			capacity: 50,
			attending: 5,
			invited: 55
 		});

 		event2 = new Evnt({
 			name: 'testing1232',
 			start_date: startDate,
 			end_date: endDate,
 			location: 'UF2',
 			schedule: 'www.google.com',
			capacity: 50,
			attending: 5,
			invited: 25
 		});

 		event1.save(function(err){
			if(err) throw err;
			event2.save(function(err){
				if(err) throw err;

				user = new User({
		 			fName: 'Full',
		 			lName: 'Name',
		 			roles: ['attendee'],
		 			displayName: 'Full Name',
		 			email: 'test@test.com',
		 			password: 'password',
		 			status: [{event_id: event1._id, attending:false, recruiter:false}],
		 			salt: 'abc123',
		 			rank: [],
		 			provider: 'local',
		 			login_enabled: true
		 		});

				userAdmin = new User({
		 			fName: 'Full',
		 			lName: 'Name',
		 			roles: ['admin'],
		 			displayName: 'Full Name',
		 			email: 'admin@test.com',
		 			password: 'password',
		 			status: [{event_id: event1._id, attending:false, recruiter:false}],
		 			salt: 'abc123',
		 			rank: [],
		 			provider: 'local',
		 			login_enabled: true
		 		});

				user.save(function(err){
					if(err) throw err;
					userAdmin.save(function(err){
						if(err) throw err;
						done();
					});
				});
			});
		});
	});

 	it("should be able to access the main page from the event route testing mechanism", function(done) {
 		request('http://localhost:3001')
 			.get('/')
 			.expect(200,done);
 	});

 	it("should not be able to enumerate events when not signed in",function(done) {
 		request('http://localhost:3001')
			.get('/events/enumerate')
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event start date when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getStartDate')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event name when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getName')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event end date when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getEndDate')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

	it("should not be able to get the event location when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getLocation')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event schedule when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getSchedule')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event object when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/getEventObj')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event capacity when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/capacity')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the number of people attending the event when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/attending')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the number of people invited to the event when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/invited')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

 	it("should not be able to get the event stats when not signed in", function(done) {
 		request('http://localhost:3001')
 			.get('/events/stats')
 			.query({event_id: event1._id.toString()})
 			.expect(401)
 			.end(function(err, res) {
 				should.not.exist(err);
 				res.body.message.should.equal("User is not logged in.");
 				done();
 			});
 	});

	it("should not be able to sign in without a password", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: ''})
 			.end(function (err, res) {
				should.not.exist(err);
				res.status.should.be.equal(400);
       			done();
 			});
    });

 	it("should be able to sign in correctly", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
				should.not.exist(err);
				res.status.should.be.equal(200);
       			done();
 			});
    });

 	it('should now be able to enumerate events when signed in', function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
					.get('http://localhost:3001/events/enumerate')
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
		 				res.body.should.have.property('events');
		 				res.body.events[0].toString().should.equal(event1._id.toString());
		 				done();
		 			});
		 	});
 	});

 	it("should now be able to get the event name when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getName')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('name');
						res.body.name.should.equal(event1.name);
						done();
					});
			});
 	});

	it("should now be able to get the event start date when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getStartDate')
		 			.query({event_id: event1._id.toString()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('start_date');
						res.body.start_date.should.equal(event1.start_date);
						done();
					});
			});
 	});

	 it("should now be able to get the event end date when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEndDate')
		 			.query({event_id: event1._id.toString()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('end_date');
						res.body.end_date.should.equal(event1.end_date);
						done();
					});
			});
 	});

	it("should now be able to get the event location when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getLocation')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('location');
						res.body.location.should.equal(event1.location);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the event schedule when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getSchedule')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('schedule');
						res.body.schedule.should.equal(event1.schedule);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the event capacity when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/capacity')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('capacity');
						res.body.capacity.should.equal(event1.capacity);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the number of people attending the event when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/attending')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('attending');
						res.body.attending.should.equal(event1.attending);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the number of people invited to the event when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/invited')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('invited');
						res.body.invited.should.equal(event1.invited);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the event stats when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/stats')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('capacity');
						res.body.capacity.should.equal(event1.capacity);
						res.body.should.have.property('attending');
						res.body.attending.should.equal(event1.attending);
						res.body.should.have.property('invited');
						res.body.invited.should.equal(event1.invited);
		 				done();
		 			});
		 	});
 	});

	it("should now be able to get the event object when signed in", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEventObj')
		 			.query({event_id: event1._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('start_date');
						res.body.start_date.should.equal(event1.start_date);
						res.body.should.have.property('end_date');
						res.body.end_date.should.equal(event1.end_date);
						res.body.should.have.property('schedule');
						res.body.schedule.should.equal(event1.schedule);
						res.body.should.have.property('location');
						res.body.location.should.equal(event1.location);
						res.body.should.have.property('name');
						res.body.name.should.equal(event1.name);
		 				done();
		 			});
		 	});
 	});

	it("should not be able to enumerate all events when not an admin", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/enumerateAll')
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.be.equal('User does not have permission.');
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access an eventObj by ID if the user shouldn't know about it", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEventObj')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access start_date if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getStartDate')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access end_date if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEndDate')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access location if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getLocation')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access schedule if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getSchedule')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access event name if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getName')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access event capacity if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/capacity')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access the number attending the event if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/attending')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access the number invited to the event if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/invited')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should not be able to access the event stats if the user shouldn't know about that event", function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/stats')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("You do not have permission to request this ID");
		 				done();
		 			});
		 	});
 	});

	it("should be able to login as admin",function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
				should.not.exist(err);
				res.status.should.be.equal(200);
       				done();
 			});
    });

	it("should be able to enumerate all events when admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/enumerateAll')
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);

						if(res.body.length !== numEvents) {
							return done(new Error("Too few/many events returned."));
						}

						for(var i=0; i < res.body.length; i++) {
							if(res.body[i]._id.toString() !== event1._id.toString() && res.body[i]._id.toString() !== event2._id.toString()) {
								return done(new Error("Returned IDs are incorrect."));
							}
						}

		 				done();
		 			});
		 	});
 	});

	it("should be able to access any event by ID if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEventObj')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body._id.toString().should.equal(event2._id.toString());
		 				done();
		 			});
		 	});
 	});

	it("should be able to access start_date of any event if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getStartDate')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('start_date');
						res.body.start_date.should.equal(event2.start_date);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access any end_date if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getEndDate')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('end_date');
						res.body.end_date.should.equal(event2.end_date);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access any location if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getLocation')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('location');
						res.body.location.should.equal(event2.location);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access any schedule if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getSchedule')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('schedule');
						res.body.schedule.should.equal(event2.schedule);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access any event name if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/getName')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('name');
						res.body.name.should.equal(event2.name);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access any event capacity if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/capacity')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('capacity');
						res.body.capacity.should.equal(event2.capacity);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access the number attending for any event if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/attending')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('attending');
						res.body.attending.should.equal(event2.attending);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access the number invited to any event if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/invited')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('invited');
						res.body.invited.should.equal(event2.invited);
		 				done();
		 			});
		 	});
 	});

	it("should be able to access the event stats if admin", function(done) {
 		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin //IMPORTANT: Agent does not support expect, use should
		 			.get('http://localhost:3001/events/stats')
					.query({event_id: event2._id.toString()})
		 			.end(function(err,res) {
		 				should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('capacity');
						res.body.capacity.should.equal(event2.capacity);
						res.body.should.have.property('attending');
						res.body.attending.should.equal(event2.attending);
						res.body.should.have.property('invited');
						res.body.invited.should.equal(event2.invited);
		 				done();
		 			});
		 	});
 	});

	//Post tests
	/* Note: At this time, there will be no methods provided to set the number attending/invited generally.  These numbers can only be modified through invitations/acceptances. */

	it("should be able to set the name if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setName')
					.send({event_id: event2._id.toString(), name:"ItsANewNameDog"})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getName')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('name');
								res.body.name.should.be.equal("ItsANewNameDog");
								done();
							});
					});
			});
	});

	it("should not be able to set invalid name if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setName')
					.send({event_id: event2._id.toString(), name:""})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("All required fields not specified.");
						agentAdmin
							.get('http://localhost:3001/events/getName')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('name');
								res.body.name.should.be.equal("testing1232");
								done();
							});
					});
			});
	});

	it("should not be able to set name if user", function(done) {
		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/auth/signin')
					.send({email: userAdmin.email, password: 'password'})
		 			.end(function (err, res) {
		 				if(err)
		 					return done(err);

				 		agent
							.post('http://localhost:3001/events/setName')
							.send({event_id: event1._id.toString(), name:"UserName"})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(401);
								res.body.message.should.equal("User does not have permission.");
								agentAdmin
									.get('http://localhost:3001/events/getName')
									.query({event_id: event1._id.toString()})
									.end(function(err,res) {
										should.not.exist(err);
										res.status.should.be.equal(200);
										res.body.should.have.property('name');
										res.body.name.should.be.equal("testing1231");
										done();
									});
							});
					});
			});
	});

	it("should be able to set the capacity if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/capacity')
					.send({event_id: event2._id.toString(), capacity:0})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/capacity')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('capacity');
								res.body.capacity.should.be.equal(0);
								done();
							});
					});
			});
	});

	it("should not be able to set invalid capacity (null) if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/capacity')
					.send({event_id: event2._id.toString(), capacity: null})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("Required fields not specified.");
						agentAdmin
							.get('http://localhost:3001/events/capacity')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('capacity');
								res.body.capacity.should.be.equal(event2.capacity);
								done();
							});
					});
			});
	});

	it("should not be able to set invalid capacity (-1) if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/capacity')
					.send({event_id: event2._id.toString(), capacity: -1})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("Validation failed");
						agentAdmin
							.get('http://localhost:3001/events/capacity')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('capacity');
								res.body.capacity.should.be.equal(event2.capacity);
								done();
							});
					});
			});
	});

	it("should not be able to set capacity if user", function(done) {
		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/auth/signin')
					.send({email: userAdmin.email, password: 'password'})
		 			.end(function (err, res) {
		 				if(err)
		 					return done(err);

				 		agent
							.post('http://localhost:3001/events/capacity')
							.send({event_id: event1._id.toString(), capacity: 111})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(401);
								res.body.message.should.equal("User does not have permission.");
								agentAdmin
									.get('http://localhost:3001/events/capacity')
									.query({event_id: event1._id.toString()})
									.end(function(err,res) {
										should.not.exist(err);
										res.status.should.be.equal(200);
										res.body.should.have.property('capacity');
										res.body.capacity.should.be.equal(event1.capacity);
										done();
									});
							});
					});
			});
	});

	it("should not be able to set invalid start_date if admin", function(done) {
		var initStartDate = event2.start_date;

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setStartDate')
					.send({event_id: event2._id.toString(), start_date : new Date(2004,11,30,10,0,0).getTime()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("Validation failed");

						agentAdmin
							.get('http://localhost:3001/events/getStartDate')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('start_date');
								res.body.start_date.should.be.equal(initStartDate);
								done();
							});
					});
			});
	});

	it("should be able to set start_date if admin", function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var startDate = new Date(Date.now() + millisInMonth + 43200000).getTime();				//Start date for 1 month from now.

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setStartDate')
					.send({event_id: event2._id.toString(), start_date : startDate})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getStartDate')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('start_date');
								res.body.start_date.should.be.equal(startDate);
								done();
							});
					});
			});
	});

	it("should not be able to set start_date if user", function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var startDate = new Date(Date.now() + millisInMonth + 43200000).getTime();				//Start date for 1 month from now.
		var initStartDate = event1.start_date;

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/auth/signin')
					.send({email: userAdmin.email, password: 'password'})
		 			.end(function (err, res) {
		 				if(err)
		 					return done(err);

				 		agent
							.post('http://localhost:3001/events/setStartDate')
							.send({event_id: event1._id.toString(), start_date : new Date(startDate).getTime()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(401);
								agentAdmin
									.get('http://localhost:3001/events/getStartDate')
									.query({event_id: event1._id.toString()})
									.end(function(err,res) {
										should.not.exist(err);
										res.status.should.be.equal(200);
										res.body.should.have.property('start_date');
										res.body.start_date.should.be.equal(initStartDate);
										done();
									});
							});
					});
			});
	});

	it("should be able to set end_date if admin", function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var endDate = new Date(Date.now() + millisInMonth + 86450000).getTime();	//Event lasts a little over 1 day.

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setEndDate')
					.send({event_id: event2._id.toString(), end_date:new Date(endDate).getTime()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getEndDate')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('end_date');
								res.body.end_date.should.be.equal(endDate);
								done();
							});
					});
			});
	});

	it("should not be able to set invalid end_date if admin", function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var endDate = new Date(Date.now() + millisInMonth - 86400000).getTime();	//Event ends 1 day before the event starts.
		var initEndDate = event2.end_date;

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setEndDate')
					.send({event_id: event2._id.toString(), end_date : endDate})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("Validation failed");
						agentAdmin
							.get('http://localhost:3001/events/getEndDate')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('end_date');
								res.body.end_date.should.be.equal(initEndDate);
								done();
							});
					});
			});
	});

	it("should not be able to set end_date if user", function(done) {
		var millisInMonth = new Date(1970, 0, 31, 11, 59, 59).getTime();			//Number of milliseconds in a typical month.
		var endDate = new Date(Date.now() + millisInMonth + 86450000).getTime();	//Event lasts a little over 1 day.
		var initEndDate = event1.end_date;

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/setEndDate')
					.send({event_id: event1._id.toString(), end_date : endDate})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");
						agent
							.get('http://localhost:3001/events/getEndDate')
							.query({event_id: event1._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('end_date');
								res.body.end_date.should.be.equal(initEndDate);
								done();
							});
					});
			});
	});

	it("should be able to set location if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setLocation')
					.send({event_id: event2._id.toString(), location:"Rainbow2"})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getLocation')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('location');
								res.body.location.should.be.equal("Rainbow2");
								done();
							});
					});
			});
	});

	it("should not be able to set invalid location if admin", function(done) {
		var initLocation = event2.location;

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setLocation')
					.send({event_id: event2._id.toString(), location:""})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(400);
						res.body.message.should.equal("All required fields not specified.");
						agentAdmin
							.get('http://localhost:3001/events/getLocation')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('location');
								res.body.location.should.be.equal(initLocation);
								done();
							});
					});
			});
	});

	it("should not be able to set location if user", function(done) {
		var initLocation = event1.location;

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/setLocation')
					.send({event_id: event1._id.toString(), location:"UserLocation"})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");
						agent
							.get('http://localhost:3001/events/getLocation')
							.query({event_id: event1._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('location');
								res.body.location.should.be.equal(initLocation);
								done();
							});
					});
			});
	});

	it("should be able to set schedule if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setSchedule')
					.send({event_id: event2._id.toString(), schedule:"BoBoBo"})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getSchedule')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('schedule');
								res.body.schedule.should.be.equal("BoBoBo");
								done();
							});
					});
			});
	});

	it("should be able to set schedule to empty string if admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setSchedule')
					.send({event_id: event2._id.toString(), schedule:""})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						agentAdmin
							.get('http://localhost:3001/events/getSchedule')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('schedule');
								res.body.schedule.should.be.equal("");
								done();
							});
					});
			});
	});

	it("should not be able to set schedule if user for event I don't know about", function(done) {
		var initSched = event2.schedule;

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/auth/signin')
					.send({email: userAdmin.email, password: 'password'})
		 			.end(function (err, res) {
		 				if(err)
		 					return done(err);

				 		agent
							.post('http://localhost:3001/events/setSchedule')
							.send({event_id: event2._id.toString(), schedule:"UserSchedule"})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(401);
								res.body.message.should.equal("User does not have permission.");

								agentAdmin
									.get('http://localhost:3001/events/getSchedule')
									.query({event_id: event2._id.toString()})
									.end(function(err,res) {
										should.not.exist(err);
										res.status.should.be.equal(200);
										res.body.should.have.property('schedule');
										res.body.schedule.should.be.equal(initSched);
										done();
									});
							});
					});
			});
	});

	it("should not be able to set schedule if user in general", function(done) {
		var initSched = event1.schedule;

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/setSchedule')
					.send({event_id: event1._id.toString(), schedule:"UserSchedule"})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");

						agent
							.get('http://localhost:3001/events/getSchedule')
							.query({event_id: event1._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('schedule');
								res.body.schedule.should.be.equal(initSched);
								done();
							});
					});
			});
	});

	it("should be able to update the event object if admin", function(done) {
		event2.name = "ReallyNewName";

		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/setEventObj')
					.send({event_id: event2._id.toString(), event:event2})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);

						agentAdmin
							.get('http://localhost:3001/events/getName')
							.query({event_id: event2._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('name');
								res.body.name.should.be.equal("ReallyNewName");
								Evnt.findOne({'_id' : event2._id}, function(err, result) {
									if(err)
										return done(err);

									res.body.name.should.be.equal(result.name);
									done();
								});
							});
					});
			});
	});

	it("should not be able to update the event object if user", function(done) {
		var initName = event1.name;
		event1.name = "ReallyNewName2";

		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/setEventObj')
					.send({event_id: event1._id.toString(), event:event1})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");

						agent
							.get('http://localhost:3001/events/getName')
							.query({event_id: event1._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.be.equal(200);
								res.body.should.have.property('name');
								res.body.name.should.be.equal(initName);
								done();
							});
					});
			});
	});

	it("should not be able to delete an event as a normal user", function(done) {
		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/delete')
					.send({event_id: event1._id.toString()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");

						agent
							.get('http://localhost:3001/events/getName')
							.query({event_id: event1._id.toString()})
							.end(function(err,res) {
								should.not.exist(err);
								res.status.should.equal(200);
								res.body.name.should.equal(event1.name);
								done();
							});
					});
			});
	});

	it("should be able to delete an event as an admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

 				var tempUser = new User({
		 			fName: 'Full',
		 			lName: 'Name',
		 			roles: ['admin', 'recruiter'],
		 			displayName: 'Full Name',
		 			email: 'temp@test.com',
		 			password: 'password',
		 			status: [{event_id: event1._id, attending:false, recruiter:false}, {event_id : event2._id, attending : true, recruiter : true}],
		 			salt: 'abc123',
		 			rank: [],
		 			provider: 'local',
		 			login_enabled: true
 				});

 				tempUser.save(function(err) {
 					if(err) {
 						return done(err);
 					}

			 		agentAdmin
						.post('http://localhost:3001/events/delete')
						.send({event_id: event1._id.toString()})
						.end(function(err,res) {
							should.not.exist(err);
							res.status.should.be.equal(200);

							agentAdmin
								.get('http://localhost:3001/events/getName')
								.query({event_id: event1._id.toString()})
								.end(function(err,res) {
									should.not.exist(err);

									res.status.should.equal(400);
									res.body.message.should.equal("No name!");

									User.find({}, function(err, users) {
										if(err) {
											return done(err);
										}

										users.length.should.equal(3);

										var canLogin = 0;
										for(var i = 0; i < users.length; i++) {
											if(!users[i].status || !users[i].status.length) {
												users[i].login_enabled.should.be.false;
											} else {
												users[i].login_enabled.should.be.true;
												(++canLogin).should.equal(1);
											}
										}

										canLogin.should.equal(1);

										done();
									});
								});
						});
 				});
			});
	});

	it("should not be able to inactivate an event as a normal user", function(done) {
		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/inactivate')
					.send({event_id: event1._id.toString()})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.message.should.equal("User does not have permission.");

						Evnt.findOne({_id : event1._id}, function(err, event) {
							if(err) {
								return done(err);
							}

							event.active.should.be.true;

							done();
						});
					});
			});
	});

	it("should be able to make an event inactive as an admin", function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

 				var tempUser = new User({
		 			fName: 'Full',
		 			lName: 'Name',
		 			roles: ['admin', 'recruiter'],
		 			displayName: 'Full Name',
		 			email: 'temp@test.com',
		 			password: 'password',
		 			status: [{event_id: event1._id, attending:false, recruiter:false}, {event_id : event2._id, attending : true, recruiter : true}],
		 			salt: 'abc123',
		 			rank: [],
		 			provider: 'local',
		 			login_enabled: true
 				});

 				tempUser.save(function(err) {
 					if(err) {
 						return done(err);
 					}

			 		agentAdmin
						.post('http://localhost:3001/events/inactivate')
						.send({event_id : event1._id})
						.end(function(err, res) {
							if(err) {
								return done(err);
							}

							res.status.should.equal(200);

							Evnt.findOne({_id : event1._id}, function(err, event) {
								event.active.should.be.false;

								User.find({"status.event_id" : event1._id}, function(err, users) {
									users.length.should.equal(3);

									for(var i = 0; i < users.length; i++) {
										for(var j = 0; j < users[i].status.length; j++) {
											if(users[i].status[j].event_id.toString() === event1._id.toString()) {
												users[i].status[j].active.should.be.false;
												break;
											}
										}
									}

									done();
								});
							});
						});
 				});
 			});
	});

	it("should be able to create an event using the event creation route as admin",function(done) {
		agentAdmin
			.post('http://localhost:3001/auth/signin')
			.send({email: userAdmin.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agentAdmin
					.post('http://localhost:3001/events/create')
					.send({
						name: 		"NewName",
						start_date:	new Date().getTime()+100000,
						end_date: 	new Date().getTime()+1000000,
						location: 	"asdf",
						schedule: 	"asdf",
						capacity: 	50
					})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(200);
						res.body.should.have.property('event_id');

						Evnt.findOne({_id : mongoose.Types.ObjectId(res.body.event_id)}, function(err, result) {
							if(err)
								return done(err);

							if(result)
								return done();

							return done(new Error("New event not actually created."));
						});
					});
			});
	});

	it("should not be able to create an event using the event creation route as a user",function(done) {
 		agent
 			.post('http://localhost:3001/auth/signin')
 			.send({email: user.email, password: 'password'})
 			.end(function (err, res) {
 				if(err)
 					return done(err);

		 		agent
					.post('http://localhost:3001/events/create')
					.send({
						name:		"NewName",
						start_date:	new Date().getTime()+100000,
						end_date:	new Date().getTime()+1000000,
						location:	"asdf",
						schedule:	"asdf"
					})
					.end(function(err,res) {
						should.not.exist(err);
						res.status.should.be.equal(401);
						res.body.should.have.property('message');
						res.body.message.should.equal("User does not have permission.");

						Evnt.find({}, function(err, result) {
							if(err)
								return done(err);

							if(result.length === 2)
								return done();

							return done(new Error("Event was created."));
						});
					});
			});
	});

	afterEach(function(done) {
		Evnt.remove(function(err) {
			if(err)
				return done(err);

			User.remove(function(err) {
				if(err)
					return done(err);

				done();
			});
		});
	});
});


text:
#ifndef _MALLOC_H_
#define _MALLOC_H_

/* All the headers include this file. */
#include <_mingw.h>

#include <stdlib.h>

#ifndef RC_INVOKED

/*
 * The structure used to walk through the heap with _heapwalk.
 */
typedef	struct _heapinfo
{
	int*	_pentry;
	size_t	_size;
	int	_useflag;
} _HEAPINFO;

/* Values for _heapinfo.useflag */
#define _FREEENTRY 0
#define _USEDENTRY 1

/* Return codes for _heapwalk()  */
#define _HEAPEMPTY	(-1)
#define _HEAPOK		(-2)
#define _HEAPBADBEGIN	(-3)
#define _HEAPBADNODE	(-4)
#define _HEAPEND	(-5)
#define _HEAPBADPTR	(-6)

/* maximum size of a user request for memory */
#define _HEAP_MAXREQ  0xFFFFFFE0

#ifdef	__cplusplus
extern "C" {
#endif
/*
   The _heap* memory allocation functions are supported on NT
   but not W9x. On latter, they always set errno to ENOSYS.
*/
_CRTIMP int __cdecl __MINGW_NOTHROW _heapwalk (_HEAPINFO*);
#ifdef __GNUC__
#define _alloca(x) __builtin_alloca((x))
#endif

#ifndef	_NO_OLDNAMES
_CRTIMP int __cdecl __MINGW_NOTHROW heapwalk (_HEAPINFO*);
#ifdef __GNUC__
#define alloca(x) __builtin_alloca((x))
#endif
#endif	/* Not _NO_OLDNAMES */

_CRTIMP int __cdecl __MINGW_NOTHROW _heapchk (void);	/* Verify heap integrety. */
_CRTIMP int __cdecl __MINGW_NOTHROW _heapmin (void);	/* Return unused heap to the OS. */
_CRTIMP int __cdecl __MINGW_NOTHROW _heapset (unsigned int);

_CRTIMP size_t __cdecl __MINGW_NOTHROW _msize (void*);
_CRTIMP size_t __cdecl __MINGW_NOTHROW _get_sbh_threshold (void);
_CRTIMP int __cdecl __MINGW_NOTHROW _set_sbh_threshold (size_t);
_CRTIMP void* __cdecl __MINGW_NOTHROW _expand (void*, size_t);

/* These require msvcr70.dll or higher. */
#if __MSVCRT_VERSION__ >= 0x0700
_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_malloc(size_t, size_t, size_t);
_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_realloc(void*, size_t, size_t, size_t);
_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_offset_recalloc(void*, size_t, size_t, size_t, size_t);

_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_malloc (size_t, size_t);
_CRTIMP void * __cdecl __MINGW_NOTHROW _aligned_realloc (void*, size_t, size_t);
_CRTIMP void* __cdecl __MINGW_NOTHROW _aligned_recalloc(void*, size_t, size_t, size_t);
_CRTIMP void __cdecl __MINGW_NOTHROW _aligned_free (void*);
#endif /* __MSVCRT_VERSION__ >= 0x0700 */

/* These require libmingwex.a. */
void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_malloc (size_t, size_t, size_t);
void * __cdecl __MINGW_NOTHROW __mingw_aligned_offset_realloc (void*, size_t, size_t, size_t);

void * __cdecl __MINGW_NOTHROW __mingw_aligned_malloc (size_t, size_t);
void * __cdecl __MINGW_NOTHROW __mingw_aligned_realloc (void*, size_t, size_t);
void __cdecl __MINGW_NOTHROW __mingw_aligned_free (void*);

#ifdef __cplusplus
}
#endif

#endif	/* RC_INVOKED */

#endif /* Not _MALLOC_H_ */

redpajama_set_name: RedPajamaGithub


text:
namespace utils {
namespace text {

/// Definitions of the templates to apply to a file.
///
/// This class provides the environment (e.g. the list of variables) that the
/// templating system has to use when generating the output files.  This
/// definition is static in the sense that this is what the caller program
/// specifies.
class templates_def {
    /// Mapping of variable names to their values.
    typedef std::map< std::string, std::string > variables_map;

    /// Collection of global variables available to the templates.
    variables_map _variables;

    /// Convenience name for a vector of strings.
    typedef std::vector< std::string > strings_vector;

    /// Mapping of vector names to their contents.
    ///
    /// Ideally, these would be represented as part of the _variables, but we
    /// would need a complex mechanism to identify whether a variable is a
    /// string or a vector.
    typedef std::map< std::string, strings_vector > vectors_map;

    /// Collection of vectors available to the templates.
    vectors_map _vectors;

    const std::string& get_vector(const std::string&, const std::string&) const;

public:
    templates_def(void);

    void add_variable(const std::string&, const std::string&);
    void remove_variable(const std::string&);
    void add_vector(const std::string&);
    void add_to_vector(const std::string&, const std::string&);

    bool exists(const std::string&) const;
    const std::string& get_variable(const std::string&) const;
    const strings_vector& get_vector(const std::string&) const;

    std::string evaluate(const std::string&) const;
};

void instantiate(const templates_def&, std::istream&, std::ostream&);
void instantiate(const templates_def&, const fs::path&, const fs::path&);

}  // namespace text
}  // namespace utils

#endif  // !defined(UTILS_TEXT_TEMPLATES_HPP)


text:
<?php date_default_timezone_set('asia/manila');?>
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="John Noah G. Ompad">

    <title>AGUS 6/7 - Warehouse Management System</title>

    <link href="<?php echo base_url();?>_assets/assets/css/bootstrap.css" rel="stylesheet">

    <link href="<?php echo base_url();?>_assets/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />

    <link href="<?php echo base_url();?>_assets/assets/css/style.css" rel="stylesheet">
    <link href="<?php echo base_url();?>_assets/assets/css/style-responsive.css" rel="stylesheet">
	<link href="<?php echo base_url();?>_assets/assets/css/dataTables.bootstrap.css" rel="stylesheet">
	<link href="<?php echo base_url();?>_assets/assets/css/dataTables.responsive.css" rel="stylesheet">

    <link href="<?php echo base_url();?>_assets/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">

    <link href="<?php echo base_url();?>_assets/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">

    <link href="<?php echo base_url();?>_assets/bower_components/datatables-responsive/css/dataTables.responsive.css" rel="stylesheet"-->

            <a href="<?php echo base_url();?>" class="logo">sWMS

 User Profile

 Settings

<a href="<?php echo base_url();?>WMS/emp_logout"> Logout

<img src="<?php echo base_url();?>/_assets/assets/img/default_profile1.png" class="img-circle" style="background-color:#F3F3F3;"width="90">

<?php echo $Enduser_Name;?>
<?php echo $Position;?>

                      <a href="<?php echo base_url();?>">

                          Home

                          Pre - PR Request

<a href="<?php echo base_url();?>WMS/Purchase_Request">Pending
						  2

<a href="<?php echo base_url();?>WMS/Purchase_Approved">Approved

                          Approved PR

<a href="<?php echo base_url();?>">My Spares

Warehouse Spares

                          Purchase Order

<a href="<?php echo base_url();?>">My Spares

Warehouse Spares

                          Warehouse Spares

<a href="<?php echo base_url();?>">My Spares

Warehouse Spares

<a href="<?php echo base_url();?>WMS/Purchase_Approved" title="List of Approved Pre-PR" style="color:#004D40;padding-left:5px;font-size:15px;">Purchase Request
			Approved

			Pre - PR

			<?php foreach ($DraftInfo as $row){ ?>
			<?php foreach ($EmployeeInfo as $row2){ ?>

					<?php echo substr($row2->Fname,0,1).".".substr($row2->Mname,0,1)." ".$row2->Lname." (".$row->SpId.") ";?>

							  <?php echo $message;?>

			<?php }?>
			<?php }?>

							<?php foreach ($DraftInfo as $row){ ?>

Requisitioning Section

: <?php echo $row->Requisitioning_Section;?>

Cost Center Number

: <?php echo $CcNo; ?>

Date Prepared

: <?php echo $row->Date_Prepared;?>

Date Needed

: <?php echo $row->Date_Needed;?>

											Purpose of Purchase

: <?php echo $row->Purpose; ?>

							<?php }?>

											  ITEM NO.
											  COMPLETE DESCRIPTION / SPECIFICATION
											  QTY
											  UM
											  ESTD. COST

									 <?php
									 $i=1;
									 $totalec=0;
									 foreach ($SpareInfo as $row){ ?>

                                            <?echo $i++;?>

											<?php echo $row->Category.", ".$row->Spare_Name;?>, <?php echo $row->Description;?>

													Specifications :

												<?php foreach ($TechnicalInfo as $row1){
													if ($row->SId == $row1->SId){
												?>

													- <?php echo $row1->Tech_Name;?>

													: <?php echo $row1->value;?>

												<?php }else {}}?>

                                            <?php if ($row->Qty <= 0){
																													echo "--";

																											} else {
																													echo number_format($row->Qty,2);
																											}

																											?>

                                            <?php if (strlen($row->UM) > 0 && strlen(trim($row->UM))){
																													echo $row->UM;
																											} else {
																													echo "--";
																											}?>

											<?php if ($row->Estimated_Cost<= 0){
																													echo "--";
																											} else {

																													echo "P ".number_format(($row->Estimated_Cost * $row->Qty),2);

																											}
																												 $ec = $row->Estimated_Cost * $row->Qty;
																												 $totalec = $totalec + $ec;
																											?>

										<?php }?>

Total : P  <?php echo number_format($totalec,2); ?>

					     <?php foreach ($DraftInfo as $row){ ?>

							Note :

<?php echo $row->note?>

							<button class="btn btn-lg" style="font-size:16px;border-radius:8px;float:right" title="Send Pre-PR DRAFT for Approval" >
								Waiting Procurement Officer
							</button>

Evaluation
<button style="font-size:15px;border-radius:8px;float:left;" title="Pre-PR Approval">
							<?php
							echo $row->Status; ?>
							</button>

Responsible
<button style="font-size:15px;border-radius:8px;float:left;" title="Pre-PR Approval">
							<?php
							echo $row->PO_Incharge; ?>
							</button>

Date Changed
<button style="font-size:15px;border-radius:8px;float:left;" title="Pre-PR Approval">
							<?php
							echo $row->Date_Status_Changed; ?>
							</button>

Remarks
<button style="font-size:15px;border-radius:8px;float:left;" title="Pre-PR Approval">
							<?php
							echo $row->remark; ?>
							</button>

					     <?php }?>

              (c) 2016 - Spares Warehouse Management System

<?php foreach ($DraftInfo as $row){?>
			<div class="modal fade" id="<?php echo $row->SpId;?>createPO" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

Create Purchase Order

Please Select :

										<button type="button" style="font-size:15px;float:left;" class="btn btn-success" data-dismiss="modal" data-toggle="modal" data-target="#<?php echo $row->SpId;?>Accept">
											Accept
										</button>
										<button type="button" style="font-size:15px;float:left;margin-left:10%;" class="btn btn-default" data-dismiss="modal" data-toggle="modal" data-target="#<?php echo $row->SpId;?>Decline">
											Decline
										</button>

<?php }?>


text:
fw_depends mysql rvm ruby-2.2

rvm ruby-$MRI_VERSION do \
  bundle install --jobs=4 --gemfile=$TROOT/Gemfile --path=vendor/bundle

# Enable Puma's clustered mode with about one process per hardware thread,
# scaling up to a maximum of about 256 concurrent threads. NOTE: I was having
# trouble keeping two cores saturated with only two workers, thus the "fuzzy"
# math here.

WORKERS=$(( $(nproc || echo 7) + 1 ))
MAX_THREADS=$(( 256 / WORKERS + 1 )) ; export MAX_THREADS
MIN_THREADS=$(( MAX_THREADS / 4 + 1 ))

rvm ruby-$MRI_VERSION do \
  bundle exec puma -w $WORKERS -t $MIN_THREADS:$MAX_THREADS -b tcp://0.0.0.0:8080 -e production &


text:
package com.intel.icecp.core.misc;

import com.intel.icecp.core.Channel;
import com.intel.icecp.core.messages.ConfigurationMessage;

import java.util.Set;

/**
 * A configuration object; the purpose of this interface is to hide the mechanics of loading configuration data from a
 * channel so that it may be used in a variety of places throughout the application.
 *
 * @deprecated this API will be replaced by the {@link com.intel.icecp.core.attributes.Attributes} API in 0.11.*; TODO
 * remove this
 */
public interface Configuration {

    /**
     * Load the configuration file from the assigned channel, see {@link Configuration#getChannel()}; if called again,
     * this will force the configuration to retrieve its latest version.
     *
     * @throws com.intel.icecp.core.misc.ChannelIOException if the channel fails
     */
    void load() throws ChannelIOException;

    /**
     * Persist any changes to the configuration; this will publish the changes as a new version on the channel.
     *
     * @throws com.intel.icecp.core.misc.ChannelIOException if the channel fails
     */
    void save() throws ChannelIOException;

    /**
     * Retrieve a value from the configuration file; if not loaded, the configuration will load itself synchronously.
     *
     * @param <T> the inferred type to return
     * @param propertyPath the path to the value, e.g. prop1.prop2.prop3
     * @return the property value
     * @throws com.intel.icecp.core.misc.PropertyNotFoundException if the path is not found
     */
    <T> T get(String propertyPath) throws PropertyNotFoundException;

    /**
     * Retrieve a value from the configuration file or return null if not found; if not loaded, the configuration will
     * load itself synchronously.
     *
     * @param <T> the inferred type to return
     * @param propertyPath the path to the value, e.g. prop1.prop2.prop3
     * @return the property value
     */
    <T> T getOrNull(String propertyPath);

    /**
     * Retrieve a value from the configuration file or return the default value given if not found; this method will
     * search each property path from left to right.
     *
     * @param <T> the inferred type to return
     * @param defaultValue the value to return if no path is found
     * @param propertyPaths a list of paths to values, e.g. prop1.prop2.prop3
     * @return the property value
     */
    <T> T getOrDefault(T defaultValue, String... propertyPaths);

    /**
     * Change a value in the configuration file; note that changes will not be persisted until {@link
     * Configuration#save()} is called. If necessary, this method will create the path structure.
     *
     * @param propertyPath the path to the value, e.g. prop1.prop2.prop3
     * @param value the property value
     */
    void put(String propertyPath, Object value);

    /**
     * @return a reference to the underlying channel; this may be permission-protected by implementing classes.
     */
    Channel<ConfigurationMessage> getChannel();

    /**
     * @return Current set of valid configuration parameters(note, static snapshot!)
     */
    Set<String> keySet();
}


text:
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (4 open source Android apps for writers)
[#]: via: (https://opensource.com/article/19/6/android-apps-writers)
[#]: author: (Scott Nesbitt https://opensource.com/users/scottnesbitt/users/tiwarinitish86)

4 open source Android apps for writers
======
Get some writing work done on your mobile device with these four apps.
![Hands holding a mobile phone with open on the screen][1]

While I'm of two minds when it comes to smartphones and tablets, I have to admit they can be useful. Not just for keeping in touch with people or using the web but also to do some work when I'm away from my computer.

For me, that work is _writing_—articles, [blog posts][2], essays for my [weekly letter][3], e-book chapters, and more. I've tried many (probably too many!) writing apps for Android over the years. Some of them were good. Others fell flat.

Here are four of my favorite open source Android apps for writers. You might find them as useful as I do.

### Markor

If you're a writer, you need to write with something. A good choice for that job is [Markor][4], a simple, flexible Markdown editor.

All you need to do is fire up Markor, create a new document, and start typing. You can add Markdown formatting by hand or by clicking a button on the toolbar. When it comes to writing, Markor has no frills. It's just you and your words, as it should be.

![Markor app][5]

The app automatically saves your work to your phone or tablet's filesystem. If you sync your phone with a service like [Nextcloud][6], you can set up Markor to save your work in a folder the Nextcloud mobile app uses. That way, you don't need to shuffle files around manually.

Markor has a few other useful features. One of those is a simple preview. Another is a task list, which uses the same format as [Todo.txt][7] (a popular to-do list manager). When you're researching a writing project, you can create a list of bookmarks. You can also export what you're writing as an HTML or a PDF file.

### Orgzly

Some writers swear by outlines. Others hate them with a passion, finding outlines restricting. I'm in the former camp. On my laptop, I do most of my outlining using [Emacs][8] and [Org mode][9]. Bringing the Org mode experience to my phone or tablet is easy using [Orgzly][10].

Don't let the fact that Orgzly uses Org mode's format turn you off. You don't need to be an Emacs guru, or even an Emacs user, to benefit from it.

Create a new _notebook_ (the label Orgzly gives an outline) and add items to it. In addition to a title, you can add tags and notes to each item in your outline. Since outlines are fluid, you can move items up, down, and around. If you need to, you can also sync your notebooks with your service or tool of choice.

![Orgzly app][11]

Orgzly takes a bit of getting used to. Once you do, Orgzly's a great app for creating not only outlines but also notes and [task lists][12].

### Carnet

Notes are the lifeblood of any writer. They're a record of thoughts on a subject. They're snippets and rough drafts. They're research and quotes. And a lot more.

You can use Markor or Orgzly to take notes, but they're not for everyone. If you're one of those people, you'll want to check out [Carnet][13].

Unlike some note-taking apps, Carnet lets you add formatting to your notes. You can change the size, color, and alignment of fonts and add character formatting. You can also insert images into a note. When you finish, you can sync the note either with [Carnet's online service][14] or with Nextcloud.

![Carnet app][15]

The way Carnet displays notes reminds me of Google Keep's layout—as tiles, which you can color, that display a note's title and its first few lines. That's not a bad thing—you can see what a note is about with a glance.

### Anysoft Keyboard

When I write on a phone or tablet, I usually use a folding Bluetooth keyboard. It's a lot faster and easier than typing with an onscreen keyboard. But there are times when I don't have my physical keyboard with me. The stock Android keyboard? It really doesn't do it for me. Instead, I use [Anysoft Keyboard][16].

Why? I prefer the layout and spacing. On top of that, it has several keyboard themes to choose from. Some are compact, while others space the keys out a bit more widely. Don't use QWERTY? Not a problem. Anysoft Keyboard also supports the [Dvorak][17], [Colemak][18], [Workman][19], and [Halmak][20] layouts.

![Anysoft Keyboard][21]

While I'm more of a poly-not than a polyglot, I know more than a couple of people will find Anysoft Keyboard's [language support][22] to be a boon when they're writing in a language other than English.

Have an open source Android app that you find indispensable when writing? Feel free to share it by leaving a comment.

About 10 years ago, when I got my first mobile phone, I hardly knew anything about its operating...

--------------------------------------------------------------------------------

via: https://opensource.com/article/19/6/android-apps-writers

作者:[Scott Nesbitt][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)

本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

[a]: https://opensource.com/users/scottnesbitt/users/tiwarinitish86
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolserieshe_rh_041x_0.png?itok=tfg6_I78 (Hands holding a mobile phone with open on the screen)
[2]: https://scottnesbitt.online
[3]: https://buttondown.email/weeklymusings
[4]: https://gsantner.net/project/markor.html
[5]: https://opensource.com/sites/default/files/uploads/markor-app.png (Markor app)
[6]: https://opensource.com/article/19/5/mobile-apps-nextcloud
[7]: http://todotxt.org/
[8]: https://www.gnu.org/software/emacs/
[9]: https://opensource.com/article/19/1/productivity-tool-org-mode
[10]: http://www.orgzly.com/
[11]: https://opensource.com/sites/default/files/uploads/orgzly.png (Orgzly app)
[12]: https://opensource.com/article/17/4/emacs-extensions-organization
[13]: https://f-droid.org/en/packages/com.spisoft.quicknote/
[14]: https://carnet.live/index.php/login
[15]: https://opensource.com/sites/default/files/uploads/carnet.png (Carnet app)
[16]: https://anysoftkeyboard.github.io/
[17]: https://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard
[18]: https://en.wikipedia.org/wiki/Colemak
[19]: https://en.wikipedia.org/wiki/Keyboard_layout#Workman
[20]: https://github.com/MadRabbit/halmak
[21]: https://opensource.com/sites/default/files/uploads/anysoft.png (Anysoft Keyboard)
[22]: https://anysoftkeyboard.github.io/languages/


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE398_Poor_Code_Quality__five_01.c
Label Definition File: CWE398_Poor_Code_Quality.label.xml
Template File: point-flaw-01.tmpl.c
*/
/*
 * @description
 * CWE: 398 Poor Code Quality
 * Sinks: five
 *    GoodSink: Removed statement that has no effect
 *    BadSink : A statement that has no effect
 * Flow Variant: 01 Baseline
 *
 * */

#include "std_testcase.h"

#ifndef OMITBAD

void CWE398_Poor_Code_Quality__five_01_bad()
{
    /* FLAW: the statement has no effect */
    5;
    printLine("Hello from bad()");
}

#endif /* OMITBAD */

#ifndef OMITGOOD

static void good1()
{
    /* FIX: Do not include a statement that has no effect */
    printLine("Hello from good()");
}

void CWE398_Poor_Code_Quality__five_01_good()
{
    good1();
}

#endif /* OMITGOOD */

/* Below is the main(). It is only used when building this testcase on
   its own for testing or for building a binary to use in testing binary
   analysis tools. It is not used when compiling all the testcases as one
   application, which is how source code analysis tools are tested. */

#ifdef INCLUDEMAIN

int main(int argc, char * argv[])
{
    /* seed randomness */
    srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
    printLine("Calling good()...");
    CWE398_Poor_Code_Quality__five_01_good();
    printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
    printLine("Calling bad()...");
    CWE398_Poor_Code_Quality__five_01_bad();
    printLine("Finished bad()");
#endif /* OMITBAD */
    return 0;
}

#endif


text:
/*************************************************************************/
/*  editor_plugin_settings.cpp                                           */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#include "editor_plugin_settings.h"
#include "scene/gui/margin_container.h"
#include "io/config_file.h"
#include "os/file_access.h"
#include "os/main_loop.h"
#include "globals.h"
#include "editor_node.h"

void EditorPluginSettings::_notification(int p_what) {

	if (p_what==MainLoop::NOTIFICATION_WM_FOCUS_IN) {
		update_plugins();
	}
}

void EditorPluginSettings::update_plugins() {

	plugin_list->clear();

	DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	Error err = da->change_dir("res://addons");
	if (err!=OK) {
		memdelete(da);
		return;
	}

	updating=true;

	TreeItem *root = plugin_list->create_item();

	da->list_dir_begin();

	String d = da->get_next();

	Vector<String> plugins;

	while(d!=String()) {

		bool dir = da->current_is_dir();
		String path = "res://addons/"+d+"/plugin.cfg";

		if (dir && FileAccess::exists(path)) {

			plugins.push_back(d);
		}

		d = da->get_next();
	}

	da->list_dir_end();
	memdelete(da);

	plugins.sort();

	Vector<String> active_plugins = Globals::get_singleton()->get("plugins/active");

	for(int i=0;i<plugins.size();i++) {

		Ref<ConfigFile> cf;
		cf.instance();
		String path = "res://addons/"+plugins[i]+"/plugin.cfg";

		Error err = cf->load(path);

		if (err!=OK) {
			WARN_PRINTS("Can't load plugin config: "+path);
		} else if (!cf->has_section_key("plugin","name")) {
			WARN_PRINTS("Plugin misses plugin/name: "+path);
		} else if (!cf->has_section_key("plugin","author")) {
			WARN_PRINTS("Plugin misses plugin/author: "+path);
		} else if (!cf->has_section_key("plugin","version")) {
			WARN_PRINTS("Plugin misses plugin/version: "+path);
		} else if (!cf->has_section_key("plugin","description")) {
			WARN_PRINTS("Plugin misses plugin/description: "+path);
		} else if (!cf->has_section_key("plugin","script")) {
			WARN_PRINTS("Plugin misses plugin/script: "+path);
		} else {

			String d = plugins[i];
			String name = cf->get_value("plugin","name");
			String author = cf->get_value("plugin","author");
			String version = cf->get_value("plugin","version");
			String description = cf->get_value("plugin","description");
			String script = cf->get_value("plugin","script");

			TreeItem *item = plugin_list->create_item(root);
			item->set_text(0,name);
			item->set_tooltip(0,"Name: "+name+"\nPath: "+path+"\nMain Script: "+script);
			item->set_metadata(0,d);
			item->set_text(1,version);
			item->set_metadata(1,script);
			item->set_text(2,author);
			item->set_metadata(2,description);
			item->set_cell_mode(3,TreeItem::CELL_MODE_RANGE);
			item->set_range_config(3,0,1,1);
			item->set_text(3,"Inactive,Active");
			item->set_editable(3,true);

			if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) {
				item->set_custom_color(3,Color(0.2,1,0.2));
				item->set_range(3,1);
			} else {
				item->set_custom_color(3,Color(1,0.2,0.2));
				item->set_range(3,0);
			}
		}

	}

	updating=false;

}

void EditorPluginSettings::_plugin_activity_changed() {

	if (updating)
		return;

	TreeItem *ti=plugin_list->get_edited();
	ERR_FAIL_COND(!ti);
	bool active = ti->get_range(3);
	String name = ti->get_metadata(0);

	EditorNode::get_singleton()->set_addon_plugin_enabled(name,active);

	bool is_active = EditorNode::get_singleton()->is_addon_plugin_enabled(name);

	if (is_active!=active) {
		updating=true;
		ti->set_range(3,is_active?1:0);
		updating=false;
	}

	if (is_active)
		ti->set_custom_color(3,Color(0.2,1,0.2));
	else
		ti->set_custom_color(3,Color(1,0.2,0.2));

}

void EditorPluginSettings::_bind_methods() {

	ObjectTypeDB::bind_method("update_plugins",&EditorPluginSettings::update_plugins);
	ObjectTypeDB::bind_method("_plugin_activity_changed",&EditorPluginSettings::_plugin_activity_changed);
}

EditorPluginSettings::EditorPluginSettings() {

	HBoxContainer *title_hb = memnew( HBoxContainer );
	title_hb->add_child(memnew( Label(TTR("Installed Plugins:"))));
	title_hb->add_spacer();
	update_list = memnew( Button(TTR("Update")) );
	update_list->connect("pressed",this,"update_plugins");
	title_hb->add_child(update_list);
	add_child(title_hb);

	plugin_list = memnew( Tree );
	plugin_list->set_v_size_flags(SIZE_EXPAND_FILL);
	plugin_list->set_columns(4);
	plugin_list->set_column_titles_visible(true);
	plugin_list->set_column_title(0,TTR("Name:"));
	plugin_list->set_column_title(1,TTR("Version:"));
	plugin_list->set_column_title(2,TTR("Author:"));
	plugin_list->set_column_title(3,TTR("Status:"));
	plugin_list->set_column_expand(0,true);
	plugin_list->set_column_expand(1,false);
	plugin_list->set_column_expand(2,false);
	plugin_list->set_column_expand(3,false);
	plugin_list->set_column_min_width(1,100);
	plugin_list->set_column_min_width(2,250);
	plugin_list->set_column_min_width(3,80);
	plugin_list->set_hide_root(true);
	plugin_list->connect("item_edited",this,"_plugin_activity_changed");

	MarginContainer *mc = memnew( MarginContainer );
	mc->add_child(plugin_list);
	mc->set_v_size_flags(SIZE_EXPAND_FILL);

	add_child(mc);

	updating=false;

}


text:
/**
 * WordPress dependencies
 */
import { __ } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import {
	IDEA_HUB_BUTTON_CREATE,
	IDEA_HUB_BUTTON_PIN,
	IDEA_HUB_BUTTON_VIEW,
	IDEA_HUB_BUTTON_UNPIN,
	IDEA_HUB_BUTTON_DELETE,
	IDEA_HUB_ACTIVITY_CREATING_DRAFT,
	IDEA_HUB_ACTIVITY_IS_DELETING,
	IDEA_HUB_ACTIVITY_IS_PINNING,
	IDEA_HUB_ACTIVITY_IS_UNPINNING,
} from '../../../datastore/constants';
import PinIcon from '../../../../../../svg/icons/idea-hub-pin.svg';
import DeleteIcon from '../../../../../../svg/icons/idea-hub-delete.svg';
import CreateIcon from '../../../../../../svg/icons/idea-hub-create.svg';
import UnpinIcon from '../../../../../../svg/icons/idea-hub-unpin.svg';
import ViewIcon from '../../../../../../svg/icons/idea-hub-view.svg';

const ACTIVITY_TIMER = 2000;

export const activityIconMap = {
	[ IDEA_HUB_BUTTON_DELETE ]: DeleteIcon,
	[ IDEA_HUB_BUTTON_PIN ]: PinIcon,
	[ IDEA_HUB_BUTTON_UNPIN ]: UnpinIcon,
	[ IDEA_HUB_BUTTON_CREATE ]: CreateIcon,
	[ IDEA_HUB_BUTTON_VIEW ]: ViewIcon,
};

export const classNamesMap = {
	[ IDEA_HUB_BUTTON_DELETE ]: 'googlesitekit-idea-hub__actions--delete',
	[ IDEA_HUB_BUTTON_PIN ]: 'googlesitekit-idea-hub__actions--pin',
	[ IDEA_HUB_BUTTON_UNPIN ]: 'googlesitekit-idea-hub__actions--unpin',
	[ IDEA_HUB_BUTTON_CREATE ]: 'googlesitekit-idea-hub__actions--create',
	[ IDEA_HUB_BUTTON_VIEW ]: 'googlesitekit-idea-hub__actions--view',
};

export const titlesMap = {
	[ IDEA_HUB_BUTTON_DELETE ]: __( 'Dismiss', 'google-site-kit' ),
	[ IDEA_HUB_BUTTON_PIN ]: __( 'Save for later', 'google-site-kit' ),
	[ IDEA_HUB_BUTTON_UNPIN ]: __( 'Remove from saved', 'google-site-kit' ),
	[ IDEA_HUB_BUTTON_CREATE ]: __( 'Start a draft post', 'google-site-kit' ),
	[ IDEA_HUB_BUTTON_VIEW ]: __( 'View draft', 'google-site-kit' ),
};

export const progressMap = {
	[ IDEA_HUB_BUTTON_DELETE ]: IDEA_HUB_ACTIVITY_IS_DELETING,
	[ IDEA_HUB_BUTTON_PIN ]: IDEA_HUB_ACTIVITY_IS_PINNING,
	[ IDEA_HUB_BUTTON_UNPIN ]: IDEA_HUB_ACTIVITY_IS_UNPINNING,
	[ IDEA_HUB_BUTTON_CREATE ]: IDEA_HUB_ACTIVITY_CREATING_DRAFT,
};

export const noticesMap = {
	IDEA_HUB_ACTIVITY_DRAFT_CREATED: __( 'Draft created', 'google-site-kit' ),
	IDEA_HUB_ACTIVITY_PINNED: __( 'Idea saved', 'google-site-kit' ),
	IDEA_HUB_ACTIVITY_UNPINNED: __(
		'Idea removed from saved',
		'google-site-kit'
	),
	IDEA_HUB_ACTIVITY_DELETED: __( 'Idea dismissed', 'google-site-kit' ),
};

export const waitForActivity = () =>
	new Promise( ( resolve ) => {
		setTimeout( () => {
			resolve();
		}, ACTIVITY_TIMER );
	} );


text:
#pragma once

#include <string>
#include <vector>

#include "Shader.h"

using std::string;
using std::vector;

/**
 * This class manages Shader objects. Shader objects are allocated using this
 * class, which maintains a pointer to them. When a ShaderManager object goes
 * out of scope, all the Shader objects it was managing are deallocated.
 */
class ShaderManager {
public:
    /**
     * Constructor. Creates an empty ShaderManager.
     */
    ShaderManager();

    /**
     * Destructor. Frees memory.
     */
    virtual ~ShaderManager();

    /**
     * Get the shader with the specified name. If the shader has not been
     * loaded, compiled and linked, this function will do so.
     * @param name The name of the shader. Corresponds to the shaders/
     * subdirectory that contains the shader programs for this shader.
     */
    Shader* get(const string& name);

    /**
      * Update the projection matrix of all managed shaders.
      *
      * @param matrix The projection matrix to pass to the shaders.
      */
    void updateProjectionMatrices(mat4 matrix);

    /**
      * Update the view matrix of all managed shaders.
      *
      * @param matrix The view matrix to pass to the shaders.
      */
    void updateViewMatrices(mat4 matrix);

    /**
      * Update the world matrix of all managed shaders.
      *
      * @param matrix The world matrix to pass to the shaders.
      */
    void updateWorldMatrices(mat4 matrix);

private:
    /** List of shader objects managed by this ShaderManager. */
    vector<Shader*> _shaders;
};


text:
"""Test config init."""
import pytest

from homeassistant.bootstrap import async_setup_component

from tests.common import mock_http_component

@pytest.fixture(autouse=True)
def stub_http(hass):
    """Stub the HTTP component."""
    mock_http_component(hass)

def test_config_setup(hass, loop):
    """Test it sets up hassbian."""
    loop.run_until_complete(async_setup_component(hass, 'config', {}))
    assert 'config' in hass.config.components


text:
using System;
using System.Collections.Generic;
using System.Text;

namespace gView.Framework.UI.Controls.Wizard
{
    public interface IWizardPageNotification
    {
        void OnShowWizardPage();
    }

    public interface IWizardPageNecessity
    {
        bool CheckNecessity();
    }
}


text:
#import <SAObjects/SAStartRequest.h>

@class NSString;

@interface SASStartCorrectedSpeechRequest : SAStartRequest
{
}

+ (id)startCorrectedSpeechRequestWithDictionary:(id)arg1 context:(id)arg2;
+ (id)startCorrectedSpeechRequest;
@property(copy, nonatomic) NSString *sessionId;
@property(copy, nonatomic) NSString *interactionId;
- (id)encodedClassName;
- (id)groupIdentifier;

@end


text:
<?php

/**
 * @file
 * Contains Drupal\book\Access\BookNodeIsRemovableAccessCheck.
 */

namespace Drupal\book\Access;

use Drupal\book\BookManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\node\NodeInterface;

/**
 * Determines whether the requested node can be removed from its book.
 */
class BookNodeIsRemovableAccessCheck implements AccessInterface{

  /**
   * Book Manager Service.
   *
   * @var \Drupal\book\BookManagerInterface
   */
  protected $bookManager;

  /**
   * Constructs a BookNodeIsRemovableAccessCheck object.
   *
   * @param \Drupal\book\BookManagerInterface $book_manager
   *   Book Manager Service.
   */
  public function __construct(BookManagerInterface $book_manager) {
    $this->bookManager = $book_manager;
  }

  /**
   * Checks access for removing the node from its book.
   *
   * @param \Drupal\node\NodeInterface $node
   *   The node requested to be removed from its book.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(NodeInterface $node) {
    return AccessResult::allowedIf($this->bookManager->checkNodeIsRemovable($node))->cacheUntilEntityChanges($node);
  }

}