Compare commits

...

1 commit

Author SHA1 Message Date
Aaron L
72c68e22de Fix exists
- Add tests for exists
2016-12-19 19:29:11 -08:00
2 changed files with 55 additions and 1 deletions

View file

@ -95,6 +95,15 @@ func test{{$tableNamePlural}}Count(t *testing.T) {
tx := MustTx(boil.Begin()) tx := MustTx(boil.Begin())
defer tx.Rollback() defer tx.Rollback()
count, err := {{$tableNamePlural}}(tx).Count()
if err != nil {
t.Error(err)
}
if count != 0 {
t.Error("want 0 records found")
}
if err = {{$varNameSingular}}One.Insert(tx); err != nil { if err = {{$varNameSingular}}One.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -102,7 +111,7 @@ func test{{$tableNamePlural}}Count(t *testing.T) {
t.Error(err) t.Error(err)
} }
count, err := {{$tableNamePlural}}(tx).Count() count, err = {{$tableNamePlural}}(tx).Count()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -111,3 +120,38 @@ func test{{$tableNamePlural}}Count(t *testing.T) {
t.Error("want 2 records, got:", count) t.Error("want 2 records, got:", count)
} }
} }
func test{{$tableNamePlural}}ExistsFinisher(t *testing.T) {
t.Parallel()
var err error
seed := randomize.NewSeed()
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
if err = randomize.Struct(seed, {{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
}
tx := MustTx(boil.Begin())
defer tx.Rollback()
exists, err := {{$tableNamePlural}}(tx).Exists()
if err != nil {
t.Error(err)
}
if exists {
t.Error("the record should not exist")
}
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
t.Error(err)
}
exists, err = {{$tableNamePlural}}(tx).Exists()
if err != nil {
t.Error(err)
}
if !exists {
t.Error("wanted record to exist")
}
}

View file

@ -105,6 +105,16 @@ func TestCount(t *testing.T) {
{{- end -}} {{- end -}}
} }
func TestExistsFinisher(t *testing.T) {
{{- range $index, $table := .Tables}}
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- $tableName := $table.Name | plural | titleCase -}}
t.Run("{{$tableName}}", test{{$tableName}}ExistsFinisher)
{{end -}}
{{- end -}}
}
{{if not .NoHooks -}} {{if not .NoHooks -}}
func TestHooks(t *testing.T) { func TestHooks(t *testing.T) {
{{- range $index, $table := .Tables}} {{- range $index, $table := .Tables}}