forked from bessfernandez/coherent
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for bi-directional to-one relations
- Loading branch information
1 parent
7aa5a63
commit 600deb2
Showing
4 changed files
with
45 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,53 @@ | ||
describe("Model ToOne relations", function() { | ||
|
||
it("should set inverse relation", function() { | ||
var M1= Model("Model1", { | ||
beforeEach(function(){ | ||
coherent.Model._resetModels(); | ||
|
||
this.M1= Model("Model1", { | ||
m2: Model.ToOne({ | ||
type: "Model2", | ||
inverse: "m1" | ||
}) | ||
}); | ||
|
||
var M2= Model("Model2", { | ||
this.M2= Model("Model2", { | ||
m1: Model.ToOne({ | ||
type: "Model1", | ||
inverse: "m2" | ||
}) | ||
}); | ||
|
||
var m1= new M1(); | ||
var m2= new M2(); | ||
|
||
}); | ||
|
||
it("should set inverse relation via setValueForKey", function() { | ||
var m1= new this.M1(); | ||
var m2= new this.M2(); | ||
|
||
m1.setValueForKey(m2, 'm2'); | ||
expect(m2.m1()).toBe(m1); | ||
}); | ||
|
||
it("should set inverse relation via set method", function() { | ||
var m1= new this.M1(); | ||
var m2= new this.M2(); | ||
|
||
m1.setM2(m2); | ||
expect(m2.m1()).toBe(m1); | ||
}); | ||
|
||
it("should clear previous inverse relation when setting new value", function() { | ||
var m1= new this.M1(); | ||
var m2= new this.M2(); | ||
var m2a= new this.M2(); | ||
|
||
debugger; | ||
m1.setM2(m2); | ||
expect(m2.m1()).toBe(m1); | ||
|
||
m1.setM2(m2a); | ||
expect(m2.m1()).toBeNull(); | ||
expect(m2a.m1()).toBe(m1); | ||
}); | ||
|
||
}); |
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