Skip to content

Commit

Permalink
feat(tests): completed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Sharp committed Feb 9, 2015
2 parents 35d463a + 39765c6 commit d1b4e39
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 124 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ bower_components
build

.tern-project
.idea
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ before_script:
- bower install -F

script:
- gulp build
- gulp build-js
- gulp test
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/janpantel/angular-sails.svg?branch=master)](https://travis-ci.org/janpantel/angular-sails)

Angular Sails
=============

Expand Down Expand Up @@ -30,10 +32,10 @@ app.controller("FooController", function ($scope, $sails) {
(function () {
// Using .success() and .error()
$sails.get("/bars")
.success(function (data, status, headers) {
.success(function (data, status, headers, jwr) {
$scope.bars = data;
})
.error(function (data, status, headers) {
.error(function (data, status, headers, jwr) {
alert('Houston, we got a problem!');
});

Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-sails",
"version": "1.0.4",
"version": "1.0.5",
"authors": [
"Jan-Oliver Pantel <[email protected]>"
],
Expand Down Expand Up @@ -29,7 +29,8 @@
"gulpfile.js",
"package.json",
"node_modules",
"build"
"build",
"mock",
"bower_components",
"app/bower_components",
"test",
Expand Down
46 changes: 35 additions & 11 deletions mock/socket-io.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
function io (){
// fix for phantomjs < 2.0
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};

fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();

return fBound;
};
}

function io() {
var mockSocketObject = createMockSocketObject();
return mockSocketObject.connect();
}

function createMockSocketObject () {
function createMockSocketObject() {

var socket = {
on: function (ev, fn) {
on: function(ev, fn) {
(this._listeners[ev] = this._listeners[ev] || []).push(fn);
},
once: function (ev, fn) {
once: function(ev, fn) {
(this._raw._listeners[ev] = this._raw._listeners[ev] || []).push(fn);
fn._once = true;
},
emit: function (ev, data) {
emit: function(ev, data) {
if (this._listeners[ev]) {
var args = arguments;
this._listeners[ev].forEach(function (listener) {
this._listeners[ev].forEach(function(listener) {
if (listener._once) {
this.removeListener(ev, listener);
}
listener.apply(null, Array.prototype.slice.call(args, 1));
},this);
}.bind(this));
}
},
_listeners: {},
removeListener: function (ev, fn) {
removeListener: function(ev, fn) {
if (fn) {
var index = this._listeners[ev].indexOf(fn);
if (index > -1) {
Expand All @@ -35,18 +59,18 @@ function createMockSocketObject () {
delete this._listeners[ev];
}
},
removeAllListeners: function (ev) {
removeAllListeners: function(ev) {
if (ev) {
delete this._listeners[ev];
} else {
this._listeners = {};
}
},
disconnect: function () {
disconnect: function() {
this.connected = false;
this.emit('disconnect');
},
connect: function () {
connect: function() {
this.connected = true;
this.emit('connect');
return this;
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "angular-sails",
"private": true,
"version": "1.0.3",
"version": "1.0.5",
"description": "An angular provider for using the sails socket.io api",
"scripts": {
"build": "gulp build-js",
"test": "gulp test"
},
"repository": {
"type": "git",
"url": "https://github.com/kyjan/angular-sails.git"
Expand Down
Loading

0 comments on commit d1b4e39

Please sign in to comment.