diff --git a/package.json b/package.json
index ef08c8e..743e7ee 100644
--- a/package.json
+++ b/package.json
@@ -26,13 +26,13 @@
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
- "ember-cli-pretender": "^0.3.1",
+ "ember-cli-pretender": "0.3.1",
"ember-cli-qunit": "0.3.10",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.16.1",
"ember-export-application-global": "^1.0.2",
- "ember-try": "0.0.4",
- "ember-sinon": "0.0.3"
+ "ember-sinon": "0.0.3",
+ "ember-try": "0.0.4"
},
"keywords": [
"adapter",
diff --git a/tests/acceptance/crud-failure-test.js b/tests/acceptance/crud-failure-test.js
index 6e1c4eb..6c53481 100644
--- a/tests/acceptance/crud-failure-test.js
+++ b/tests/acceptance/crud-failure-test.js
@@ -4,7 +4,7 @@ import {
test,
} from 'qunit';
import Pretender from 'pretender';
-import startApp from 'ember-django-adapter/tests/helpers/start-app';
+import startApp from 'dummy/tests/helpers/start-app';
var application;
var store;
@@ -62,20 +62,14 @@ module('Acceptance: CRUD Failure', {
}
});
-/*
- * These integration tests need to use the QUnit.stop() / QUnit.start()
- * pattern as described in the following stackoverflow question:
- *
- * https://stackoverflow.com/questions/26317855/ember-cli-how-to-do-asynchronous-model-unit-testing-with-restadapter
- */
test('Permission denied error', function(assert) {
assert.expect(4);
- stop();
- Ember.run(function() {
- store.find('post', 1).then({}, function(response) {
+ return Ember.run(function() {
+
+ return store.find('post', 1).then({}, function(response) {
+
assert.ok(response);
- start();
assert.equal(response.status, 401);
assert.equal(response.statusText, 'Unauthorized');
assert.equal(response.responseText, JSON.stringify({detail: 'Authentication credentials were not provided.'}));
@@ -86,11 +80,11 @@ test('Permission denied error', function(assert) {
test('Server error', function(assert) {
assert.expect(4);
- stop();
- Ember.run(function() {
- store.find('post', 2).then({}, function(response) {
+ return Ember.run(function() {
+
+ return store.find('post', 2).then({}, function(response) {
+
assert.ok(response);
- start();
assert.equal(response.status, 500);
assert.equal(response.statusText, 'Internal Server Error');
assert.equal(response.responseText, '
Server Error (500)
');
@@ -101,27 +95,25 @@ test('Server error', function(assert) {
test('Create field errors', function(assert) {
assert.expect(6);
- var record,
- data = {postTitle: '', body: ''};
+ return Ember.run(function() {
+
+ var post = store.createRecord('post', {
+ postTitle: '',
+ body: ''
+ });
+
+ return post.save().then({}, function(response) {
- stop();
- Ember.run(function() {
- record = store.createRecord('post', data);
- record.save().then({}, function(response) {
assert.ok(response);
assert.ok(response.errors);
- var errors = response.errors;
-
// Test camelCase field.
- assert.equal(errors.postTitle.length, 1);
- assert.equal(errors.postTitle[0], 'This field is required.');
+ assert.equal(response.errors.postTitle.length, 1);
+ assert.equal(response.errors.postTitle[0], 'This field is required.');
// Test non-camelCase field.
- assert.equal(errors.body.length, 1);
- assert.equal(errors.body[0], 'This field is required.');
-
- start();
+ assert.equal(response.errors.body.length, 1);
+ assert.equal(response.errors.body[0], 'This field is required.');
});
});
});
@@ -129,31 +121,28 @@ test('Create field errors', function(assert) {
test('Update field errors', function(assert) {
assert.expect(9);
- stop();
- Ember.run(function() {
- store.find('post', 3).then(function(response) {
- assert.ok(response);
+ return Ember.run(function() {
+
+ return store.find('post', 3).then(function(post) {
- assert.equal(response.get('isDirty'), false);
- response.set('postTitle', 'Lorem ipsum dolor sit amet, consectetur adipiscing el');
- response.set('body', '');
- assert.equal(response.get('isDirty'), true);
+ assert.ok(post);
+ assert.equal(post.get('isDirty'), false);
+ post.set('postTitle', 'Lorem ipsum dolor sit amet, consectetur adipiscing el');
+ post.set('body', '');
+ assert.equal(post.get('isDirty'), true);
- response.save().then({}, function(updateResponse) {
- assert.ok(updateResponse);
- assert.ok(updateResponse.errors);
+ post.save().then({}, function(response) {
- var errors = updateResponse.errors;
+ assert.ok(response);
+ assert.ok(response.errors);
// Test camelCase field.
- assert.equal(errors.postTitle.length, 1);
- assert.equal(errors.postTitle[0], 'Ensure this value has at most 50 characters (it has 53).');
+ assert.equal(response.errors.postTitle.length, 1);
+ assert.equal(response.errors.postTitle[0], 'Ensure this value has at most 50 characters (it has 53).');
// Test non-camelCase field.
- assert.equal(errors.body.length, 1);
- assert.equal(errors.body[0], 'This field is required.');
-
- start();
+ assert.equal(response.errors.body.length, 1);
+ assert.equal(response.errors.body[0], 'This field is required.');
});
});
});
diff --git a/tests/acceptance/crud-success-test.js b/tests/acceptance/crud-success-test.js
index 259086d..49c06ec 100644
--- a/tests/acceptance/crud-success-test.js
+++ b/tests/acceptance/crud-success-test.js
@@ -4,7 +4,7 @@ import {
test
} from 'qunit';
import Pretender from 'pretender';
-import startApp from 'ember-django-adapter/tests/helpers/start-app';
+import startApp from 'dummy/tests/helpers/start-app';
var application;
var store;
@@ -75,43 +75,31 @@ module('Acceptance: CRUD Success', {
}
});
-/*
- * These integration tests need to use the QUnit.stop() / QUnit.start()
- * pattern as described in the following stackoverflow question:
- *
- * https://stackoverflow.com/questions/26317855/ember-cli-how-to-do-asynchronous-model-unit-testing-with-restadapter
- */
test('Retrieve list of non-paginated records', function(assert) {
assert.expect(4);
- stop();
- Ember.run(function() {
- store.find('post').then(function(response) {
- assert.ok(response);
+ return store.find('post').then(function(posts) {
- assert.equal(response.get('length'), 3);
+ assert.ok(posts);
+ assert.equal(posts.get('length'), 3);
- var post = response.objectAt(2);
- assert.equal(post.get('postTitle'), 'post title 3');
- assert.equal(post.get('body'), 'post body 3');
+ var post = posts.objectAt(2);
- start();
- });
+ assert.equal(post.get('postTitle'), 'post title 3');
+ assert.equal(post.get('body'), 'post body 3');
});
});
test('Retrieve single record', function(assert) {
assert.expect(3);
- stop();
- Ember.run(function() {
- store.find('post', 1).then(function(response) {
- assert.ok(response);
+ return Ember.run(function() {
- assert.equal(response.get('postTitle'), 'post title 1');
- assert.equal(response.get('body'), 'post body 1');
+ return store.find('post', 1).then(function(post) {
- start();
+ assert.ok(post);
+ assert.equal(post.get('postTitle'), 'post title 1');
+ assert.equal(post.get('body'), 'post body 1');
});
});
});
@@ -119,20 +107,19 @@ test('Retrieve single record', function(assert) {
test('Create record', function(assert) {
assert.expect(4);
- var record,
- data = {postTitle: 'post title 4', body: 'post body 4'};
+ return Ember.run(function() {
- stop();
- Ember.run(function() {
- record = store.createRecord('post', data);
- record.save().then(function(response) {
- assert.ok(response);
+ var post = store.createRecord('post', {
+ postTitle: 'my new post title',
+ body: 'my new post body'
+ });
- assert.equal(response.get('id'), 4);
- assert.equal(response.get('title'), data['title']);
- assert.equal(response.get('body'), data['body']);
+ return post.save().then(function(post) {
- start();
+ assert.ok(post);
+ assert.equal(post.get('id'), 4);
+ assert.equal(post.get('postTitle'), 'my new post title');
+ assert.equal(post.get('body'), 'my new post body');
});
});
});
@@ -140,27 +127,26 @@ test('Create record', function(assert) {
test('Update record', function(assert) {
assert.expect(7);
- var postTitleUpdate = 'updated post title 1',
- bodyUpdate = 'updated post body 1';
+ return Ember.run(function() {
+
+ return store.find('post', 1).then(function(post) {
- stop();
- Ember.run(function() {
- store.find('post', 1).then(function(response) {
- assert.ok(response);
+ assert.ok(post);
+ assert.equal(post.get('isDirty'), false);
- assert.equal(response.get('isDirty'), false);
- response.set('postTitle', postTitleUpdate);
- response.set('body', bodyUpdate);
- assert.equal(response.get('isDirty'), true);
+ return Ember.run(function() {
- response.save().then(function(updateResponse) {
- assert.ok(updateResponse);
+ post.set('postTitle', 'new post title');
+ post.set('body', 'new post body');
+ assert.equal(post.get('isDirty'), true);
- assert.equal(updateResponse.get('isDirty'), false);
- assert.equal(updateResponse.get('postTitle'), postTitleUpdate);
- assert.equal(updateResponse.get('body'), bodyUpdate);
+ return post.save().then(function(post) {
- start();
+ assert.ok(post);
+ assert.equal(post.get('isDirty'), false);
+ assert.equal(post.get('postTitle'), 'new post title');
+ assert.equal(post.get('body'), 'new post body');
+ });
});
});
});
@@ -169,15 +155,15 @@ test('Update record', function(assert) {
test('Delete record', function(assert) {
assert.expect(2);
- stop();
- Ember.run(function() {
- store.find('post', 1).then(function(response) {
- assert.ok(response);
+ return Ember.run(function() {
+
+ return store.find('post', 1).then(function(post) {
+
+ assert.ok(post);
- response.destroyRecord().then(function(deleteResponse) {
- assert.ok(deleteResponse);
+ return post.destroyRecord().then(function(post) {
- start();
+ assert.ok(post);
});
});
});
diff --git a/tests/acceptance/pagination-test.js b/tests/acceptance/pagination-test.js
index b5e6d22..437949b 100644
--- a/tests/acceptance/pagination-test.js
+++ b/tests/acceptance/pagination-test.js
@@ -4,7 +4,7 @@ import {
test
} from 'qunit';
import Pretender from 'pretender';
-import startApp from 'ember-django-adapter/tests/helpers/start-app';
+import startApp from 'dummy/tests/helpers/start-app';
var application;
var store;
@@ -110,38 +110,27 @@ module('Acceptance: Pagination', {
}
});
-/*
- * These integration tests need to use the QUnit.stop() / QUnit.start()
- * pattern as described in the following stackoverflow question:
- *
- * https://stackoverflow.com/questions/26317855/ember-cli-how-to-do-asynchronous-model-unit-testing-with-restadapter
- */
test('Retrieve list of paginated records', function(assert) {
assert.expect(8);
- stop();
- Ember.run(function() {
- store.find('post').then(function(response) {
- assert.ok(response);
+ return store.find('post').then(function(response) {
+ assert.ok(response);
- assert.equal(response.get('length'), 4);
+ assert.equal(response.get('length'), 4);
- // Test the camelCase and non-camelCase fields of a paginated result.
- var post = response.objectAt(1);
- assert.equal(post.get('postTitle'), 'post title 2');
- assert.equal(post.get('body'), 'post body 2');
+ // Test the camelCase and non-camelCase fields of a paginated result.
+ var post = response.objectAt(1);
+ assert.equal(post.get('postTitle'), 'post title 2');
+ assert.equal(post.get('body'), 'post body 2');
- // Test the type metadata.
- var metadata = store.metadataFor('post');
- assert.equal(metadata.count, 6);
- assert.equal(metadata.next, 2);
- assert.equal(metadata.previous, null);
+ // Test the type metadata.
+ var metadata = store.metadataFor('post');
+ assert.equal(metadata.count, 6);
+ assert.equal(metadata.next, 2);
+ assert.equal(metadata.previous, null);
- // No metadata on results when using find without query params.
- assert.ok(!response.get('meta'));
-
- start();
- });
+ // No metadata on results when using find without query params.
+ assert.ok(!response.get('meta'));
});
});
@@ -149,22 +138,17 @@ test('Retrieve list of paginated records', function(assert) {
test("Type metadata doesn't have previous", function(assert) {
assert.expect(5);
- stop();
- Ember.run(function() {
- store.find('post').then(function(response) {
- assert.ok(response);
-
- // Test the type metadata.
- var metadata = store.metadataFor('post');
- assert.equal(metadata.count, 6);
- assert.equal(metadata.next, 2);
- assert.equal(metadata.previous, null);
+ return store.find('post').then(function(response) {
+ assert.ok(response);
- // No metadata on results when using find without query params.
- assert.ok(!response.get('meta'));
+ // Test the type metadata.
+ var metadata = store.metadataFor('post');
+ assert.equal(metadata.count, 6);
+ assert.equal(metadata.next, 2);
+ assert.equal(metadata.previous, null);
- start();
- });
+ // No metadata on results when using find without query params.
+ assert.ok(!response.get('meta'));
});
});
@@ -172,26 +156,21 @@ test("Type metadata doesn't have previous", function(assert) {
test("Type metadata doesn't have next", function(assert) {
assert.expect(8);
- stop();
- Ember.run(function() {
- store.find('post', {page: 2}).then(function(response) {
- assert.ok(response);
- assert.equal(response.get('length'), 2);
-
- // Test the type metadata.
- var typeMetadata = store.metadataFor('post');
- assert.equal(typeMetadata.count, 6);
- assert.equal(typeMetadata.next, null);
- assert.equal(typeMetadata.previous, 1);
-
- // Test the results metadata.
- var resultsMetadata = response.get('meta');
- assert.equal(resultsMetadata.count, 6);
- assert.equal(resultsMetadata.next, null);
- assert.equal(resultsMetadata.previous, 1);
-
- start();
- });
+ return store.find('post', {page: 2}).then(function(response) {
+ assert.ok(response);
+ assert.equal(response.get('length'), 2);
+
+ // Test the type metadata.
+ var typeMetadata = store.metadataFor('post');
+ assert.equal(typeMetadata.count, 6);
+ assert.equal(typeMetadata.next, null);
+ assert.equal(typeMetadata.previous, 1);
+
+ // Test the results metadata.
+ var resultsMetadata = response.get('meta');
+ assert.equal(resultsMetadata.count, 6);
+ assert.equal(resultsMetadata.next, null);
+ assert.equal(resultsMetadata.previous, 1);
});
});
@@ -199,25 +178,20 @@ test("Type metadata doesn't have next", function(assert) {
test("Test page_size query param", function(assert) {
assert.expect(8);
- stop();
- Ember.run(function() {
- store.find('post', {page: 2, page_size: 2}).then(function(response) {
- assert.ok(response);
- assert.equal(response.get('length'), 2);
-
- // Test the type metadata.
- var typeMetadata = store.metadataFor('post');
- assert.equal(typeMetadata.count, 6);
- assert.equal(typeMetadata.previous, 1);
- assert.equal(typeMetadata.next, 3);
-
- // Test the results metadata.
- var resultsMetadata = response.get('meta');
- assert.equal(resultsMetadata.count, 6);
- assert.equal(resultsMetadata.previous, 1);
- assert.equal(resultsMetadata.next, 3);
-
- start();
- });
+ return store.find('post', {page: 2, page_size: 2}).then(function(response) {
+ assert.ok(response);
+ assert.equal(response.get('length'), 2);
+
+ // Test the type metadata.
+ var typeMetadata = store.metadataFor('post');
+ assert.equal(typeMetadata.count, 6);
+ assert.equal(typeMetadata.previous, 1);
+ assert.equal(typeMetadata.next, 3);
+
+ // Test the results metadata.
+ var resultsMetadata = response.get('meta');
+ assert.equal(resultsMetadata.count, 6);
+ assert.equal(resultsMetadata.previous, 1);
+ assert.equal(resultsMetadata.next, 3);
});
});
diff --git a/tests/unit/serializers/drf-test.js b/tests/unit/serializers/drf-test.js
index 53d6eb5..685c766 100644
--- a/tests/unit/serializers/drf-test.js
+++ b/tests/unit/serializers/drf-test.js
@@ -79,7 +79,7 @@ test('keyForRelationship', function(assert) {
test('extractMeta', function(assert) {
var serializer = this.subject();
- var store = { metaForType: sinon.spy() };
+ var store = { setMetadataFor: sinon.spy() };
var payload = {
results: 'mock',
count: 'count',
@@ -89,7 +89,7 @@ test('extractMeta', function(assert) {
serializer.extractMeta(store, 'type', payload);
- assert.ok(store.metaForType.calledWith('type', {count: 'count', next: 3, previous: 1}),
+ assert.ok(store.setMetadataFor.calledWith('type', {count: 'count', next: 3, previous: 1}),
'metaForType not called properly');
assert.ok(!payload.count, 'payload.count not removed');
assert.ok(!payload.next, 'payload.next not removed');