Example #1
0
func (m *Mother) TemplateServiceObjects() (services.TemplateCreator, services.TemplateFinder, services.TemplateUpdater,
	services.TemplateDeleter, services.TemplateLister, services.TemplateAssigner, services.TemplateAssociationLister) {

	clientsRepo, kindsRepo := m.Repos()
	templatesRepo := m.TemplatesRepo()

	return services.NewTemplateCreator(templatesRepo),
		m.TemplateFinder(),
		services.NewTemplateUpdater(templatesRepo),
		services.NewTemplateDeleter(templatesRepo),
		services.NewTemplateLister(templatesRepo),
		services.NewTemplateAssigner(clientsRepo, kindsRepo, templatesRepo),
		services.NewTemplateAssociationLister(clientsRepo, kindsRepo, templatesRepo)
}
var _ = Describe("Updater", func() {
	Describe("Update", func() {
		var (
			conn          *mocks.Connection
			database      *mocks.Database
			templatesRepo *mocks.TemplatesRepo
			updater       services.TemplateUpdater
		)

		BeforeEach(func() {
			conn = mocks.NewConnection()
			database = mocks.NewDatabase()
			database.ConnectionCall.Returns.Connection = conn
			templatesRepo = mocks.NewTemplatesRepo()

			updater = services.NewTemplateUpdater(templatesRepo)
		})

		It("Inserts templates into the templates repo", func() {
			err := updater.Update(database, "my-awesome-id", models.Template{
				Name: "gobble template",
				Text: "gobble",
				HTML: "<p>gobble</p>",
			})
			Expect(err).ToNot(HaveOccurred())

			Expect(templatesRepo.UpdateCall.Receives.Connection).To(Equal(conn))
			Expect(templatesRepo.UpdateCall.Receives.TemplateID).To(Equal("my-awesome-id"))
			Expect(templatesRepo.UpdateCall.Receives.Template).To(Equal(models.Template{
				Name: "gobble template",
				Text: "gobble",