Update a text measurement type

This commit is contained in:
Matthew Dillon 2014-11-27 11:34:42 -09:00
parent e368426aad
commit 49621ca27b
9 changed files with 158 additions and 0 deletions

View file

@ -46,3 +46,26 @@ func (s *textMeasurementTypesStore) List(opt *models.TextMeasurementTypeListOpti
}
return text_measurement_types, nil
}
func (s *textMeasurementTypesStore) Update(id int64, text_measurement_type *models.TextMeasurementType) (bool, error) {
_, err := s.Get(id)
if err != nil {
return false, err
}
if id != text_measurement_type.Id {
return false, models.ErrObservationNotFound
}
text_measurement_type.UpdatedAt = time.Now()
changed, err := s.dbh.Update(text_measurement_type)
if err != nil {
return false, err
}
if changed == 0 {
return false, ErrNoRowsUpdated
}
return true, nil
}

View file

@ -85,3 +85,23 @@ func TestTextMeasurementTypesStore_List_db(t *testing.T) {
t.Errorf("got text_measurement_types %+v, want %+v", text_measurement_types, want)
}
}
func TestTextMeasurementTypesStore_Update_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
text_measurement_type := insertTextMeasurementType(t, tx)
d := NewDatastore(tx)
// Tweak it
text_measurement_type.TextMeasurementName = "Updated Text Measurement Type"
updated, err := d.TextMeasurementTypes.Update(text_measurement_type.Id, text_measurement_type)
if err != nil {
t.Fatal(err)
}
if !updated {
t.Error("!updated")
}
}