diff --git a/Brocfile.js b/Brocfile.js index ab03da8cd..40c178ce8 100644 --- a/Brocfile.js +++ b/Brocfile.js @@ -43,10 +43,17 @@ var vendor = concat('bower_components', { inputFiles: ['jquery/dist/jquery.js', 'ember/ember-template-compiler.js', 'ember/ember.debug.js', - 'ember-data/ember-data.js'], + 'ember-data/ember-data.js', + 'FakeXMLHttpRequest/fake_xml_http_request.js', + 'route-recognizer/dist/route-recognizer.js', + 'pretender/pretender.js'], outputFile: '/assets/vendor.js' }); +var pretender = pickFiles('bower_components', { + +}); + var qunit = pickFiles('bower_components', { srcDir: '/qunit/qunit', files: ['qunit.js', 'qunit.css'], diff --git a/bower.json b/bower.json index 91f5bc5b5..55b61272e 100644 --- a/bower.json +++ b/bower.json @@ -25,14 +25,15 @@ ], "dependencies": { "klassy": "cerebris/klassy.js#0.1.0", - "ember": "^1.13.0" + "ember": "^1.13.0", + "ember-data": "canary", + "pretender": "^0.7.0" }, "devDependencies": { "qunit": "^1.15.0", "loader.js": "ember-cli/loader.js#3.0.0", "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", "ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", - "jquery": "~2.1.1", - "ember-data": "~1.0.0-beta.19.2" + "jquery": "~2.1.1" } -} \ No newline at end of file +} diff --git a/config/ember-try.js b/config/ember-try.js index 4c88c0355..7e85fa328 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -3,13 +3,21 @@ module.exports = { { name: 'ember-1.11.3', dependencies: { - "ember": "1.11.3" + "ember": "1.11.3", + "ember-data": "~1.0.0-beta.19.2" } }, { name: 'ember-1.12.1', dependencies: { - "ember": "1.12.1" + "ember": "1.12.1", + "ember-data": "~1.0.0-beta.19.2" + } + }, + { + name: 'ember-1.13.5', + dependencies: { + "ember": "1.13.5" } }, { diff --git a/lib/ember-test-helpers/build-registry.js b/lib/ember-test-helpers/build-registry.js index d98ef036a..2fddf5a9f 100644 --- a/lib/ember-test-helpers/build-registry.js +++ b/lib/ember-test-helpers/build-registry.js @@ -52,8 +52,18 @@ export default function(resolver) { // Ember 1.10.0 did not properly add `view:toplevel` or `view:default` // to the registry in Ember.Application.buildRegistry :( - register('view:toplevel', Ember.View.extend()); - register('view:default', Ember._MetamorphView); + // + // Ember 2.0.0 removed Ember.View as public API, so only do this when + // Ember.View is present + if (Ember.View) { + register('view:toplevel', Ember.View.extend()); + } + + // Ember 2.0.0 removed Ember._MetamorphView from the Ember global, so only + // do this when present + if (Ember._MetamorphView) { + register('view:default', Ember._MetamorphView); + } var globalContext = typeof global === 'object' && global || self; if (globalContext.DS) { diff --git a/lib/ember-test-helpers/test-module-for-component.js b/lib/ember-test-helpers/test-module-for-component.js index 8e690177e..4318a2410 100644 --- a/lib/ember-test-helpers/test-module-for-component.js +++ b/lib/ember-test-helpers/test-module-for-component.js @@ -63,16 +63,16 @@ export default TestModule.extend({ context.dispatcher.setup({}, '#ember-testing'); this.callbacks.render = function() { - var containerView = Ember.ContainerView.create({container: container}); + var subject; + Ember.run(function(){ - var subject = context.subject(); - containerView.pushObject(subject); - containerView.appendTo('#ember-testing'); + subject = context.subject(); + subject.appendTo('#ember-testing'); }); _this.teardownSteps.unshift(function() { Ember.run(function() { - Ember.tryInvoke(containerView, 'destroy'); + Ember.tryInvoke(subject, 'destroy'); }); }); }; diff --git a/lib/ember-test-helpers/test-module-for-model.js b/lib/ember-test-helpers/test-module-for-model.js index 5942eb7af..178067bf5 100644 --- a/lib/ember-test-helpers/test-module-for-model.js +++ b/lib/ember-test-helpers/test-module-for-model.js @@ -18,7 +18,8 @@ export default TestModule.extend({ var adapterFactory = container.lookupFactory('adapter:application'); if (!adapterFactory) { - container.register('adapter:application', DS.FixtureAdapter); + adapterFactory = DS.JSONAPIAdapter || DS.FixtureAdapter; + container.register('adapter:application', adapterFactory); } callbacks.store = function(){ diff --git a/lib/ember-test-helpers/test-module.js b/lib/ember-test-helpers/test-module.js index 77acd0fcc..11ecf546e 100644 --- a/lib/ember-test-helpers/test-module.js +++ b/lib/ember-test-helpers/test-module.js @@ -178,7 +178,12 @@ export default Klass.extend({ teardownTestElements: function() { Ember.$('#ember-testing').empty(); - Ember.View.views = {}; + + // Ember 2.0.0 removed Ember.View as public API, so only do this when + // Ember.View is present + if (Ember.View) { + Ember.View.views = {}; + } }, defaultSubject: function(options, factory) { diff --git a/package.json b/package.json index be08b317d..93479c8e8 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "broccoli-static-compiler": "^0.1.4", "ember-cli": "^0.2.7", "ember-cli-release": "^0.2.4", - "ember-try": "0.0.5", + "ember-try": "0.0.7", "testem": "^0.6.19" } } diff --git a/tests/test-module-for-component-test.js b/tests/test-module-for-component-test.js index 7f173eacd..de1318f9f 100644 --- a/tests/test-module-for-component-test.js +++ b/tests/test-module-for-component-test.js @@ -17,7 +17,7 @@ var PrettyColor = Ember.Component.extend({ }.property('name') }); -var ColorController = Ember.ObjectController.extend({ +var ColorController = Ember.Controller.extend({ hexa: function() { switch( this.get('model') ) { case 'red': @@ -239,16 +239,28 @@ test('it allows missing callbacks', function() { ok(true, 'no errors are thrown'); }); -moduleForComponent('x-bad', { - needs: ['mis:sing'], - beforeEach: function(assert) { - // won't be called because of setup error - var done = assert.async(); - assert.ok(true); - done(); - } +module('moduleForComponent: handles errors thrown during setup', { + beforeEach: function(assert) { + var done = assert.async(); + testModule = new TestModuleForComponent('x-bad', { + needs: ['mis:sing'], + + beforeEach: function(assert) { + // won't be called because of setup error + var done = assert.async(); + assert.ok(true); + done(); + } + }); + + testModule.setup() + .catch(function(error) { + ok(error.message.indexOf('mis:sing') > -1, 'correct error was thrown from module setup'); + }) + .finally(done); + } }); test('it happens', function() { - expect(0); + ok(true, 'errors are properly thrown/handled'); }); diff --git a/tests/test-module-for-model-test.js b/tests/test-module-for-model-test.js index a0915a2f5..5e2ed582b 100644 --- a/tests/test-module-for-model-test.js +++ b/tests/test-module-for-model-test.js @@ -8,16 +8,20 @@ function moduleForModel(name, description, callbacks) { qunitModuleFor(module); } +var server; + +var adapter = DS.JSONAPIAdapter || DS.FixtureAdapter; + var Whazzit = DS.Model.extend({ gear: DS.attr('string') }); var whazzitAdapterFindAllCalled = false; -var WhazzitAdapter = DS.FixtureAdapter.extend({ +var WhazzitAdapter = adapter.extend({ findAll: function(store, type) { whazzitAdapterFindAllCalled = true; return this._super.apply(this, arguments); } }); -var ApplicationAdapter = DS.FixtureAdapter.extend(); +var ApplicationAdapter = adapter.extend(); function setupRegistry() { setResolverRegistry({ @@ -66,11 +70,11 @@ test('model exists as subject', function() { ok(model instanceof Whazzit); }); -test('FixtureAdapter is registered for model', function() { +test('JSONAPIAdapter (ED >= 2) or FixtureAdapter (ED < 2) is registered for model', function() { var model = this.subject(), store = this.store(); - ok(store.adapterFor(model.constructor) instanceof DS.FixtureAdapter); + ok(store.adapterFor(model.constructor) instanceof adapter); ok(!(store.adapterFor(model.constructor) instanceof WhazzitAdapter)); }); @@ -101,7 +105,22 @@ moduleForModel('whazzit', 'model:whazzit with custom adapter', { setup: function() { Whazzit.FIXTURES = []; + + if (DS.JSONAPIAdapter && adapter === DS.JSONAPIAdapter) { + server = new Pretender(function() { + this.get('/whazzits', function(request) { + return [200, {"Content-Type": "application/json"}, JSON.stringify({ data: Whazzit.FIXTURES })]; + }); + }); + } + whazzitAdapterFindAllCalled = false; + }, + + teardown: function() { + if (DS.JSONAPIAdapter && adapter === DS.JSONAPIAdapter) { + server.shutdown(); + } } }); @@ -112,14 +131,14 @@ test('WhazzitAdapter is registered for model', function() { ok(store.adapterFor(model.constructor) instanceof WhazzitAdapter); }); -test('WhazzitAdapter is used for `find`', function() { +test('WhazzitAdapter is used for `findAll`', function() { expect(2); ok(!whazzitAdapterFindAllCalled, 'precond - custom adapter has not yet been called'); var store = this.store(); return Ember.run(function() { - return store.find('whazzit').then(function() { + return store.findAll('whazzit', { reload: true }).then(function() { ok(whazzitAdapterFindAllCalled, 'uses the custom adapter'); }); });