Skip to content

Commit

Permalink
[BUGFIX beta] Ensure {{view id=bar}} sets id on the view.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Mar 12, 2015
1 parent 5e39827 commit 695302f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/system/merge-view-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function mergeDOMViewBindings(view, props, hash) {
);

if (hash.id) {
props.elementId = read(hash.id);
props.id = props.elementId = read(hash.id);
}

if (hash.tag) {
Expand Down
38 changes: 38 additions & 0 deletions packages/ember-htmlbars/tests/helpers/view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1294,3 +1294,41 @@ QUnit.test("{{view}} asserts that a view subclass instance is present off contro
runAppend(view);
}, /must be a subclass or an instance of Ember.View/);
});

QUnit.test('Specifying `id` to {{view}} is set on the view.', function() {
registry.register('view:derp', EmberView.extend({
template: compile('<div id="view-id">{{view.id}}</div><div id="view-elementId">{{view.elementId}}</div>')
}));

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

runAppend(view);

equal(view.$('#bar').length, 1, 'it uses the provided id for the views elementId');
equal(view.$('#view-id').text(), 'bar', 'the views id property is set');
equal(view.$('#view-elementId').text(), 'bar', 'the views elementId property is set');
});

QUnit.test('Specifying `id` to {{view}} does not allow bound id changes.', function() {
registry.register('view:derp', EmberView.extend({
template: compile('<div id="view-id">{{view.id}}</div><div id="view-elementId">{{view.elementId}}</div>')
}));

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

runAppend(view);

equal(view.$('#view-id').text(), 'bar', 'the views id property is set');

run(view, set, view, 'foo', 'baz');

equal(view.$('#view-id').text(), 'bar', 'the views id property is not changed');
});

0 comments on commit 695302f

Please sign in to comment.