From df18355a75dd7b085985f2535f01e5ebae8eeefd Mon Sep 17 00:00:00 2001 From: Antonio Pagano <645522+paganotoni@users.noreply.github.com> Date: Sun, 25 Mar 2018 11:25:31 -0500 Subject: [PATCH] fixes auto issue with plurals (#990) --- render/auto.go | 2 +- render/auto_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/render/auto.go b/render/auto.go index 2c026967f..b0ce48e89 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(ir.typeName()) + name := inflect.Name(strings.ToLower(ir.typeName())) name = inflect.Name(name.Singular()) pname := inflect.Name(name.Plural()) diff --git a/render/auto_test.go b/render/auto_test.go index f71319702..ac6ad9bb8 100644 --- a/render/auto_test.go +++ b/render/auto_test.go @@ -68,6 +68,32 @@ func Test_Auto_HTML_List(t *testing.T) { r.NoError(err) } +func Test_Auto_HTML_List_Plural(t *testing.T) { + r := require.New(t) + + type Person struct { + Name string + } + + type People []Person + + err := withHTMLFile("people/index.html", "INDEX: <%= len(people) %>", func(e *render.Engine) { + app := buffalo.New(buffalo.Options{}) + app.GET("/people", func(c buffalo.Context) error { + return c.Render(200, e.Auto(c, People{ + Person{Name: "Ford"}, + Person{Name: "Chevy"}, + })) + }) + + w := willie.New(app) + res := w.HTML("/people").Get() + + r.Contains(res.Body.String(), "INDEX: 2") + }) + r.NoError(err) +} + func Test_Auto_HTML_Show(t *testing.T) { r := require.New(t)