Exemplo n.º 1
0
func TestReadMany(t *testing.T) {
	art, e := article.New(DB)
	if e != nil {
		t.Error(e)
	}
	art.Title = "Art 1"
	e = art.Save()
	if e != nil {
		t.Error(e)
	}

	art1, _ := article.New(DB)

	art1.Title = "Art 2"
	e = art1.Save()
	if e != nil {
		t.Error(e)
	}

	arts, e := art.ReadMany(&db.Filter{Limit: 2})
	if e != nil {
		t.Error(e)
	}

	assert.Equal(t, 2, len(arts), "Sould be 2 articles")
	art = arts[0]

	art.Title = "Kirya"
	e = art.Save()
	if e != nil {
		t.Error(e)
	}
}
Exemplo n.º 2
0
func (s *Service) NewArticle(a ...article.Article) (*article.Article, error) {
	if len(a) > 0 {
		return article.NewFrom(a[0], s.db)
	}
	return article.New(s.db)
}