Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Jacobs committed Apr 27, 2012
2 parents 78d7d12 + 520984b commit a296c4c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 54 deletions.
9 changes: 1 addition & 8 deletions kevlar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5616,13 +5616,6 @@ Kevlar.persistence.RestProxy = Kevlar.extend( Kevlar.persistence.Proxy, {
*/
urlRoot : "",

/**
* @cfg {Boolean} appendId
* True to automatically append the ID of the Model to the {@link #urlRoot} when
* performing 'read', 'update', and 'delete' actions.
*/
appendId: true,

/**
* @cfg {Boolean} incremental
* True to have the RestProxy only provide data that has changed to the server when
Expand Down Expand Up @@ -5897,7 +5890,7 @@ Kevlar.persistence.RestProxy = Kevlar.extend( Kevlar.persistence.Proxy, {
var url = this.urlRoot;

// And now, use the model's ID to set the url.
if( this.appendId ) {
if( action !== 'create' ) {
if( !url.match( /\/$/ ) ) {
url += '/';
}
Expand Down
2 changes: 1 addition & 1 deletion kevlar.min.js

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions src/persistence/RestProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ Kevlar.persistence.RestProxy = Kevlar.extend( Kevlar.persistence.Proxy, {
*/
urlRoot : "",

/**
* @cfg {Boolean} appendId
* True to automatically append the ID of the Model to the {@link #urlRoot} when
* performing 'read', 'update', and 'delete' actions.
*/
appendId: true,

/**
* @cfg {Boolean} incremental
* True to have the RestProxy only provide data that has changed to the server when
Expand Down Expand Up @@ -300,7 +293,7 @@ Kevlar.persistence.RestProxy = Kevlar.extend( Kevlar.persistence.Proxy, {
var url = this.urlRoot;

// And now, use the model's ID to set the url.
if( this.appendId ) {
if( action !== 'create' ) {
if( !url.match( /\/$/ ) ) {
url += '/';
}
Expand Down
33 changes: 15 additions & 18 deletions tests/kevlarTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7023,7 +7023,7 @@ tests.unit.persistence.add( new Ext.test.TestSuite( {
name: 'Test buildUrl()',


"buildUrl() should return simply the configured urlRoot, if the 'appendId' config is false" : function() {
"buildUrl() should handle a urlRoot without a trailing slash" : function() {
var mockModel = JsMockito.mock( Kevlar.Model );
JsMockito.when( mockModel ).getId().thenReturn( 42 );

Expand All @@ -7032,29 +7032,26 @@ tests.unit.persistence.add( new Ext.test.TestSuite( {
appendId : false
} );

Y.Assert.areSame( '/testUrl', proxy.buildUrl( mockModel ), "buildUrl() should have simply still returned the url" );
Y.Assert.areSame( '/testUrl', proxy.buildUrl( mockModel, 'create' ), "buildUrl() should have returned the urlRoot when doing a 'create'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'read' ), "buildUrl() should have appended the ID when doing a 'read'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'update' ), "buildUrl() should have appended the ID when doing a 'update'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'delete' ), "buildUrl() should have appended the ID when doing a 'delete'" );
},
"buildUrl() should return the configured urlRoot with the model's id, if the 'appendId' config is true" : function() {


"buildUrl() should handle a urlRoot with a trailing slash" : function() {
var mockModel = JsMockito.mock( Kevlar.Model );
JsMockito.when( mockModel ).getId().thenReturn( 42 );

// Try with no trailing slash on the url
var proxy1 = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl', // note: no trailing slash
appendId : true
} );

Y.Assert.areSame( '/testUrl/42', proxy1.buildUrl( mockModel ), "buildUrl() should have returned the url with the id appended" );

// Try with a trailing slash on the url
var proxy2 = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl/', // note: trailing slash exists
appendId : true
var proxy = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl/',
appendId : false
} );

Y.Assert.areSame( '/testUrl/42', proxy2.buildUrl( mockModel ), "buildUrl() should have returned the url with the id appended" );
Y.Assert.areSame( '/testUrl/', proxy.buildUrl( mockModel, 'create' ), "buildUrl() should have returned the urlRoot when doing a 'create'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'read' ), "buildUrl() should have appended the ID when doing a 'read'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'update' ), "buildUrl() should have appended the ID when doing a 'update'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'delete' ), "buildUrl() should have appended the ID when doing a 'delete'" );
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion tests/kevlarTests.min.js

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions tests/unit/persistence/RestProxyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ tests.unit.persistence.add( new Ext.test.TestSuite( {
name: 'Test buildUrl()',


"buildUrl() should return simply the configured urlRoot, if the 'appendId' config is false" : function() {
"buildUrl() should handle a urlRoot without a trailing slash" : function() {
var mockModel = JsMockito.mock( Kevlar.Model );
JsMockito.when( mockModel ).getId().thenReturn( 42 );

Expand All @@ -508,29 +508,26 @@ tests.unit.persistence.add( new Ext.test.TestSuite( {
appendId : false
} );

Y.Assert.areSame( '/testUrl', proxy.buildUrl( mockModel ), "buildUrl() should have simply still returned the url" );
Y.Assert.areSame( '/testUrl', proxy.buildUrl( mockModel, 'create' ), "buildUrl() should have returned the urlRoot when doing a 'create'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'read' ), "buildUrl() should have appended the ID when doing a 'read'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'update' ), "buildUrl() should have appended the ID when doing a 'update'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'delete' ), "buildUrl() should have appended the ID when doing a 'delete'" );
},
"buildUrl() should return the configured urlRoot with the model's id, if the 'appendId' config is true" : function() {


"buildUrl() should handle a urlRoot with a trailing slash" : function() {
var mockModel = JsMockito.mock( Kevlar.Model );
JsMockito.when( mockModel ).getId().thenReturn( 42 );

// Try with no trailing slash on the url
var proxy1 = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl', // note: no trailing slash
appendId : true
} );

Y.Assert.areSame( '/testUrl/42', proxy1.buildUrl( mockModel ), "buildUrl() should have returned the url with the id appended" );

// Try with a trailing slash on the url
var proxy2 = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl/', // note: trailing slash exists
appendId : true
var proxy = new Kevlar.persistence.RestProxy( {
urlRoot : '/testUrl/',
appendId : false
} );

Y.Assert.areSame( '/testUrl/42', proxy2.buildUrl( mockModel ), "buildUrl() should have returned the url with the id appended" );
Y.Assert.areSame( '/testUrl/', proxy.buildUrl( mockModel, 'create' ), "buildUrl() should have returned the urlRoot when doing a 'create'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'read' ), "buildUrl() should have appended the ID when doing a 'read'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'update' ), "buildUrl() should have appended the ID when doing a 'update'" );
Y.Assert.areSame( '/testUrl/42', proxy.buildUrl( mockModel, 'delete' ), "buildUrl() should have appended the ID when doing a 'delete'" );
}
}
]
Expand Down

0 comments on commit a296c4c

Please sign in to comment.