Skip to content

Commit

Permalink
Pipeline:Rest - Add ability to set contentType and dataType during pi…
Browse files Browse the repository at this point in the history
…pe creation. Fixes AGJS-31
  • Loading branch information
kborchers committed Jun 6, 2013
1 parent dcb91f3 commit 9d0710b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/pipeline/adapters/rest.js
Expand Up @@ -22,6 +22,8 @@
@param {Object} [settings={}] - the settings to be passed to the adapter
@param {Object} [settings.authenticator=null] - the AeroGear.auth object used to pass credentials to a secure endpoint
@param {String} [settings.baseURL] - defines the base URL to use for an endpoint
@param {String} [settings.contentType="application/json"] - the default type of content being sent to the server
@param {String} [settings.dataType="json"] - the default type of data expected to be returned from the server
@param {String} [settings.endpoint=pipename] - overrides the default naming of the endpoint which uses the pipeName
@param {Object|Boolean} [settings.pageConfig] - an object containing the current paging configuration, true to use all defaults or false/undefined to not use paging
@param {String} [settings.pageConfig.metadataLocation="webLinking"] - indicates whether paging information is received from the response "header", the response "body" or via RFC 5988 "webLinking", which is the default.
Expand Down Expand Up @@ -65,8 +67,8 @@ AeroGear.Pipeline.adapters.Rest = function( pipeName, settings ) {
ajaxSettings = {
// use the pipeName as the default rest endpoint
url: settings.baseURL ? settings.baseURL + endpoint : endpoint,
contentType: "application/json",
dataType: "json"
contentType: settings.contentType || "application/json",
dataType: settings.dataType || "json"
},
recordId = settings.recordId || "id",
authenticator = settings.authenticator || null,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/pipeline/pipeline-mockjax-config.js
Expand Up @@ -40,6 +40,12 @@ $.mockjax({
]
});

$.mockjax({
url: "text",
type: "GET",
responseText: "plain text response"
});

// save mocks
$.mockjax({
url: "tasks",
Expand Down
26 changes: 20 additions & 6 deletions tests/unit/pipeline/pipeline-rest.js
Expand Up @@ -90,35 +90,43 @@ var pipeline = AeroGear.Pipeline([
baseURL: "baseURL/",
endpoint: "customEndPoint"
}
},
{
name: "text",
settings: {
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "text"
}
}
]),
pipe = pipeline.pipes.tasks,
pipe2 = pipeline.pipes.tasksCustom,
pipe3 = pipeline.pipes.projects,
pipe4 = pipeline.pipes.tags,
pipe5 = pipeline.pipes.users;
pipe5 = pipeline.pipes.users,
textPipe = pipeline.pipes.text;

// Add pipe test
test( "add method", function() {
expect( 2 );

var pipe = pipeline.add( "addTest" ).pipes;
equal( Object.keys( pipe ).length, 6, "Single Pipe added" );
equal( Object.keys( pipe )[ 5 ], "addTest", "Pipe Name addTest" );
equal( Object.keys( pipe ).length, 7, "Single Pipe added" );
equal( Object.keys( pipe )[ 6 ], "addTest", "Pipe Name addTest" );
});

// Remove pipe test
test( "remove method", function() {
expect( 2 );

var pipe = pipeline.remove( "addTest" ).pipes;
equal( Object.keys( pipe ).length, 5, "Single Pipe removed" );
equal( Object.keys( pipe ).length, 6, "Single Pipe removed" );
equal( pipe.addTest, undefined, "Removed pipe is really gone" );
});

// Read method test
asyncTest( "read method", function() {
expect( 2 );
expect( 3 );

var read1 = pipe.read({
success: function( data, textStatus, jqXHR ) {
Expand All @@ -133,7 +141,13 @@ asyncTest( "read method", function() {
}
});

$.when( read1, read2 ).done( function( r1, r2 ) {
var read3 = textPipe.read({
success: function( data, textStatus, jqXHR ) {
equal( data, "plain text response", "Read with non-default dataType" );
}
});

$.when( read1, read2, read3 ).done( function( r1, r2, r3 ) {
start();
});
});
Expand Down

0 comments on commit 9d0710b

Please sign in to comment.