From 5968e555f5b70c52108a2166930a3aea2154ed02 Mon Sep 17 00:00:00 2001 From: Pablo Vallejo Date: Wed, 30 Apr 2014 21:45:09 -0500 Subject: [PATCH] Add 'Post' request method tests. --- bower.json | 2 +- gillie.js | 5 ++- gillie.min.js | 4 +-- package.json | 2 +- tests/environment.js | 19 ++++++++++ tests/index.html | 5 +-- tests/model-view.js | 3 +- tests/requests.js | 84 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 tests/environment.js create mode 100644 tests/requests.js diff --git a/bower.json b/bower.json index 0a02242..369ade1 100644 --- a/bower.json +++ b/bower.json @@ -9,7 +9,7 @@ "authors": [ "Pablo Vallejo " ], - "description": "Lightweight JavaScript framework inspired in Backbone", + "description": "Lightweight JavaScript MVC framework inspired in Backbone", "keywords": [ "javascript", "framework", diff --git a/gillie.js b/gillie.js index b0f2350..af7f261 100644 --- a/gillie.js +++ b/gillie.js @@ -12,7 +12,7 @@ var // Gillie version - version = '0.2.0' + version = '0.2.1' , initializing = false , fnTest = /xyz/.test( function(){ xyz; }) ? /\b_super\b/ : /.*/ @@ -307,8 +307,7 @@ return optional ? match : modelVar || match; }); - // Use `route` as full URL if its contains - // `http:|https:`. + // Use `route` as full URL if its contains `http:` or `https:`. return (/^(\/\/|http:|https:).*/.test( route )) ? route : ( this.url ? this.url + route : window.location.href + '/' + route ); diff --git a/gillie.min.js b/gillie.min.js index 636c3c9..122c749 100644 --- a/gillie.min.js +++ b/gillie.min.js @@ -1,5 +1,5 @@ /*! -* Gillie JavaScript Library 0.2.0 +* Gillie JavaScript Library 0.2.1 * http://pablovallejo.github.io/gillie */ -!function(a,b){var c=!1,d=/xyz/.test(function(){})?/\b_super\b/:/.*/,e=function(){},f=function(b){return a.each([].slice.call(arguments,1),function(a,c){if(c)for(var d in c)b[d]=c[d]}),b},g=e.Events={on:function(a,b,c){if(!i(this,"on",a,[b,c])||!b)return this;this._events||(this._events={});var d=this._events[a]||(this._events[a]=[]);return d.push({callback:b,context:c,ctx:c||this}),this},trigger:function(a){if(!this._events)return this;var b=[].slice.call(arguments,1);if(!i(this,"trigger",a,b))return this;var c=this._events[a];return c&&j(c,b),this}},h=/\s+/,i=function(a,b,c,d){if(c){if("object"==typeof c){for(var e in c)a[b].apply(a,[e,c[e]].concat(d));return!1}if(h.test(c)){for(var f=c.split(h),g=0,i=f.length;i>g;g++)a[b].apply(a,[f[g]].concat(d));return!1}return!0}},j=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++dg;g++)a[b].apply(a,[f[g]].concat(d));return!1}return!0}},j=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++d + - + @@ -22,4 +23,4 @@ - \ No newline at end of file + diff --git a/tests/model-view.js b/tests/model-view.js index 5fbc745..12b1993 100644 --- a/tests/model-view.js +++ b/tests/model-view.js @@ -1,5 +1,5 @@ /** -* General Gillie tests +* Tests for model and view */ $( document ).ready( function() { @@ -101,7 +101,6 @@ $( document ).ready( function() { }); - test( 'Set and unset', 4, function() { var m = new Gillie.Model({ id: 'id', foo: 1, bar: 2, baz: 3 }); diff --git a/tests/requests.js b/tests/requests.js new file mode 100644 index 0000000..e0eaf7f --- /dev/null +++ b/tests/requests.js @@ -0,0 +1,84 @@ +/** + * Request Tests + */ + +$(document).ready(function(){ + + // Model + var person; + Person = Gillie.Model.extend({ + + // Base URL + url: 'http://myapi.io' + }); + + // Requests + //---------------- + module('Gillie requests', { + + setup: function() { + + // Create a new person + person = new Person({ + name: 'Fonzie', + age: 40 + }); + } + }); + + // Test Model.Post method + test( 'Model.Post', function() { + + // Save user + person.Post( '/person' ); + + // Get data + var data = JSON.parse( this.ajaxSettings.data ); + + // Test equality + equal( this.ajaxSettings.type, 'POST' ); + equal( this.ajaxSettings.dataType, 'json' ); + equal( this.ajaxSettings.url, 'http://myapi.io/person' ); + equal( data.name, person.get( 'name' ) ); + equal( data.age, person.get( 'age' ) ); + + }); + + // Test Model.Post passing a complete URL + test( 'Model.Post full URL http', function() { + + // Save user + person.Post( 'http://otherapi.io/person' ); + + // Get data + var data = JSON.parse( this.ajaxSettings.data ); + + // Test equality + equal( this.ajaxSettings.type, 'POST' ); + equal( this.ajaxSettings.dataType, 'json' ); + equal( this.ajaxSettings.url, 'http://otherapi.io/person' ); + equal( data.name, person.get( 'name' ) ); + equal( data.age, person.get( 'age' ) ); + + console.log( this.ajaxSettings ); + + }); + + // Test Model.Post passing a complete URL + test( 'Model.Post full URL https', function() { + + // Save user + person.Post( 'https://otherapi.io/person' ); + equal( this.ajaxSettings.url, 'https://otherapi.io/person' ); + }); + + // Test Model.Post passing a complete URL + test( 'Model.Post full URL not https or http', function() { + + // Save user + person.Post( 'ttps://otherapi.io/person' ); + equal( this.ajaxSettings.url, 'http://myapi.iottps://otherapi.io/person' ); + + }); + +});