Navigation Menu

Skip to content

Commit

Permalink
Adds test to show behaviour described in #2
Browse files Browse the repository at this point in the history
  • Loading branch information
blackjid committed Oct 8, 2013
1 parent cd21f15 commit 7c792de
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions test/instanceSpec.js
Expand Up @@ -2,26 +2,31 @@

describe('Restmod model instance:', function() {

var $httpBackend, Book, Chapter;
var $httpBackend, Book, Chapter, Page;

beforeEach(module('plRestmod'));

// generate a dummy module
beforeEach(module(function($provide) {
$provide.factory('Book', function($restmod) {
return $restmod('/api/books', { chapters: { hasMany: 'Chapter' } });
return $restmod('/api/books', { chapters: { hasMany: 'Chapter' }, pages: { hasMany: 'Page'} });
});

$provide.factory('Chapter', function($restmod) {
return $restmod('/api/chapters');
});

$provide.factory('Page', function($restmod) {
return $restmod(null);
});
}));

// cache entities to be used in tests
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
Book = $injector.get('Book');
Chapter = $injector.get('Chapter');
Page = $injector.get('Page');
}));

describe('hasMany relation', function() {
Expand Down Expand Up @@ -54,6 +59,22 @@ describe('Restmod model instance:', function() {

});

describe('when retrieving inlined relation data with null url', function() {

beforeEach(function() {
$httpBackend.when('GET', '/api/books/1').respond(200, '{"id": 1, "chapters": [{"id": 2}], "pages": [{"id": 1}]}');
});

it('should load inline data into relation', function() {
var book = Book.$find(1);
$httpBackend.flush();
expect(book.pages.length).toEqual(1);
expect(book.pages[0] instanceof Page).toBeTruthy();
expect(book.pages[0].$url()).toBeNull();
});

});

});

});
Expand Down

0 comments on commit 7c792de

Please sign in to comment.