Add some tests for Related()

This commit is contained in:
Jinzhu 2014-01-03 18:34:53 +08:00
parent 09c26cb387
commit 84395b435b
1 changed files with 11 additions and 0 deletions

View File

@ -1273,6 +1273,11 @@ func TestRelated(t *testing.T) {
if len(emails) != 2 {
t.Errorf("Should have two emails")
}
var user1 User
db.Model(&user).Related(&user1.Emails)
if len(user1.Emails) != 2 {
t.Errorf("Should have two emails")
}
var address1 Address
db.Model(&user).Related(&address1, "BillingAddressId")
@ -1280,6 +1285,12 @@ func TestRelated(t *testing.T) {
t.Errorf("Should get billing address from user correctly")
}
user1 = User{}
db.Model(&address1).Related(&user1, "BillingAddressId")
if db.NewRecord(user1) {
t.Errorf("Should get user from address correctly")
}
var user2 User
db.Model(&emails[0]).Related(&user2)
if user2.Id != user.Id || user2.Name != user.Name {