Clean up the Test model
This commit is contained in:
parent
2a2b761d0a
commit
ac163eca37
|
@ -6,7 +6,6 @@
|
||||||
use Mojolicious::Lite -signatures;
|
use Mojolicious::Lite -signatures;
|
||||||
use Mojo::Pg;
|
use Mojo::Pg;
|
||||||
use lib 'lib';
|
use lib 'lib';
|
||||||
use GuestbookNg::Model::Test;
|
|
||||||
use GuestbookNg::Model::Message;
|
use GuestbookNg::Model::Message;
|
||||||
use Data::Dumper; # Uncomment for debugging
|
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 {
|
helper message => sub {
|
||||||
state $message = GuestbookNg::Model::Message->new(pg => shift->pg)
|
state $message = GuestbookNg::Model::Message->new(pg => shift->pg)
|
||||||
};
|
};
|
||||||
|
@ -48,20 +43,7 @@ get '/' => sub ($c) {
|
||||||
$c->render(posts => $posts);
|
$c->render(posts => $posts);
|
||||||
} => 'index';
|
} => 'index';
|
||||||
|
|
||||||
any '/test' => sub ($c) {
|
any '/sign' => 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) {
|
|
||||||
if ($c->req->method() eq 'POST') {
|
if ($c->req->method() eq 'POST') {
|
||||||
my $name = $c->param('name');
|
my $name = $c->param('name');
|
||||||
my $message = $c->param('message');
|
my $message = $c->param('message');
|
||||||
|
|
|
@ -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;
|
|
11
t/basic.t
11
t/basic.t
|
@ -6,10 +6,15 @@ use Test::Mojo;
|
||||||
|
|
||||||
my $script = curfile->dirname->sibling('guestbook-ng.pl');
|
my $script = curfile->dirname->sibling('guestbook-ng.pl');
|
||||||
my $t = Test::Mojo->new($script);
|
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('/')->status_is(200);
|
||||||
$t->get_ok('/test')->status_is(200);
|
$t->get_ok('/sign')->status_is(200);
|
||||||
$t->post_ok('/test', form => {string => 'a'})->status_is(200);
|
$t->post_ok('/sign', form => \%form)->status_is(200);
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
@ -9,11 +9,9 @@
|
||||||
<!-- Nav table -->
|
<!-- Nav table -->
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to Home => 'index' %></td>
|
<td><%= link_to View => 'index' %></td>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
<td><%= link_to Test => 'test' %></td>
|
<td><%= link_to Sign => 'sign' %></td>
|
||||||
<td> </td>
|
|
||||||
<td><%= link_to Sign => 'post' %></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<%= content %>
|
<%= content %>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
% layout 'default';
|
% layout 'default';
|
||||||
% title 'New Post';
|
% title 'New Post';
|
||||||
<h2>Create a New Post</h2>
|
<h2>Sign the Guestbook</h2>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
|
@ -1,13 +0,0 @@
|
||||||
% layout 'default';
|
|
||||||
% title 'Test';
|
|
||||||
<h2>test page</h2>
|
|
||||||
<% if ($method eq 'POST') { %>
|
|
||||||
<p><%= $string %> at <%= $time =></p>
|
|
||||||
<% } else { %>
|
|
||||||
<form action="/test" method="post">
|
|
||||||
<label>Give me string:<br>
|
|
||||||
<input type="text" name="string"></label><br>
|
|
||||||
<br>
|
|
||||||
<input type="submit" value="Submit">
|
|
||||||
</form>
|
|
||||||
<% } %>
|
|
Loading…
Reference in a new issue