2016-07-06 08:02:35 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
|
|
|
func {{$varNameSingular}}BeforeCreateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{$varNameSingular}}AfterCreateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{$varNameSingular}}BeforeUpdateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func {{$varNameSingular}}AfterUpdateHook(o *{{$tableNameSingular}}) error {
|
2016-07-15 17:21:09 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
2016-07-06 08:02:35 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test{{$tableNamePlural}}Hooks(t *testing.T) {
|
2016-07-15 17:21:09 +02:00
|
|
|
var err error
|
2016-07-06 08:02:35 +02:00
|
|
|
|
2016-07-15 17:21:09 +02:00
|
|
|
empty := &{{$tableNameSingular}}{}
|
|
|
|
o := &{{$tableNameSingular}}{}
|
|
|
|
|
|
|
|
if err = boil.RandomizeStruct(o, {{$varNameSingular}}DBTypes, false); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{{$tableNameSingular}}AddHook(boil.HookBeforeCreate, {{$varNameSingular}}BeforeCreateHook)
|
|
|
|
if err = o.doBeforeCreateHooks(); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeCreateHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected BeforeCreateHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
|
|
|
|
{{$varNameSingular}}BeforeCreateHooks = []{{$tableNameSingular}}Hook{}
|
2016-07-06 08:02:35 +02:00
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
}
|