From 9e8e0e96d24d0bb6e9f8a3fd76872a577760c009 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 3 Apr 2018 15:44:39 -0500 Subject: [PATCH 1/3] adding broken tests for the multiple word handling in Auto --- render/auto_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/render/auto_test.go b/render/auto_test.go index ac6ad9bb8..3421b4485 100644 --- a/render/auto_test.go +++ b/render/auto_test.go @@ -94,6 +94,32 @@ func Test_Auto_HTML_List_Plural(t *testing.T) { r.NoError(err) } +func Test_Auto_HTML_List_Plural_MultiWord(t *testing.T) { + r := require.New(t) + + type RoomProvider struct { + Name string + } + + type RoomProviders []RoomProvider + + err := withHTMLFile("room_providers/index.html", "INDEX: <%= len(room_providers) %>", func(e *render.Engine) { + app := buffalo.New(buffalo.Options{}) + app.GET("/room_providers", func(c buffalo.Context) error { + return c.Render(200, e.Auto(c, RoomProviders{ + RoomProvider{Name: "Ford"}, + RoomProvider{Name: "Chevy"}, + })) + }) + + w := willie.New(app) + res := w.HTML("/room_providers").Get() + + r.Contains(res.Body.String(), "INDEX: 2") + }) + r.NoError(err) +} + func Test_Auto_HTML_Show(t *testing.T) { r := require.New(t) From a7b94e3d1a85cc46cd2f81ab67d8b07600373594 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 3 Apr 2018 16:00:08 -0500 Subject: [PATCH 2/3] fixing auto for multiple words --- render/auto.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/auto.go b/render/auto.go index b0ce48e89..1bf98ffa8 100644 --- a/render/auto.go +++ b/render/auto.go @@ -91,7 +91,7 @@ func (htmlAutoRenderer) ContentType() string { } func (ir htmlAutoRenderer) Render(w io.Writer, data Data) error { - name := inflect.Name(strings.ToLower(ir.typeName())) + name := inflect.Name(inflect.Underscore(ir.typeName())) name = inflect.Name(name.Singular()) pname := inflect.Name(name.Plural()) From 550f6a74f5c8349267df724aed86321703dde3d2 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 3 Apr 2018 16:51:37 -0500 Subject: [PATCH 3/3] fixing test template variable --- render/auto_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render/auto_test.go b/render/auto_test.go index 3421b4485..f4c66fc80 100644 --- a/render/auto_test.go +++ b/render/auto_test.go @@ -103,7 +103,7 @@ func Test_Auto_HTML_List_Plural_MultiWord(t *testing.T) { type RoomProviders []RoomProvider - err := withHTMLFile("room_providers/index.html", "INDEX: <%= len(room_providers) %>", func(e *render.Engine) { + err := withHTMLFile("room_providers/index.html", "INDEX: <%= len(roomProviders) %>", func(e *render.Engine) { app := buffalo.New(buffalo.Options{}) app.GET("/room_providers", func(c buffalo.Context) error { return c.Render(200, e.Auto(c, RoomProviders{