Skip to content

Instantly share code, notes, and snippets.

View christiansmith's full-sized avatar

Christian Smith christiansmith

View GitHub Profile
@christiansmith
christiansmith / e2e-login-scenario.coffee
Created November 16, 2012 17:59
AngularJS/Testacular e2e test navigation issue
###
I have an AngularJS application that requires authentication. It's
part of a larger project served from Express and lives at its own
base path: `<base href="/path/to/app/">`, not `/`. The existing
application already has a round trip login. Users need to be logged
in before they can access the Angular app. This works fine, except
for e2e testing with testacular.
With authentication on the server disabled, e2e tests run without
problems. For example:
describe('SomeService', function () {
var SomeService, $window;
beforeEach(module('app.services'));
beforeEach(inject(function ($injector) {
SomeService = $injector.get('SomeService');
$window = $injector.get('$window');
}));
angular.module('app.services')
.factory('SomeService', function ($q, $http) {
function withQuery(path, options) {
if (options) {
var params = [];
for (var key in options) {
params.push(key + '=' + options[key]);
}
User.create = function (data, callback) {
var user = new User(data)
, validation = user.validate();
if (!user.id) { user.id = uuid.v4(); }
if (!user.created) { user.created = Date.now() }
if (!validation.valid) { return callback(validation); }
async.parallel({
'use strict';
angular.module('authentication')
.factory('CurrentUser', function ($http, $location) {
function CurrentUser () {}
CurrentUser.isAuthenticated = false;
CurrentUser.requiresAuthentication = false;
var express = require('express')
, RedisStore = require('connect-redis')(express)
, authorize = require('oauth2resource')({
uri: 'https://authserver.tld/access',
cache: new RedisStore({ prefix: 'auth' })
}).authorize
, app = express();
app.configure(function () {
/**
* Module dependencies
*/
var _ = require('underscore')
, validate = require('../lib/validate');
/**
* User constructor
var _ = require('underscore')
, fs = require('fs')
, path = require('path')
, crypto = require('crypto')
;
function JSONFile (config) {
this.config = config;
# ...
practice ()
{
practicedir=~/Projects/practice/$(date +%Y-%m-%d)/$1
mkdir -p $practicedir && cd $practicedir
echo ""
echo "Welcome to $practicedir"
echo ""
echo "May you become less dumb through deliberate practice."
sip = 1
slurp = 2
gulp = 3
class EarlyRiser
constructor: (@config) ->
@caffeinated = false
@cupsRequired = @config.cupsRequired
@cupsConsumed =