From 5ff48a68ecac7e0b354504890442dadad6d59712 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Thu, 15 May 2014 22:42:34 -0600 Subject: [PATCH] Closes #51. --- CHANGELOG.md | 1 + Gruntfile.js | 8 ++++++++ bower.json | 2 +- dist/angular-data.js | 18 +++++++++--------- dist/angular-data.min.js | 2 +- src/adapters/http.js | 14 +++++++------- src/datastore/async_methods/create.js | 4 ++-- .../datastore/async_methods/create.test.js | 4 ++-- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c9a865..8cf2551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - #30, #48 - DSCacheFactory integration - #49 - DS.bindOne($scope, prop, resourceName, id) - #50 - DS.bindAll($scope, prop, resourceName, query) +- #51 - Allow baseUrl to be overridable at the method level - #52 - DS.update(resourceName, id, attrs[, options]) (different from DS.save()) - #54 - Adding functionality to resources - #56 - DS.updateAll(resourceName, attrs, params[, options]) diff --git a/Gruntfile.js b/Gruntfile.js index 0b2f687..7484d07 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -292,6 +292,14 @@ module.exports = function (grunt) { 'bower_components/angular-cache/dist/angular-cache.js' ], docs: ['guide/api'] + }, + { + id: 'angular-data-mocks', + title: 'angular-data-mocks', + scripts: [ + 'bower_components/angular-data-mocks/dist/angular-data-mocks.js' + ], + docs: ['guide/api'] } ] } diff --git a/bower.json b/bower.json index b7ce891..9b3cb4f 100644 --- a/bower.json +++ b/bower.json @@ -28,7 +28,7 @@ "devDependencies": { "angular": "~1.2.16", "angular-mocks": "~1.2.16", - "angular-data-mocks": "0.1.0", + "angular-data-mocks": "0.2.0", "angular-cache": "~3.0.0-beta.4", "observe-js": "~0.2.0" } diff --git a/dist/angular-data.js b/dist/angular-data.js index 03cbfab..b70815d 100644 --- a/dist/angular-data.js +++ b/dist/angular-data.js @@ -1589,7 +1589,7 @@ function DSHttpAdapterProvider() { function find(resourceConfig, id, options) { options = options || {}; return this.GET( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), options ); } @@ -1602,7 +1602,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.GET( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), options ); } @@ -1610,7 +1610,7 @@ function DSHttpAdapterProvider() { function create(resourceConfig, attrs, options) { options = options || {}; return this.POST( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), defaults.serialize(attrs), options ); @@ -1618,7 +1618,7 @@ function DSHttpAdapterProvider() { function update(resourceConfig, id, attrs, options) { return this.PUT( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), defaults.serialize(attrs), options ); @@ -1632,7 +1632,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.PUT( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), defaults.serialize(attrs), options ); @@ -1641,7 +1641,7 @@ function DSHttpAdapterProvider() { function destroy(resourceConfig, id, options) { options = options || {}; return this.DEL( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), options ); } @@ -1654,7 +1654,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.DEL( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), options ); } @@ -1664,7 +1664,7 @@ function DSHttpAdapterProvider() { module.exports = DSHttpAdapterProvider; },{}],32:[function(require,module,exports){ -var errorPrefix = 'DS.create(resourceName, attrs): '; +var errorPrefix = 'DS.create(resourceName, attrs[, options]): '; /** * @doc method @@ -1675,7 +1675,7 @@ var errorPrefix = 'DS.create(resourceName, attrs): '; * * ## Signature: * ```js - * DS.create(resourceName, attrs) + * DS.create(resourceName, attrs[, options]) * ``` * * ## Example: diff --git a/dist/angular-data.min.js b/dist/angular-data.min.js index 9bcc039..3416cc8 100644 --- a/dist/angular-data.min.js +++ b/dist/angular-data.min.js @@ -7,5 +7,5 @@ * * @overview Data store for Angular.js. */ -require=function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb&&a.check();)a.report(),b++}function e(a){for(var b in a)return!1;return!0}function f(a){return e(a.added)&&e(a.removed)&&e(a.changed)}function g(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var f in a)f in b||(c[f]=a[f]);return Array.isArray(a)&&a.length!==b.length&&(e.length=a.length),{added:c,removed:d,changed:e}}function h(a,b){var c=b||(Array.isArray(a)?[]:{});for(var d in a)c[d]=a[d];return Array.isArray(a)&&(c.length=a.length),c}function i(a,b,c,d){if(this.closed=!1,this.object=a,this.callback=b,this.target=c,this.token=d,this.reporting=!0,n){var e=this;this.boundInternalCallback=function(a){e.internalCallback(a)}}j(this),this.connect(),this.sync(!0)}function j(a){u&&(t.push(a),i._allObserversCount++)}function k(a,b,c,d){i.call(this,a,b,c,d)}function l(a){this.arr=[],this.callback=a,this.isObserved=!0}function m(a,b,c){for(var d={},e={},f=0;fa&&b.anyChanged);i._allObserversCount=t.length,v=!1}}},u&&(a.Platform.clearObservers=function(){t=[]}),k.prototype=r({__proto__:i.prototype,connect:function(){n&&Object.observe(this.object,this.boundInternalCallback)},sync:function(){n||(this.oldObject=h(this.object))},check:function(a){var b,c;if(n){if(!a)return!1;c={},b=m(this.object,a,c)}else c=this.oldObject,b=g(this.object,this.oldObject);return f(b)?!1:(this.reportArgs=[b.added||{},b.removed||{},b.changed||{}],this.reportArgs.push(function(a){return c[a]}),!0)},disconnect:function(){n?this.object&&Object.unobserve(this.object,this.boundInternalCallback):this.oldObject=void 0}});var x=Object.getPrototypeOf({}),y=Object.getPrototypeOf([]);l.prototype={reset:function(){this.isObserved=!this.isObserved},observe:function(a){if(c(a)&&a!==x&&a!==y){var b=this.arr.indexOf(a);b>=0&&this.arr[b+1]===this.isObserved||(0>b&&(b=this.arr.length,this.arr[b]=a,Object.observe(a,this.callback)),this.arr[b+1]=this.isObserved,this.observe(Object.getPrototypeOf(a)))}},cleanup:function(){for(var a=0,b=0,c=this.isObserved;ba&&(this.arr[a]=d,this.arr[a+1]=c),a+=2):Object.unobserve(d,this.callback),b+=2}this.arr.length=a}};var z={"new":!0,updated:!0,deleted:!0};a.Observer=i,a.Observer.hasObjectObserve=n,a.ObjectObserver=k}((c.Number={isNaN:window.isNaN})?c:c)}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],observejs:[function(a,b){b.exports=a("QYwGEY")},{}],3:[function(a,b){function c(a,b){return-1!==d(a,b)}var d=a("./indexOf");b.exports=c},{"./indexOf":6}],4:[function(a,b){function c(a,b,c){b=d(b,c);var e=[];if(null==a)return e;for(var f,g=-1,h=a.length;++gc?d+c:c;d>e;){if(a[e]===b)return e;e++}return-1}b.exports=c},{}],7:[function(a,b){function c(a){return null!=a&&""!==a}function d(a,b){return b=b||"",e(a,c).join(b)}var e=a("./filter");b.exports=d},{"./filter":4}],8:[function(a,b){function c(a,b,c){var d=a.length;b=null==b?0:0>b?Math.max(d+b,0):Math.min(b,d),c=null==c?d:0>c?Math.max(d+c,0):Math.min(c,d);for(var e=[];c>b;)e.push(a[b++]);return e}b.exports=c},{}],9:[function(a,b){function c(a,b){if(null==a)return[];if(a.length<2)return a;null==b&&(b=d);var f,g,h;return f=~~(a.length/2),g=c(a.slice(0,f),b),h=c(a.slice(f,a.length),b),e(g,h,b)}function d(a,b){return b>a?-1:a>b?1:0}function e(a,b,c){for(var d=[];a.length&&b.length;)d.push(c(a[0],b[0])<=0?a.shift():b.shift());return a.length&&d.push.apply(d,a),b.length&&d.push.apply(d,b),d}b.exports=c},{}],10:[function(a,b){function c(a,b){var c={};if(null==a)return c;var e,f=-1,g=a.length;if(d(b))for(;++f"in a?d=d&&c[b]>a[">"]:">="in a?d=d&&c[b]>=a[">="]:"<"in a?d=d&&c[b]b&&a.check();)a.report(),b++}function e(a){for(var b in a)return!1;return!0}function f(a){return e(a.added)&&e(a.removed)&&e(a.changed)}function g(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var f in a)f in b||(c[f]=a[f]);return Array.isArray(a)&&a.length!==b.length&&(e.length=a.length),{added:c,removed:d,changed:e}}function h(a,b){var c=b||(Array.isArray(a)?[]:{});for(var d in a)c[d]=a[d];return Array.isArray(a)&&(c.length=a.length),c}function i(a,b,c,d){if(this.closed=!1,this.object=a,this.callback=b,this.target=c,this.token=d,this.reporting=!0,n){var e=this;this.boundInternalCallback=function(a){e.internalCallback(a)}}j(this),this.connect(),this.sync(!0)}function j(a){u&&(t.push(a),i._allObserversCount++)}function k(a,b,c,d){i.call(this,a,b,c,d)}function l(a){this.arr=[],this.callback=a,this.isObserved=!0}function m(a,b,c){for(var d={},e={},f=0;fa&&b.anyChanged);i._allObserversCount=t.length,v=!1}}},u&&(a.Platform.clearObservers=function(){t=[]}),k.prototype=r({__proto__:i.prototype,connect:function(){n&&Object.observe(this.object,this.boundInternalCallback)},sync:function(){n||(this.oldObject=h(this.object))},check:function(a){var b,c;if(n){if(!a)return!1;c={},b=m(this.object,a,c)}else c=this.oldObject,b=g(this.object,this.oldObject);return f(b)?!1:(this.reportArgs=[b.added||{},b.removed||{},b.changed||{}],this.reportArgs.push(function(a){return c[a]}),!0)},disconnect:function(){n?this.object&&Object.unobserve(this.object,this.boundInternalCallback):this.oldObject=void 0}});var x=Object.getPrototypeOf({}),y=Object.getPrototypeOf([]);l.prototype={reset:function(){this.isObserved=!this.isObserved},observe:function(a){if(c(a)&&a!==x&&a!==y){var b=this.arr.indexOf(a);b>=0&&this.arr[b+1]===this.isObserved||(0>b&&(b=this.arr.length,this.arr[b]=a,Object.observe(a,this.callback)),this.arr[b+1]=this.isObserved,this.observe(Object.getPrototypeOf(a)))}},cleanup:function(){for(var a=0,b=0,c=this.isObserved;ba&&(this.arr[a]=d,this.arr[a+1]=c),a+=2):Object.unobserve(d,this.callback),b+=2}this.arr.length=a}};var z={"new":!0,updated:!0,deleted:!0};a.Observer=i,a.Observer.hasObjectObserve=n,a.ObjectObserver=k}((c.Number={isNaN:window.isNaN})?c:c)}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],observejs:[function(a,b){b.exports=a("QYwGEY")},{}],3:[function(a,b){function c(a,b){return-1!==d(a,b)}var d=a("./indexOf");b.exports=c},{"./indexOf":6}],4:[function(a,b){function c(a,b,c){b=d(b,c);var e=[];if(null==a)return e;for(var f,g=-1,h=a.length;++gc?d+c:c;d>e;){if(a[e]===b)return e;e++}return-1}b.exports=c},{}],7:[function(a,b){function c(a){return null!=a&&""!==a}function d(a,b){return b=b||"",e(a,c).join(b)}var e=a("./filter");b.exports=d},{"./filter":4}],8:[function(a,b){function c(a,b,c){var d=a.length;b=null==b?0:0>b?Math.max(d+b,0):Math.min(b,d),c=null==c?d:0>c?Math.max(d+c,0):Math.min(c,d);for(var e=[];c>b;)e.push(a[b++]);return e}b.exports=c},{}],9:[function(a,b){function c(a,b){if(null==a)return[];if(a.length<2)return a;null==b&&(b=d);var f,g,h;return f=~~(a.length/2),g=c(a.slice(0,f),b),h=c(a.slice(f,a.length),b),e(g,h,b)}function d(a,b){return b>a?-1:a>b?1:0}function e(a,b,c){for(var d=[];a.length&&b.length;)d.push(c(a[0],b[0])<=0?a.shift():b.shift());return a.length&&d.push.apply(d,a),b.length&&d.push.apply(d,b),d}b.exports=c},{}],10:[function(a,b){function c(a,b){var c={};if(null==a)return c;var e,f=-1,g=a.length;if(d(b))for(;++f"in a?d=d&&c[b]>a[">"]:">="in a?d=d&&c[b]>=a[">="]:"<"in a?d=d&&c[b]e?-1:e>d?1:0:e>d?-1:d>e?1:0})}}return this.utils.isNumber(b.query.limit)&&this.utils.isNumber(b.query.skip)?i=this.utils.slice(i,b.query.skip,Math.min(i.length,b.query.skip+b.query.limit)):this.utils.isNumber(b.query.limit)?i=this.utils.slice(i,0,Math.min(i.length,b.query.limit)):this.utils.isNumber(b.query.skip)&&(i=b.query.skip=b?a+1:b},deepFreeze:function b(a){if("function"==typeof Object.freeze){var c,d;Object.freeze(a);for(d in a)c=a[d],a.hasOwnProperty(d)&&"object"==typeof c&&!Object.isFrozen(c)&&b(c)}},diffObjectFromOldObject:function(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var h in a)h in b||(c[h]=a[h]);return{added:c,removed:d,changed:e}}}}]},{"mout/array/contains":3,"mout/array/filter":4,"mout/array/slice":8,"mout/array/sort":9,"mout/array/toLookup":10,"mout/lang/isEmpty":15,"mout/object/deepMixIn":22,"mout/object/forOwn":24,"mout/object/pick":27,"mout/object/set":28,"mout/string/makePath":29,"mout/string/upperCase":30}],utils:[function(a,b){b.exports=a("K0yknU")},{}]},{},[60]); \ No newline at end of file diff --git a/src/adapters/http.js b/src/adapters/http.js index 34e0d52..e99130b 100644 --- a/src/adapters/http.js +++ b/src/adapters/http.js @@ -386,7 +386,7 @@ function DSHttpAdapterProvider() { function find(resourceConfig, id, options) { options = options || {}; return this.GET( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), options ); } @@ -399,7 +399,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.GET( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), options ); } @@ -407,7 +407,7 @@ function DSHttpAdapterProvider() { function create(resourceConfig, attrs, options) { options = options || {}; return this.POST( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), defaults.serialize(attrs), options ); @@ -415,7 +415,7 @@ function DSHttpAdapterProvider() { function update(resourceConfig, id, attrs, options) { return this.PUT( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), defaults.serialize(attrs), options ); @@ -429,7 +429,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.PUT( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), defaults.serialize(attrs), options ); @@ -438,7 +438,7 @@ function DSHttpAdapterProvider() { function destroy(resourceConfig, id, options) { options = options || {}; return this.DEL( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint, id), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id), options ); } @@ -451,7 +451,7 @@ function DSHttpAdapterProvider() { } DSUtils.deepMixIn(options, params); return this.DEL( - DSUtils.makePath(resourceConfig.baseUrl, resourceConfig.endpoint), + DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint), options ); } diff --git a/src/datastore/async_methods/create.js b/src/datastore/async_methods/create.js index 285ab09..6c11779 100644 --- a/src/datastore/async_methods/create.js +++ b/src/datastore/async_methods/create.js @@ -1,4 +1,4 @@ -var errorPrefix = 'DS.create(resourceName, attrs): '; +var errorPrefix = 'DS.create(resourceName, attrs[, options]): '; /** * @doc method @@ -9,7 +9,7 @@ var errorPrefix = 'DS.create(resourceName, attrs): '; * * ## Signature: * ```js - * DS.create(resourceName, attrs) + * DS.create(resourceName, attrs[, options]) * ``` * * ## Example: diff --git a/test/integration/datastore/async_methods/create.test.js b/test/integration/datastore/async_methods/create.test.js index 6cf8355..155f300 100644 --- a/test/integration/datastore/async_methods/create.test.js +++ b/test/integration/datastore/async_methods/create.test.js @@ -1,5 +1,5 @@ -describe('DS.create(resourceName, attrs)', function () { - var errorPrefix = 'DS.create(resourceName, attrs): '; +describe('DS.create(resourceName, attrs[, options])', function () { + var errorPrefix = 'DS.create(resourceName, attrs[, options]): '; it('should throw an error when method pre-conditions are not met', function (done) { DS.create('does not exist', 5).then(function () {