Create a strain.

This commit is contained in:
Matthew Dillon 2014-10-29 13:09:54 -08:00
parent 6c118f47f7
commit 6bba9058aa
9 changed files with 146 additions and 2 deletions

View file

@ -20,3 +20,10 @@ func (s *strainsStore) Get(id int64) (*models.Strain, error) {
}
return strain[0], nil
}
func (s *strainsStore) Create(strain *models.Strain) (bool, error) {
if err := s.dbh.Insert(strain); err != nil {
return false, err
}
return true, nil
}

View file

@ -45,3 +45,23 @@ func TestStrainsStore_Get_db(t *testing.T) {
t.Errorf("got strain %+v, want %+v", strain, want)
}
}
func TestStrainsStore_Create_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
strain := newStrain(t, tx)
d := NewDatastore(tx)
created, err := d.Strains.Create(strain)
if err != nil {
t.Fatal(err)
}
if !created {
t.Error("!created")
}
if strain.Id == 0 {
t.Error("want nonzero strain.Id after submitting")
}
}