Skip to content

Commit 3914e0c

Browse files
committed
Merge pull request #391 from saponifi3d/parseOptions-fix
bug fix for backbone overriding the creation of a model
2 parents cd83109 + 3d6b4c2 commit 3914e0c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

shared/base/view.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module.exports = BaseView = Backbone.View.extend({
2929

3030
this.name = this.name || this.app.modelUtils.underscorize(this.constructor.id || this.constructor.name);
3131

32-
Backbone.View.apply(this, arguments);
32+
// parseOptions deals w/ models and collections, but the BaseView will override those changes
33+
Backbone.View.call(this, _.omit(options, ['model', 'collection']));
3334

3435
if (this.postInitialize) {
3536
console.warn('`postInitialize` is deprecated, please use `initialize`');

test/shared/base/view.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var should = require('chai').should(),
22
sinon = require('sinon'),
3+
_ = require('underscore'),
34
BaseModel = require('../../../shared/base/model'),
45
BaseCollection = require('../../../shared/base/collection'),
56
BaseView = require('../../../shared/base/view'),
@@ -37,6 +38,37 @@ describe('BaseView', function() {
3738
childViews.should.have.length(2);
3839
});
3940

41+
describe('constructor', function() {
42+
var spy, data, view;
43+
44+
beforeEach(function() {
45+
spy = sinon.spy(Backbone, 'View');
46+
data = { app: this.app, el: '#test' };
47+
});
48+
49+
afterEach(function() {
50+
Backbone.View.restore();
51+
})
52+
53+
it('does not pass the model if it is set', function() {
54+
data.model = 'a'
55+
view = new BaseView(data)
56+
57+
spy.should.have.been.called
58+
spy.should.have.been.calledWith(_.omit(data, 'model'))
59+
view.model.should.equal(data.model)
60+
});
61+
62+
it('does not pass the collection if it is set', function() {
63+
data.collection = 'a'
64+
view = new BaseView(data)
65+
66+
spy.should.have.been.called
67+
spy.should.have.been.calledWith(_.omit(data, 'collection'))
68+
view.collection.should.equal(data.collection)
69+
});
70+
});
71+
4072
describe('getTemplate', function() {
4173
beforeEach(function() {
4274
this.app = {

0 commit comments

Comments
 (0)