Delete a unit type

This commit is contained in:
Matthew Dillon 2014-11-30 16:10:38 -09:00
parent 76baee1fa7
commit eccbffb86d
9 changed files with 141 additions and 0 deletions

View file

@ -69,3 +69,19 @@ func (s *unitTypesStore) Update(id int64, unit_type *models.UnitType) (bool, err
return true, nil
}
func (s *unitTypesStore) Delete(id int64) (bool, error) {
unit_type, err := s.Get(id)
if err != nil {
return false, err
}
deleted, err := s.dbh.Delete(unit_type)
if err != nil {
return false, err
}
if deleted == 0 {
return false, ErrNoRowsDeleted
}
return true, nil
}

View file

@ -105,3 +105,22 @@ func TestUnitTypesStore_Update_db(t *testing.T) {
t.Error("!updated")
}
}
func TestUnitTypesStore_Delete_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
unit_type := insertUnitType(t, tx)
d := NewDatastore(tx)
// Delete it
deleted, err := d.UnitTypes.Delete(unit_type.Id)
if err != nil {
t.Fatal(err)
}
if !deleted {
t.Error("!delete")
}
}