Skip to content

Commit

Permalink
Add 'Post' request method tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloVallejo authored and --global committed May 1, 2014
1 parent 1e30383 commit 5968e55
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"authors": [
"Pablo Vallejo <[email protected]>"
],
"description": "Lightweight JavaScript framework inspired in Backbone",
"description": "Lightweight JavaScript MVC framework inspired in Backbone",
"keywords": [
"javascript",
"framework",
Expand Down
5 changes: 2 additions & 3 deletions gillie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/ : /.*/
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions gillie.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gillie",
"title": "Gillie",
"version": "0.2.0",
"version": "0.2.1",
"description": "JavaScript MVC Microframework",
"homepage": "http://pablovallejo.github.io/gillie",
"directories": {
Expand Down
19 changes: 19 additions & 0 deletions tests/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Test environment setup
*/
(function() {

// Setup config variables on test start
QUnit.testStart(function() {

var env = this.config.current.testEnvironment;

// Capture Gillie.ajax arguments for comparison.
// Adapted from https://github.com/jashkenas/backbone/blob/master/test/environment.js#L23
Gillie.ajax = function( settings ) {
env.ajaxSettings = settings;
}

});

})();
5 changes: 3 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<script src="vendor/qunit.js"></script>
<script src="vendor/utilities.js"></script>
<script src="../gillie.js"></script>
<script src="environment.js"></script>
<script src="events.js"></script>
<script src="handler.js"></script>
<script src="model-view-controller.js"></script>
<script src="inheritance.js"></script>
<script src="requests.js"></script>
</head>
<body>

Expand All @@ -22,4 +23,4 @@

</div>
</div>
</html>
</html>
3 changes: 1 addition & 2 deletions tests/model-view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* General Gillie tests
* Tests for model and view
*/

$( document ).ready( function() {
Expand Down Expand Up @@ -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 });
Expand Down
84 changes: 84 additions & 0 deletions tests/requests.js
Original file line number Diff line number Diff line change
@@ -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' );

});

});

0 comments on commit 5968e55

Please sign in to comment.