Skip to content

Commit

Permalink
Merge pull request #65 from gobuffalo/task/adding-missing-tests
Browse files Browse the repository at this point in the history
Adding missing tests for the input hidden
  • Loading branch information
paganotoni committed Jan 25, 2018
2 parents c2176b1 + f7e184e commit 5949790
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions form/bootstrap/form_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type FormFor struct {
*form.FormFor
}

//CheckboxTag adds a checkbox to a form
func (f FormFor) CheckboxTag(field string, opts tags.Options) *tags.Tag {
label := field
if opts["label"] != nil {
Expand Down
7 changes: 7 additions & 0 deletions form/form_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ func Test_FormFor_FieldDoesntExist(t *testing.T) {
r.Equal(`<input id="talk-IDontExist" name="IDontExist" type="text" value="" />`, l.String())
}

func Test_FormFor_HiddenTag(t *testing.T) {
r := require.New(t)
f := form.NewFormFor(Talk{}, tags.Options{})
l := f.HiddenTag("Name", tags.Options{})
r.Equal(`<input id="talk-Name" name="Name" type="hidden" value="" />`, l.String())
}

func Test_FormFor_NullableField(t *testing.T) {
r := require.New(t)
model := struct {
Expand Down
5 changes: 5 additions & 0 deletions form/input_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import "github.com/gobuffalo/tags"

//InputTag generates an input tag with passed options, by default will be type=text.
func (f Form) InputTag(opts tags.Options) *tags.Tag {
if opts["type"] == "hidden" {
return f.HiddenTag(opts)
}

if opts["type"] == nil {
opts["type"] = "text"
}

if opts["type"] == "file" {
f.Options["enctype"] = "multipart/form-data"
}
Expand Down
7 changes: 7 additions & 0 deletions form/input_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ func Test_Form_HiddenTag_File(t *testing.T) {
i := f.HiddenTag(tags.Options{})
r.Equal(`<input type="hidden" />`, i.String())
}

func Test_Form_InputTag_Hidden(t *testing.T) {
r := require.New(t)
f := form.New(tags.Options{})
i := f.InputTag(tags.Options{"type": "hidden"})
r.Equal(`<input type="hidden" />`, i.String())
}

0 comments on commit 5949790

Please sign in to comment.