diff --git a/lib/PostText.pm b/lib/PostText.pm index c7415c3..c2a4ca7 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -43,6 +43,8 @@ sub startup($self) { my $r = $self->routes->under(sub ($c) { $c->session(expires => time + 31536000); + $c->session(author => 'Anonymous') unless $c->session('author'); + 1; }); diff --git a/t/post.t b/t/post.t index 3c9bf1b..1b12a6d 100644 --- a/t/post.t +++ b/t/post.t @@ -61,7 +61,7 @@ $t->post_ok('/post', form => \%invalid_title)->status_is(400) $t->post_ok('/post', form => \%invalid_post)->status_is(400) ->text_like(p => qr/Invalid text/); $t->post_ok('/post', form => \%valid_params)->status_is(200) - ->text_like(h2 => qr/Threads List/); + ->text_like(h2 => qr/Thread #[0-9]+/); $t->post_ok('/post/1')->status_is(200) ->element_exists('form input[name="author"]' ) diff --git a/templates/post.html.ep b/templates/post.html.ep index 56098f2..24e874a 100644 --- a/templates/post.html.ep +++ b/templates/post.html.ep @@ -4,11 +4,10 @@
<%= label_for author => 'Author' %> - <% if (my $previous_author = session->{'author'}) { =%> - <%= text_field author => $previous_author, maxlength => 63, minlength => 1 %> - <% } else { =%> - <%= text_field author => 'Anonymous', maxlength => 63, minlength => 1 %> - <% } =%> + <%= text_field author => session->{'author'}, ( + maxlength => 63, + minlength => 1 + ) %> <% if (my $error = validation->error('author')) { =%>

Invalid author: 1 to 63 characters please.

<% } =%> diff --git a/templates/thread_id.html.ep b/templates/thread_id.html.ep index c33057a..00d82a4 100644 --- a/templates/thread_id.html.ep +++ b/templates/thread_id.html.ep @@ -4,11 +4,10 @@
<%= label_for author => 'Author' %> - <% if (my $previous_author = session->{'author'}) { =%> - <%= text_field author => $previous_author, maxlength => 63, minlength => 1 %> - <% } else { =%> - <%= text_field author => 'Anonymous', maxlength => 63, minlength => 1 %> - <% } =%> + <%= text_field author => session->{'author'}, ( + maxlength => 63, + minlength => 1 + ) %> <% if (my $error = validation->error('author')) { =%>

Invalid author: 1 to 63 characters please.

<% } =%>