Create text measurement type

This commit is contained in:
Matthew Dillon 2014-11-26 22:13:46 -09:00
parent 3e0ca9df8c
commit b1dad9bfbd
9 changed files with 154 additions and 3 deletions

View file

@ -1,6 +1,10 @@
package datastore
import "github.com/thermokarst/bactdb/models"
import (
"time"
"github.com/thermokarst/bactdb/models"
)
func init() {
DB.AddTableWithName(models.TextMeasurementType{}, "text_measurement_types").SetKeys(true, "Id")
@ -20,3 +24,13 @@ func (s *textMeasurementTypesStore) Get(id int64) (*models.TextMeasurementType,
}
return text_measurement_type[0], nil
}
func (s *textMeasurementTypesStore) Create(text_measurement_type *models.TextMeasurementType) (bool, error) {
currentTime := time.Now()
text_measurement_type.CreatedAt = currentTime
text_measurement_type.UpdatedAt = currentTime
if err := s.dbh.Insert(text_measurement_type); err != nil {
return false, err
}
return true, nil
}

View file

@ -42,3 +42,23 @@ func TestTextMeasurementTypesStore_Get_db(t *testing.T) {
t.Errorf("got text_measurement_type %+v, want %+v", text_measurement_type, want)
}
}
func TestTextMeasurementTypesStore_Create_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
text_measurement_type := newTextMeasurementType(t, tx)
d := NewDatastore(tx)
created, err := d.TextMeasurementTypes.Create(text_measurement_type)
if err != nil {
t.Fatal(err)
}
if !created {
t.Error("!created")
}
if text_measurement_type.Id == 0 {
t.Error("want nonzero text_measurement_type.Id after submitting")
}
}