[Pkg-javascript-commits] [backbone] 03/15: Using a save join() for the default implementation of Model#url

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


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

js pushed a commit to tag 0.3.2
in repository backbone.

commit 11dcf246c70e5a53b6c6789b310875482e0f4645
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Nov 16 17:36:53 2010 -0500

    Using a save join() for the default implementation of Model#url
---
 backbone.js   | 2 +-
 test/model.js | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index e2e96ea..12f8b84 100644
--- a/backbone.js
+++ b/backbone.js
@@ -274,7 +274,7 @@
     url : function() {
       var base = getUrl(this.collection);
       if (this.isNew()) return base;
-      return base + '/' + this.id;
+      return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
     },
 
     // **parse** converts a response into the hash of attributes to be `set` on
diff --git a/test/model.js b/test/model.js
index b55ae44..3622015 100644
--- a/test/model.js
+++ b/test/model.js
@@ -53,6 +53,8 @@ $(document).ready(function() {
 
   test("Model: url", function() {
     equals(doc.url(), '/collection/1-the-tempest');
+    doc.collection.url = '/collection/';
+    equals(doc.url(), '/collection/1-the-tempest');
     doc.collection = null;
     var failed = false;
     try {

-- 
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