[Pkg-javascript-commits] [backbone] 04/211: Add urlBase option to model to allow specifying restful url without using a collection

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.5.0
in repository backbone.

commit 524901083e9cb8e20aa7db844c117c9998f55e5a
Author: Matt <matt at zurb.com>
Date:   Thu Dec 2 14:23:13 2010 -0800

    Add urlBase option to model to allow specifying restful url without using a collection
---
 backbone.js   |  2 +-
 test/model.js | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index 3031eb1..2663ff1 100644
--- a/backbone.js
+++ b/backbone.js
@@ -287,7 +287,7 @@
     // using Backbone's restful methods, override this to change the endpoint
     // that will be called.
     url : function() {
-      var base = getUrl(this.collection);
+      var base = this.urlBase || getUrl(this.collection);
       if (this.isNew()) return base;
       return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
     },
diff --git a/test/model.js b/test/model.js
index c1dfe3e..a7cdcdd 100644
--- a/test/model.js
+++ b/test/model.js
@@ -65,6 +65,16 @@ $(document).ready(function() {
     equals(failed, true);
     doc.collection = collection;
   });
+  
+  test("Model: url when using urlBase", function() {
+    var Model = Backbone.Model.extend({
+      urlBase: '/collection'
+    });
+    var model = new Model();
+    equals(model.url(), '/collection');
+    model.set({id: '1'});
+    equals(model.url(), '/collection/1');
+  });
 
   test("Model: clone", function() {
     attrs = { 'foo': 1, 'bar': 2, 'baz': 3};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list