Skip to content

Instantly share code, notes, and snippets.

@ssoriche
Created April 8, 2012 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssoriche/2338286 to your computer and use it in GitHub Desktop.
Save ssoriche/2338286 to your computer and use it in GitHub Desktop.
checked check_box set from stash or param.
use Test::More tests => 3;
use Test::Mojo;
{
package Foo;
use Mojo::Base 'Mojolicious';
sub startup {
my $self = shift;
my $r = $self->routes;
$r->get('form/:test')->to( 'Form#form' );
}
1;
}
{
package Foo::Form;
use Mojo::Base 'Mojolicious::Controller';
sub form {
my ($self, $args) = @_;
$self->stash(foo => 'baz');
$self->param(a => 'a');
$self->stash(bar => 'foo');
$self->render(template => 'form');
}
}
my $t = Test::Mojo->new('Foo');
$t->get_ok('/form/23')->status_is(200)->content_is(<<EOF);
<form action="form" method="post">
<input name="foo" value="baz" />
<input name="bar" type="checkbox" checked="checked" value="1" />
<input name="a" type="checkbox" checked="checked" value="2" />
<input type="submit" value="Ok!" />
<input id="bar" type="submit" value="Ok too!" />
</form>
EOF
__DATA__
@@ form.html.ep
%= form_for 'form', {test => 24}, method => 'post' => begin
%= text_field 'foo', value => stash 'foo'
%= check_box bar => 1
%= check_box a => 2
%= submit_button 'Ok!'
%= submit_button 'Ok too!', id => 'bar'
%= end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment