Skip to content

Commit

Permalink
Merge pull request #27 from bantic/remove-view-$
Browse files Browse the repository at this point in the history
[breaking] Remove `view.$()` call in `render()` of module for component
  • Loading branch information
dgeb committed Mar 17, 2015
2 parents 28c342e + c2d5ad9 commit 63b112f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
17 changes: 5 additions & 12 deletions lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,29 @@ export default TestModule.extend({

this.callbacks.render = function() {
var containerView = Ember.ContainerView.create({container: container});
var view = Ember.run(function(){
Ember.run(function(){
var subject = context.subject();
containerView.pushObject(subject);
containerView.appendTo('#ember-testing');
return subject;
});

_this.teardownSteps.unshift(function() {
Ember.run(function() {
Ember.tryInvoke(containerView, 'destroy');
});
});

return view.$();
};

this.callbacks.append = function() {
Ember.deprecate('this.append() is deprecated. Please use this.render() instead.');
return this.callbacks.render();
Ember.deprecate('this.append() is deprecated. Please use this.render() or this.$() instead.');
return context.$();
};

context.$ = function() {
var $view = this.render();
this.render();
var subject = this.subject();

if (arguments.length){
return subject.$.apply(subject, arguments);
} else {
return $view;
}
return subject.$.apply(subject, arguments);
};
}
});
5 changes: 4 additions & 1 deletion lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default Klass.extend({
this.invokeSteps(this.contextualizedTeardownSteps, this.context);
this.invokeSteps(this.teardownSteps);
this.cache = null;
this.cachedCalls = null;
},

invokeSteps: function(steps, _context) {
Expand Down Expand Up @@ -177,18 +178,20 @@ export default Klass.extend({
var factory = context.factory;

this.cache = this.cache || {};
this.cachedCalls = this.cachedCalls || {};

var keys = Ember.keys(callbacks);

for (var i = 0, l = keys.length; i < l; i++) {
(function(key) {

context[key] = function(options) {
if (_this.cache[key]) { return _this.cache[key]; }
if (_this.cachedCalls[key]) { return _this.cache[key]; }

var result = callbacks[key].call(_this, options, factory());

_this.cache[key] = result;
_this.cachedCalls[key] = true;

return result;
};
Expand Down
28 changes: 23 additions & 5 deletions tests/test-module-for-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ function setupRegistry() {

///////////////////////////////////////////////////////////////////////////////

var originalDeprecate;
moduleForComponent('x-foo', {
needs: ['controller:color'],

setup: function() {
originalDeprecate = Ember.deprecate;
},

teardown: function() {
Ember.deprecate = originalDeprecate;
},

beforeSetup: function() {
setupRegistry();
}
Expand All @@ -68,13 +77,22 @@ test('renders', function() {
});

test('append', function() {
expect(2);
var component = this.subject();
expect(4);

var deprecations = [];
var $el;
var component;

// capture all deprecations so they can be checked later
Ember.deprecate = function(message) {
deprecations.push(message);
};
component = this.subject();
equal(component._state, 'preRender');
this.append();
$el = this.append();
equal(component._state, 'inDOM');
// TODO - is there still a way to check deprecationWarnings?
// ok(Ember.A(Ember.deprecationWarnings).contains('this.append() is deprecated. Please use this.render() instead.'));
ok($el && $el.length, 'append returns $el');
ok(Ember.A(deprecations).contains('this.append() is deprecated. Please use this.render() or this.$() instead.'));
});

test('yields', function() {
Expand Down

0 comments on commit 63b112f

Please sign in to comment.