Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Scott Burch
committed
Feb 1, 2012
1 parent
d9e6229
commit 4958f84
Showing
6 changed files
with
122 additions
and
3 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var domain = require('couch-ar'); | ||
var domain; | ||
|
||
describe('hasMany', function() { | ||
|
||
|
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,83 @@ | ||
var ar = require('couch-ar'); | ||
|
||
describe('hasMany', function() { | ||
|
||
var user, phoneNumber; | ||
|
||
beforeEach(function() { | ||
ar = require('couch-ar'); | ||
|
||
if(ar.TestUser === undefined) { | ||
ar.init({ | ||
dbName:'couch-ar-test', | ||
root:__dirname + '/../' + 'testDomain' | ||
} | ||
); | ||
waitsFor(function() { | ||
return ar.TestUser; | ||
}); | ||
} | ||
|
||
runs(function() { | ||
user = ar.TestUser.create({}); | ||
phoneNumber = ar.PhoneNumber.create({id:'pn1'}); | ||
}); | ||
}); | ||
|
||
describe('hasOne setter', function() { | ||
it('should set the id of the new entity to the id property', function() { | ||
user.setHomePhoneNumber(phoneNumber); | ||
expect(user.homePhoneNumberId).toBe('pn1'); | ||
}); | ||
|
||
it('will throw exception if you are setting something that is not persisted', function() { | ||
phoneNumber.id = undefined; | ||
expect(function() {user.setHomePhoneNumber(phoneNumber)}).toThrow('Can not set non-persisted entity to hasOne'); | ||
}); | ||
|
||
it('allows you to set undefined', function() { | ||
user.setHomePhoneNumber(undefined); | ||
var callback = jasmine.createSpy(); | ||
user.getHomePhoneNumber(callback); | ||
expect(callback).toHaveBeenCalledWith(undefined); | ||
|
||
}); | ||
}); | ||
|
||
describe('hasOne getter', function() { | ||
|
||
beforeEach(function() { | ||
var cb = jasmine.createSpy(); | ||
phoneNumber.save(cb); | ||
waitsFor(function() { | ||
return cb.callCount; | ||
}); | ||
}); | ||
|
||
it('will get entity that is set', function() { | ||
var callback = jasmine.createSpy(); | ||
runs(function() { | ||
user.setHomePhoneNumber(phoneNumber); | ||
user.getHomePhoneNumber(callback); | ||
}); | ||
waitsFor(function() { | ||
return callback.callCount; | ||
}); | ||
runs(function() { | ||
var phoneNumber = callback.argsForCall[0][0]; | ||
expect(phoneNumber.id).toBe('pn1'); | ||
}); | ||
}); | ||
|
||
it('returns undefined if entity is not set', function() { | ||
var callback = jasmine.createSpy(); | ||
expect(user.getHomePhoneNumber(callback)); | ||
waitsFor(function() { | ||
return callback.callCount; | ||
}); | ||
runs(function() { | ||
expect(callback).toHaveBeenCalledWith(undefined); | ||
}); | ||
}); | ||
}); | ||
}); |
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