Skip to content

Commit

Permalink
Merge a7076b7 into 2b07b94
Browse files Browse the repository at this point in the history
  • Loading branch information
saponifi3d committed May 15, 2015
2 parents 2b07b94 + a7076b7 commit ee2d0f4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shared/base/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ module.exports = BaseView = Backbone.View.extend({
};
}

// Allow ability to just pass the full "spec" to a lazy loaded view
if (this.options.fetch_spec) {
if (!_.isObject(this.options.fetch_spec)) {
throw new Error('fetch_spec must be an object for lazy loaded views')
}

fetchSpec = this.options.fetch_spec;
}

this.setLoading(true);

this._preRender();
Expand Down
32 changes: 32 additions & 0 deletions test/shared/base/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,38 @@ describe('BaseView', function() {
});
});

describe('fetchLazy', function () {
beforeEach(function () {
this.app = {
fetch: sinon.spy(),
modelUtils: modelUtils
};

this.view = new this.MyTopView({ app: this.app });
sinon.stub(this.view, 'setLoading')
});

context('passed a fetch_spec', function () {
var fetchSpec;

beforeEach(function () {
fetchSpec = {
model: {
model: 'Test',
params: { id: 1 }
}
};

this.view.options.fetch_spec = fetchSpec;
});

it('overrides the fetchSpec and calls fetch with it.', function () {
this.view.fetchLazy();
expect(this.app.fetch).to.have.been.calledWith(fetchSpec);
});
});
});

describe('_fetchLazyCallback', function() {
beforeEach(function() {
this.app = {
Expand Down

0 comments on commit ee2d0f4

Please sign in to comment.