Delete a unit type
This commit is contained in:
parent
76baee1fa7
commit
eccbffb86d
9 changed files with 141 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue