Cleaning stuff up
This commit is contained in:
parent
99cef47f95
commit
419769545b
|
@ -13,16 +13,16 @@ sub startup($self) {
|
|||
$self->plugin(AssetPack => {pipes => [qw{Css Combine}]});
|
||||
|
||||
# Helpers
|
||||
$self->helper(pg => sub {
|
||||
state $pg = Mojo::Pg->new(shift->config->{$self->mode}{'pg_string'})
|
||||
$self->helper(pg => sub ($c) {
|
||||
state $pg = Mojo::Pg->new($c->config->{$self->mode}{'pg_string'})
|
||||
});
|
||||
|
||||
$self->helper(thread => sub {
|
||||
state $thread = PostText::Model::Thread->new(pg => shift->pg)
|
||||
$self->helper(thread => sub ($c) {
|
||||
state $thread = PostText::Model::Thread->new(pg => $c->pg)
|
||||
});
|
||||
|
||||
$self->helper(remark => sub {
|
||||
state $remark = PostText::Model::Remark->new(pg => shift->pg)
|
||||
$self->helper(remark => sub ($c) {
|
||||
state $remark = PostText::Model::Remark->new(pg => $c->pg)
|
||||
});
|
||||
|
||||
$self->helper(truncate_text => sub ($c, $input_text) {
|
||||
|
@ -71,7 +71,7 @@ sub startup($self) {
|
|||
->to('thread#create')
|
||||
->name('post_thread');
|
||||
|
||||
$thread->under('/:thread_id', [thread_id => qr/[0-9]+/])
|
||||
$thread->under('/single/:thread_id', [thread_id => qr/[0-9]+/])
|
||||
->get('/:thread_page', [thread_page => qr/[0-9]+/], {thread_page => 1})
|
||||
->to('thread#by_id')
|
||||
->name('single_thread');
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
daniel@graymember.98268
|
27
t/remark.t
27
t/remark.t
|
@ -4,46 +4,49 @@ use Test::Mojo;
|
|||
|
||||
my $t = Test::Mojo->new('PostText');
|
||||
|
||||
my %valid_remark = (
|
||||
my %valid_remark = (
|
||||
author => 'Anonymous',
|
||||
body => 'hi'
|
||||
);
|
||||
|
||||
my %invalid_remark = (
|
||||
author => 'Anonymous',
|
||||
body => 'a'
|
||||
);
|
||||
|
||||
subtest 'View single remark', sub {
|
||||
$t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/);
|
||||
$t->get_ok('/remark/single/1')->status_is(200)
|
||||
->text_like(h2 => qr/Remark #1/);
|
||||
};
|
||||
|
||||
subtest 'Flagging remark', sub {
|
||||
$t->get_ok('/remark/1')->status_is(200)
|
||||
->element_exists('a[href*="flag"]')
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
}
|
||||
|
||||
$t->ua->max_redirects(1);
|
||||
|
||||
subtest 'Post new remark', sub {
|
||||
# GET
|
||||
$t->get_ok('/post/1')->status_is(200)
|
||||
$t->get_ok('/remark/post/1')->status_is(200)
|
||||
->element_exists('form input[name="author"]' )
|
||||
->element_exists('form textarea[name="body"]')
|
||||
->element_exists('form input[type="submit"]' )
|
||||
->text_like(h2 => qr/New Remark/);
|
||||
|
||||
# POST
|
||||
$t->post_ok('/post/1')->status_is(200)
|
||||
$t->post_ok('/remark/post/1')->status_is(200)
|
||||
->element_exists('form input[name="author"]' )
|
||||
->element_exists('form textarea[name="body"]')
|
||||
->element_exists('form input[type="submit"]' )
|
||||
->text_like(h2 => qr/New Remark/);
|
||||
|
||||
$t->post_ok('/post/1', form => \%valid_remark)->status_is(200)
|
||||
$t->post_ok('/remark/post/1', form => \%valid_remark)->status_is(200)
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
$t->post_ok('/post/1', form => \%invalid_remark)->status_is(400)
|
||||
|
||||
$t->post_ok('/remark/post/1', form => \%invalid_remark)->status_is(400)
|
||||
->text_like(p => qr/Invalid text/);
|
||||
};
|
||||
|
||||
subtest 'Flagging remark', sub {
|
||||
$t->get_ok('/remark/single/1')->status_is(200)
|
||||
->element_exists('a[href*="flag"]')
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
|
2
t/root.t
2
t/root.t
|
@ -4,6 +4,6 @@ use Test::Mojo;
|
|||
|
||||
my $t = Test::Mojo->new('PostText');
|
||||
|
||||
$t->get_ok('/')->status_is(302);
|
||||
$t->get_ok('/')->status_is(302)->header_like(Location => qr/thread/);
|
||||
|
||||
done_testing();
|
||||
|
|
40
t/thread.t
40
t/thread.t
|
@ -4,37 +4,45 @@ use Test::Mojo;
|
|||
|
||||
my $t = Test::Mojo->new('PostText');
|
||||
|
||||
my %valid_params = (
|
||||
my %valid_params = (
|
||||
author => 'Anonymous',
|
||||
title => 'hi',
|
||||
body => 'ayy... lmao'
|
||||
);
|
||||
|
||||
my %invalid_title = (
|
||||
author => 'Anonymous',
|
||||
title => '',
|
||||
body => 'ayy... lmao'
|
||||
);
|
||||
my %invalid_post = (
|
||||
|
||||
my %invalid_post = (
|
||||
author => 'Anonymous',
|
||||
title => 'hi',
|
||||
body => 'a'
|
||||
);
|
||||
|
||||
subtest 'List threads by page', sub {
|
||||
$t->get_ok('/list' )->status_is(200)->text_like(h2 => qr/Threads List/);
|
||||
$t->get_ok('/list/1')->status_is(200)->text_like(h2 => qr/Threads List/);
|
||||
$t->get_ok('/thread/list')->status_is(200)
|
||||
->text_like(h2 => qr/Threads List/);
|
||||
|
||||
$t->get_ok('/thread/list/1')->status_is(200)
|
||||
->text_like(h2 => qr/Threads List/);
|
||||
};
|
||||
|
||||
subtest 'View single thread', sub {
|
||||
$t->get_ok('/thread/1' )->status_is(200)->text_like(h2 => qr/Thread #1/);
|
||||
$t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/);
|
||||
$t->get_ok('/thread/single/1')->status_is(200)
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
|
||||
$t->get_ok('/thread/single/1/1')->status_is(200)
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
};
|
||||
|
||||
$t->ua->max_redirects(1);
|
||||
|
||||
subtest 'Post new thread', sub {
|
||||
# GET
|
||||
$t->get_ok('/post')->status_is(200)
|
||||
$t->get_ok('/thread/post')->status_is(200)
|
||||
->element_exists('form input[name="author"]' )
|
||||
->element_exists('form input[name="title"]' )
|
||||
->element_exists('form textarea[name="body"]')
|
||||
|
@ -42,37 +50,39 @@ subtest 'Post new thread', sub {
|
|||
->text_like(h2 => qr/New Thread/);
|
||||
|
||||
# POST
|
||||
$t->post_ok('/post')->status_is(200)
|
||||
$t->post_ok('/thread/post')->status_is(200)
|
||||
->element_exists('form input[name="author"]' )
|
||||
->element_exists('form input[name="title"]' )
|
||||
->element_exists('form textarea[name="body"]')
|
||||
->element_exists('form input[type="submit"]' )
|
||||
->text_like(h2 => qr/New Thread/);
|
||||
|
||||
$t->post_ok('/post', form => \%invalid_title)->status_is(400)
|
||||
$t->post_ok('/thread/post', form => \%invalid_title)->status_is(400)
|
||||
->text_like(p => qr/Invalid title/);
|
||||
$t->post_ok('/post', form => \%invalid_post)->status_is(400)
|
||||
|
||||
$t->post_ok('/thread/post', form => \%invalid_post)->status_is(400)
|
||||
->text_like(p => qr/Invalid text/);
|
||||
$t->post_ok('/post', form => \%valid_params)->status_is(200)
|
||||
|
||||
$t->post_ok('/thread/post', form => \%valid_params)->status_is(200)
|
||||
->text_like(h2 => qr/Thread #[0-9]+/);
|
||||
};
|
||||
|
||||
subtest 'Bumping thread', sub {
|
||||
$t->get_ok('/list')->status_is(200)
|
||||
$t->get_ok('/thread/list')->status_is(200)
|
||||
->element_exists('a[href*="bump"]')
|
||||
->text_like(h2 => qr/Threads List/);
|
||||
|
||||
$t->get_ok('/bump/1')->status_is(200)
|
||||
$t->get_ok('/thread/bump/1')->status_is(200)
|
||||
->element_exists('p[class="field-with-info"]')
|
||||
->text_like(p => qr/Thread #[0-9]+ has been bumped/);
|
||||
};
|
||||
|
||||
subtest 'Flagging thread', sub {
|
||||
$t->get_ok('/list')->status_is(200)
|
||||
$t->get_ok('/thread/list')->status_is(200)
|
||||
->element_exists('a[href*="flag"]')
|
||||
->text_like(h2 => qr/Threads List/);
|
||||
|
||||
$t->get_ok('/thread/1')->status_is(200)
|
||||
$t->get_ok('/thread/single/1')->status_is(200)
|
||||
->element_exists('a[href*="flag"]')
|
||||
->text_like(h2 => qr/Thread #1/);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue