From ff93fa1d2b4ef5c82021ca40b846c44a628b1c89 Mon Sep 17 00:00:00 2001 From: swag Date: Tue, 27 Sep 2022 13:20:30 -0400 Subject: [PATCH] Fix test; clean up the author name stuff a lil --- lib/PostText.pm | 2 ++ t/post.t | 2 +- templates/post.html.ep | 9 ++++----- templates/thread_id.html.ep | 9 ++++----- 4 files changed, 11 insertions(+), 11 deletions(-) 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.

<% } =%>