forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
belongs_to_test.go
50 lines (37 loc) · 1.11 KB
/
belongs_to_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package pop
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func Test_BelongsTo(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)
q := PDB.BelongsTo(&User{ID: 1})
m := NewModel(new(Enemy), context.Background())
sql, _ := q.ToSQL(m)
r.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE user_id = ?"), sql)
}
func Test_BelongsToAs(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)
q := PDB.BelongsToAs(&User{ID: 1}, "u_id")
m := NewModel(new(Enemy), context.Background())
sql, _ := q.ToSQL(m)
r.Equal(ts("SELECT enemies.A FROM enemies AS enemies WHERE u_id = ?"), sql)
}
func Test_BelongsToThrough(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
r := require.New(t)
q := PDB.BelongsToThrough(&User{ID: 1}, &Friend{})
qs := "SELECT enemies.A FROM enemies AS enemies, good_friends AS good_friends WHERE good_friends.user_id = ? AND enemies.id = good_friends.enemy_id"
m := NewModel(new(Enemy), context.Background())
sql, _ := q.ToSQL(m)
r.Equal(ts(qs), sql)
}