Skip to content

Commit

Permalink
Merge pull request #11242 from rwjblue/proper-view-for-helpers
Browse files Browse the repository at this point in the history
[BUGFIX beta] Use the proper options.data.view for Handlebars compat helpers.
  • Loading branch information
rwjblue committed May 21, 2015
2 parents 1ce6034 + d93977a commit 2a5efd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/compat/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function HandlebarsCompatibleHelper(fn) {
};

handlebarsOptions.data = {
view: env.view
view: scope.view
};

args.push(handlebarsOptions);
Expand Down
56 changes: 55 additions & 1 deletion packages/ember-htmlbars/tests/compat/helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import makeViewHelper from "ember-htmlbars/system/make-view-helper";
import helpers from "ember-htmlbars/helpers";
import compile from "ember-template-compiler/system/compile";
import { runAppend, runDestroy } from "ember-runtime/tests/utils";
import Registry from "container/registry";
import ComponentLookup from 'ember-views/component_lookup';

var view;
var view, registry, container;

QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', {
setup() {
registry = new Registry();
container = registry.container();
registry.optionsForType('component', { singleton: false });
registry.optionsForType('view', { singleton: false });
registry.optionsForType('template', { instantiate: false });
registry.optionsForType('helper', { instantiate: false });
registry.register('component-lookup:main', ComponentLookup);
},
teardown() {
runDestroy(view);

Expand Down Expand Up @@ -60,6 +71,49 @@ QUnit.test('combines `env` and `options` for the wrapped helper', function() {
runAppend(view);
});

QUnit.test('combines `env` and `options` for the wrapped helper', function() {
expect(1);

function someHelper(options) {
equal(options.data.view, view);
}

registerHandlebarsCompatibleHelper('test', someHelper);

view = EmberView.create({
controller: {
value: 'foo'
},
template: compile('{{test}}')
});

runAppend(view);
});

QUnit.test('has the correct options.data.view within a components layout', function() {
expect(1);
var component;

registry.register('component:foo-bar', Component.extend({
init() {
this._super(...arguments);
component = this;
}
}));

registry.register('template:components/foo-bar', compile('{{my-thing}}'));
registry.register('helper:my-thing', function(options) {
equal(options.data.view, component, 'passed in view should match the current component');
});

view = EmberView.create({
container,
template: compile('{{foo-bar}}')
});

runAppend(view);
});

QUnit.test('adds `hash` into options `options` for the wrapped helper', function() {
expect(1);

Expand Down
9 changes: 3 additions & 6 deletions packages/ember-htmlbars/tests/system/lookup-helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,9 @@ QUnit.test('wraps helper from container in a Handlebars compat helper', function
template: {},
inverse: {}
};
var fakeEnv = {
data: {
view: { }
}
};
actual.helperFunction(fakeParams, fakeHash, fakeOptions, fakeEnv);
var fakeEnv = { };
var fakeScope = { };
actual.helperFunction(fakeParams, fakeHash, fakeOptions, fakeEnv, fakeScope);

ok(called, 'HTMLBars compatible wrapper is wraping the provided function');
});
Expand Down

0 comments on commit 2a5efd6

Please sign in to comment.