forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport warnings and errors for 1.0's Ember.Object.create() behaviour.
Closes #2.
- Loading branch information
Showing
4 changed files
with
186 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# `Ember.Object.create` | ||
|
||
This backports the `create` and `createWithMixins` functionality from Ember 1.0 | ||
to Ember 0.9. In Ember 0.9.8.1, the following is perfectly valid: | ||
|
||
```javascript | ||
Ember.Object.create(Ember.Mixin.create(), { | ||
someProperty: function() { return 'some value'; }.property(), | ||
someFunction: function() { return this._super(); } | ||
}); | ||
``` | ||
|
||
In Ember 1.0, that same code throws three exceptions: | ||
|
||
* Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead. | ||
* Ember.Object.create no longer supports defining computed properties. | ||
* Ember.Object.create no longer supports defining methods that call _super. | ||
|
||
This helps those migrating from Ember 0.9 to 1.0 by backporting the new | ||
behavior, conditional on a flag, `ENV.CREATE_WITH_MIXINS`, which | ||
has four possible values: | ||
|
||
* `null` (the default): Ember 0.9.8.1 compatibility; `Ember.Object.create` | ||
accepts `Ember.Mixin`s and `Object`s that contain | ||
`Ember.ComputedProperty`s or `Function`s that call `_super`. | ||
* `"warn"`: Ember 0.9.8.1 compatibility with warnings. | ||
* `"error"`: Ember 1.0 compatibility; `Ember.Object.create` will throw an | ||
exception if passed an `Ember.Mixin` or an object that contains an | ||
`Ember.ComputedProperty` or `Function` that calls `_super`. | ||
|
||
See [issue #2](https://github.com/zendesk/ember.js/issues/2) for more | ||
information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
module("Ember.Object.createWithMixins"); | ||
|
||
test("it exists", function() { | ||
ok(Ember.Object.createWithMixins); | ||
}); | ||
|
||
test("it instantiates objects", function() { | ||
var obj = Ember.Object.createWithMixins({ foo: 'bar' }); | ||
ok(obj); | ||
equal(obj.get('foo'), 'bar'); | ||
}); | ||
|
||
test('it works on subclasses', function() { | ||
var Klass = Ember.Object.extend({ | ||
foo: 'bar' | ||
}); | ||
var obj = Klass.createWithMixins({ foo: 'baz' }); | ||
equal(obj.get('foo'), 'baz'); | ||
}); | ||
|
||
var originalFlag, originalWarn, warnings; | ||
|
||
module("Backported Ember.Object.create", { | ||
setup: function() { | ||
originalFlag = Ember.ENV.CREATE_WITH_MIXINS; | ||
originalWarn = Ember.Logger.warn; | ||
warnings = []; | ||
Ember.Logger.warn = function(msg) { | ||
warnings.push(msg.replace("WARNING: ", "")); | ||
}; | ||
}, | ||
teardown: function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = originalFlag; | ||
Ember.Logger.warn = originalWarn; | ||
} | ||
}); | ||
|
||
test("passing a mixin with warnings off", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = null; | ||
Ember.Object.create(Ember.Mixin.create()); | ||
equal(warnings.length, 0); | ||
}); | ||
|
||
test("passing a mixin with warnings on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'warn'; | ||
|
||
Ember.Object.create(Ember.Mixin.create()); | ||
equal(warnings.length, 1); | ||
equal(warnings[0], "Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead."); | ||
}); | ||
|
||
test("passing a mixin with errors on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'error'; | ||
raises(function() { | ||
Ember.Object.create(Ember.Mixin.create()); | ||
}, "Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead."); | ||
}); | ||
|
||
test("passing computed properties with warnings off", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = null; | ||
|
||
Ember.Object.create({ | ||
aProp: Ember.computed(function() { return 'three'; }) | ||
}); | ||
equal(warnings.length, 0); | ||
}); | ||
|
||
test("passing computed properties with warnings on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'warn'; | ||
|
||
Ember.Object.create({ | ||
aProp: Ember.computed(function() { return 'three'; }) | ||
}); | ||
equal(warnings.length, 1); | ||
equal(warnings[0], "Ember.Object.create no longer supports defining computed properties."); | ||
}); | ||
|
||
test("passing a computed property with errors on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'error'; | ||
raises(function() { | ||
Ember.Object.create({ | ||
aProp: Ember.computed(function() { return 'three'; }) | ||
}); | ||
}, "Ember.Object.create no longer supports defining computed properties."); | ||
}); | ||
|
||
test("passing methods that use _super with warnings off", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = null; | ||
|
||
Ember.Object.create({ | ||
aProp: function() { return this._super(); } | ||
}); | ||
equal(warnings.length, 0); | ||
}); | ||
|
||
test("passing methods that use _super with warnings on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'warn'; | ||
|
||
Ember.Object.create({ | ||
aProp: function() { return this._super(); } | ||
}); | ||
equal(warnings.length, 1); | ||
equal(warnings[0], "Ember.Object.create no longer supports defining methods that call _super."); | ||
}); | ||
|
||
test("passing methods that *don't* use _super with warnings on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'warn'; | ||
|
||
Ember.Object.create({ | ||
aProp: function() { return this._notSuper(); } | ||
}); | ||
equal(warnings.length, 0); | ||
}); | ||
|
||
test("passing methods that use _super with errors on", function() { | ||
Ember.ENV.CREATE_WITH_MIXINS = 'error'; | ||
|
||
raises(function() { | ||
Ember.Object.create({ | ||
aProp: function() { return this._super(); } | ||
}); | ||
}); | ||
}); | ||
|