Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
fixes auto issue with plurals (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni authored and stanislas-m committed May 12, 2018
1 parent 24434c4 commit df18355
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion render/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
26 changes: 26 additions & 0 deletions render/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit df18355

Please sign in to comment.