Permalink
Browse files

Using a save join() for the default implementation of Model#url

  • Loading branch information...
jashkenas committed Nov 16, 2010
1 parent 99fbc08 commit 11dcf246c70e5a53b6c6789b310875482e0f4645
Showing with 3 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +2 −0 test/model.js
View
@@ -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
View
@@ -52,6 +52,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;

0 comments on commit 11dcf24

Please sign in to comment.