diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index 6497cc6edf..5929c5d809 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -358,10 +358,11 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { * the feature received from the server. */ update: function(feature, options) { - options = OpenLayers.Util.applyDefaults(options, this.options); + options = options || {}; var url = options.url || feature.url || this.options.url + "/" + feature.fid; + options = OpenLayers.Util.applyDefaults(options, this.options); var resp = new OpenLayers.Protocol.Response({ reqFeatures: feature, @@ -408,10 +409,11 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { * completes. */ "delete": function(feature, options) { - options = OpenLayers.Util.applyDefaults(options, this.options); + options = options || {}; var url = options.url || feature.url || this.options.url + "/" + feature.fid; + options = OpenLayers.Util.applyDefaults(options, this.options); var resp = new OpenLayers.Protocol.Response({ reqFeatures: feature, diff --git a/tests/Protocol/HTTP.html b/tests/Protocol/HTTP.html index 92177ce7bf..16f6da259b 100644 --- a/tests/Protocol/HTTP.html +++ b/tests/Protocol/HTTP.html @@ -696,6 +696,34 @@ OpenLayers.Request.PUT = _put; } + function test_update_featureurl(t) { + + // test that OpenLayers.Request.PUT receives the URL + // set in the feature + // http://trac.openlayers.org/ticket/2393#comment:11 + + t.plan(1); + + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // feature to pass to update + var feature = {'feature':'feature', 'url': 'bar_url'}; + + var _put = OpenLayers.Request.PUT; + + OpenLayers.Request.PUT = function(options) { + t.eq(options.url, feature.url, + 'PUT called with correct url in options'); + }; + + protocol.update(feature); + + OpenLayers.Request.PUT = _put; + } + function test_handleResponse(t) { t.plan(6); @@ -817,6 +845,34 @@ OpenLayers.Request.DELETE = _delete; } + function test_delete_featureurl(t) { + + // test that OpenLayers.Request.DELETE receives the URL + // set in the feature + // http://trac.openlayers.org/ticket/2393#comment:11 + + t.plan(1); + + var protocol = new OpenLayers.Protocol.HTTP({ + 'url': 'foo_url', + 'format': {'write': function() {}} + }); + + // feature to pass to update + var feature = {'feature':'feature', 'url': 'bar_url'}; + + var _delete = OpenLayers.Request.DELETE; + + OpenLayers.Request.DELETE = function(options) { + t.eq(options.url, feature.url, + 'DELETE called with correct url in options'); + }; + + protocol['delete'](feature); + + OpenLayers.Request.DELETE = _delete; + } + function test_handleDelete(t) { t.plan(4);