From ac163eca37d7652f28c309a37202e1edc3cdce87 Mon Sep 17 00:00:00 2001 From: swag Date: Sat, 11 Dec 2021 19:01:43 -0500 Subject: [PATCH] Clean up the Test model --- guestbook-ng.pl | 20 +------------------- lib/GuestbookNg/Model/Test.pm | 21 --------------------- t/basic.t | 11 ++++++++--- templates/layouts/default.html.ep | 6 ++---- templates/{post.html.ep => sign.html.ep} | 2 +- templates/test.html.ep | 13 ------------- 6 files changed, 12 insertions(+), 61 deletions(-) delete mode 100644 lib/GuestbookNg/Model/Test.pm rename templates/{post.html.ep => sign.html.ep} (92%) delete mode 100644 templates/test.html.ep diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 14500b4..ca1a01c 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -6,7 +6,6 @@ use Mojolicious::Lite -signatures; use Mojo::Pg; use lib 'lib'; -use GuestbookNg::Model::Test; use GuestbookNg::Model::Message; use Data::Dumper; # Uncomment for debugging @@ -30,10 +29,6 @@ helper pg => sub { ); }; -helper test => sub { - state $test = GuestbookNg::Model::Test->new(pg => shift->pg) -}; - helper message => sub { state $message = GuestbookNg::Model::Message->new(pg => shift->pg) }; @@ -48,20 +43,7 @@ get '/' => sub ($c) { $c->render(posts => $posts); } => 'index'; -any '/test' => sub ($c) { - my $method = $c->req->method(); - my $time = $c->test->now(); - my $string = - $method eq 'POST' ? $c->test->test_model($c->param('string')) : undef; - - $c->render( - method => $method, - string => $string, - time => $time - ); -}; - -any '/post' => sub ($c) { +any '/sign' => sub ($c) { if ($c->req->method() eq 'POST') { my $name = $c->param('name'); my $message = $c->param('message'); diff --git a/lib/GuestbookNg/Model/Test.pm b/lib/GuestbookNg/Model/Test.pm deleted file mode 100644 index 8a9823a..0000000 --- a/lib/GuestbookNg/Model/Test.pm +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env perl - -package GuestbookNg::Model::Test; - -use Mojo::Base -base, -signatures; - -has 'pg'; - -sub new($class, $pg, $object) { - bless {$pg => $object} -} - -sub test_model($self, $string) { - "you've supplied: $string" -} - -sub now($self) { - $self->pg->db->query('SELECT NOW() AS now')->text() -} - -1; diff --git a/t/basic.t b/t/basic.t index 8b926f8..13e1dbe 100644 --- a/t/basic.t +++ b/t/basic.t @@ -6,10 +6,15 @@ use Test::Mojo; my $script = curfile->dirname->sibling('guestbook-ng.pl'); my $t = Test::Mojo->new($script); +my %form = ( + name => 'swagg boi', + message => 'Ayy... lmao' + ); + +$t->ua->max_redirects(10); -# Just make sure we get a 200 OK for now $t->get_ok('/')->status_is(200); -$t->get_ok('/test')->status_is(200); -$t->post_ok('/test', form => {string => 'a'})->status_is(200); +$t->get_ok('/sign')->status_is(200); +$t->post_ok('/sign', form => \%form)->status_is(200); done_testing(); diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 0916ebb..1d8cb48 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -9,11 +9,9 @@ - + - - - +
<%= link_to Home => 'index' %><%= link_to View => 'index' %>  <%= link_to Test => 'test' %> <%= link_to Sign => 'post' %><%= link_to Sign => 'sign' %>
<%= content %> diff --git a/templates/post.html.ep b/templates/sign.html.ep similarity index 92% rename from templates/post.html.ep rename to templates/sign.html.ep index cf6032f..e6152c2 100644 --- a/templates/post.html.ep +++ b/templates/sign.html.ep @@ -1,6 +1,6 @@ % layout 'default'; % title 'New Post'; -

Create a New Post

+

Sign the Guestbook

diff --git a/templates/test.html.ep b/templates/test.html.ep deleted file mode 100644 index 770fd8c..0000000 --- a/templates/test.html.ep +++ /dev/null @@ -1,13 +0,0 @@ -% layout 'default'; -% title 'Test'; -

test page

-<% if ($method eq 'POST') { %> -

<%= $string %> at <%= $time =>

-<% } else { %> - -
-
- - -<% } %>