Skip to content

Commit

Permalink
Add tests for urlFor methods. Resolves emberjs#2966
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds committed Apr 17, 2015
1 parent ab93c00 commit 0a8dff1
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,102 @@ test('pathForType - works with underscored types', function() {
test('buildURL - works with empty paths', function() {
equal(adapter.buildURL('rootModel', 1), "/1");
});

test('buildURL - find requestType delegates to urlForFind', function() {
expect(4);
var snapshotStub = { snapshot: true };
var originalMethod = adapter.urlForFind;
adapter.urlForFind = function(id, type, snapshot) {
equal(id, 1);
equal(type, 'super-user');
equal(snapshot, snapshotStub);
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', 1, snapshotStub, 'find'), '/superUsers/1');
});

test('buildURL - findAll requestType delegates to urlForFindAll', function() {
expect(2);
var originalMethod = adapter.urlForFindAll;
adapter.urlForFindAll = function(type) {
equal(type, 'super-user');
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', null, null, 'findAll'), '/superUsers');
});

test('buildURL - findQuery requestType delegates to urlForFindQuery', function() {
expect(3);
var originalMethod = adapter.urlForFindQuery;
var queryStub = { limit: 10 };
adapter.urlForFindQuery = function(query, type) {
equal(query, queryStub);
equal(type, 'super-user');
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', queryStub, null, 'findQuery'), '/superUsers');
});

test('buildURL - findMany requestType delegates to urlForFindMany', function() {
expect(3);
var originalMethod = adapter.urlForFindMany;
var idsStub = [1, 2, 3];
adapter.urlForFindMany = function(ids, type) {
equal(ids, idsStub);
equal(type, 'super-user');
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', idsStub, null, 'findMany'), '/superUsers');
});

test('buildURL - findHasMany requestType delegates to urlForFindHasMany', function() {
expect(3);
var originalMethod = adapter.urlForFindHasMany;
adapter.urlForFindHasMany = function(id, type) {
equal(id, 1);
equal(type, 'super-user');
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', 1, null, 'findHasMany'), '/superUsers/1');
});

test('buildURL - findBelongsTo requestType delegates to urlForFindBelongsTo', function() {
expect(3);
var originalMethod = adapter.urlForFindBelongsTo;
adapter.urlForFindBelongsTo = function(id, type) {
equal(id, 1);
equal(type, 'super-user');
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', 1, null, 'findBelongsTo'), '/superUsers/1');
});

test('buildURL - createRecord requestType delegates to urlForFindBelongsTo', function() {
expect(3);
var snapshotStub = { snapshot: true };
var originalMethod = adapter.urlForCreateRecord;
adapter.urlForCreateRecord = function(type, snapshot) {
equal(type, 'super-user');
equal(snapshot, snapshotStub);
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', null, snapshotStub, 'createRecord'), '/superUsers');
});

test('buildURL - deleteRecord requestType delegates to urlForDeleteRecord', function() {
expect(4);
var snapshotStub = { snapshot: true };
var originalMethod = adapter.urlForDeleteRecord;
adapter.urlForDeleteRecord = function(id, type, snapshot) {
equal(id, 1);
equal(type, 'super-user');
equal(snapshot, snapshotStub);
return originalMethod.apply(this, arguments);
};
equal(adapter.buildURL('super-user', 1, snapshotStub, 'deleteRecord'), '/superUsers/1');
});

test('buildURL - unknown requestType', function() {
equal(adapter.buildURL('super-user', 1, null, 'unknown'), '/superUsers/1');
equal(adapter.buildURL('super-user', null, null, 'unknown'), '/superUsers');
});

0 comments on commit 0a8dff1

Please sign in to comment.