attaching url and urlRoot on the model if passed

This commit is contained in:
Tim Griesser
2013-03-19 15:36:00 -04:00
parent 7edfcf8426
commit b490e477f7
2 changed files with 9 additions and 0 deletions

View File

@@ -244,6 +244,8 @@
var attrs = attributes || {};
this.cid = _.uniqueId('c');
this.attributes = {};
if (options && options.url) this.url = options.url;
if (options && options.urlRoot) this.urlRoot = options.urlRoot;
if (options && options.collection) this.collection = options.collection;
if (options && options.parse) attrs = this.parse(attrs, options) || {};
if (defaults = _.result(this, 'defaults')) {

View File

@@ -111,6 +111,13 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});
test('url and urlRoot are directly attached if passed in the options', 2, function () {
var model = new Backbone.Model({a: 1}, {url: '/test'});
var model2 = new Backbone.Model({a: 2}, {urlRoot: '/test2'});
equal(model.url, '/test');
equal(model2.urlRoot, '/test2');
});
test("underscore methods", 5, function() {
var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
var model2 = model.clone();