Skip to content

Instantly share code, notes, and snippets.

View robksawyer's full-sized avatar
🎯
Focusing

Rob Sawyer robksawyer

🎯
Focusing
View GitHub Profile
@robksawyer
robksawyer / for loop prop
Created August 27, 2015 00:36
Weird issue with loop and applying values to object.
for user, key in users
users[key].prop1 = [ user.id ]
users[key].prop2 = [ user.id ]
users[key].prop3 = [ user.id ]
users[key].prop4 = [ user.id ]
#update the data
console.log users
#shows that only the prop3 is getting updated.
@robksawyer
robksawyer / sails_referrer_view
Created October 22, 2014 07:08
Returns the referring view in SailsJS.
//Returns just the referring view. This can be used in the res.redirect or res.view.
var referrer = req.header('Referer').replace(req.protocol + "://" + req.host + ":" + req.port + '/', '');
return res.view(referringView, {result: false, errors: error_object});
//I'm trying to get the errors in the view via:
//<% sails.log(errors); %>
@robksawyer
robksawyer / gist:f739b110f580e025420e
Created October 31, 2014 05:04
SailsJS: Ajax Image Upload
//Source: https://github.com/balderdashy/sails/issues/27
var UUIDGenerator = require('node-uuid');
var DirectoryController = {
// uploads a file to a directory
upload: function(req, res) {
// Parse form data from server
var parsedFormData = JSON.parse(req.param('data'));
@robksawyer
robksawyer / scope issues
Created October 31, 2014 07:03
Simple file processing function.
/**
* CampaignController
*
* @description :: Server-side logic for managing campaigns
* @help :: See http://links.sailsjs.org/docs/controllers
*/
module.exports = {
fileExtension: function(fileName) {
@robksawyer
robksawyer / appHelper.js
Last active August 29, 2015 14:10
This is inside of test/helpers/appHelper.js
/*
* Location: /test/helpers/appHelper.js
*
* @description :: Provides 'lift' and 'lower' methods to set up
* and tear down a Sails instance (for use in tests)
*/
var Sails = require('sails'),
should = require('should'),
async = require('async'),
lifted = false,
'use strict';
/*
* Location: /test/bootstrap.test.js
*
* @description :: This file is run before all other tests.
*/
var should = require('chai').should(),
appHelper = require('./helpers/appHelper');
error: The bootstrap function threw an error after its callback was called :: Error: done() called multiple times
at Hook.Runnable (/Users/testing/Sites/node_modules/mocha/lib/runnable.js:48:17)
at new Hook (/Users/testing/Sites/node_modules/mocha/lib/hook.js:22:12)
at Suite.beforeAll (/Users/testing/Sites/node_modules/mocha/lib/suite.js:170:14)
at context.before (/Users/testing/Sites/node_modules/mocha/lib/interfaces/bdd.js:37:17)
at Object.<anonymous> (/Users/testing/Sites/test/bootstrap.test.js:11:1)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at Object.Module._extensions..js (/Users/testing/Sites/node_modules/istanbul/lib/hook.js:102:13)
at Module.load (module.js:356:32)
@robksawyer
robksawyer / UserController.test.js
Created November 26, 2014 08:01
appHelper.fixtures = null
var sails = require('sails'),
sinon = require('sinon'),
assert = require('assert'),
request = require('supertest'),
appHelper = require('../../helpers/appHelper'),
agent = request.agent('http://localhost:1337');
before(function(done){
appHelper.lift(done);
});
error: Sending 500 ("Server Error") response:
Error (E_VALIDATION) :: 1 attribute is invalid
at WLValidationError.WLError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:33:18)
at new WLValidationError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLValidationError.js:20:28)
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/validate.js:45:43
at allValidationsChecked (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:195:5)
at done (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:135:19)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:32:16
at validate (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:135:49)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:125:13