Skip to content

Commit

Permalink
Fix {{#with view.foo as bar}}
Browse files Browse the repository at this point in the history
The `with` helper can correctly bind through the `view` keyword when
it's used like this:

    {{#with view.foo}}

But the binding is broken if you try it like this:

    {{#with view.foo as bar}}

This change fixes it.
  • Loading branch information
ef4 committed Jul 6, 2014
1 parent 3b46733 commit 6d9e886
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-handlebars/lib/helpers/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ function withHelper(context, options) {
localizedOptions.hash.keywordPath = contextPath;

bindContext = this;
context = path;
context = contextPath;
options = localizedOptions;
preserveContext = true;
} else {
Expand Down
27 changes: 27 additions & 0 deletions packages/ember-handlebars/tests/helpers/with_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,30 @@ test("destroys the controller generated with {{with foo as bar controller='blah'

ok(destroyed, 'controller was destroyed properly');
});

QUnit.module("{{#with}} helper binding to view keyword", {
setup: function() {
Ember.lookup = lookup = { Ember: Ember };

view = EmberView.create({
template: EmberHandlebars.compile("We have: {{#with view.thing as fromView}}{{fromView.name}} and {{fromContext.name}}{{/with}}"),
thing: { name: 'this is from the view' },
context: {
fromContext: { name: "this is from the context" },
}
});

appendView(view);
},

teardown: function() {
run(function() {
view.destroy();
});
Ember.lookup = originalLookup;
}
});

test("{{with}} helper can bind to keywords with 'as'", function(){
equal(view.$().text(), "We have: this is from the view and this is from the context", "should render");
});

0 comments on commit 6d9e886

Please sign in to comment.