From c7e2445c37d9ef4cdb10e2d2a179d4bddf3e8256 Mon Sep 17 00:00:00 2001 From: swag Date: Thu, 6 Oct 2022 22:46:38 -0400 Subject: [PATCH] Implement tests for Bump feature; tweak some tests a bit; begin initial bump feature stuff --- lib/PostText.pm | 9 ++++++++- lib/PostText/Controller/Bump.pm | 14 ++++++++++++++ lib/PostText/Model/Bump.pm | 0 t/bump.t | 14 ++++++++++++++ t/remark.t | 6 ++---- t/root.t | 2 -- t/thread.t | 6 ++---- 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 lib/PostText/Controller/Bump.pm create mode 100644 lib/PostText/Model/Bump.pm create mode 100644 t/bump.t diff --git a/lib/PostText.pm b/lib/PostText.pm index 2eb9791..9d6d1a6 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -67,7 +67,8 @@ sub startup($self) { ->name('threads_list'); my $post_thread = $r->under; - $post_thread->any([qw{GET POST}], '/post')->to('thread#create') + $post_thread->any([qw{GET POST}], '/post') + ->to('thread#create') ->name('post_thread'); my $single_thread = @@ -88,6 +89,12 @@ sub startup($self) { $single_remark->get('/:remark_id', [remark_id => qr/[0-9]+/]) ->to('remark#by_id') ->name('single_remark'); + + # Bump + my $bump_thread = $r->under('/bump'); + $bump_thread->get('/:thread_id', [thread_id => qr/[0-9]+/]) + ->to('bump#create') + ->name('bump_thread'); } 1; diff --git a/lib/PostText/Controller/Bump.pm b/lib/PostText/Controller/Bump.pm new file mode 100644 index 0000000..252fd86 --- /dev/null +++ b/lib/PostText/Controller/Bump.pm @@ -0,0 +1,14 @@ +package PostText::Controller::Bump; + +use Mojo::Base 'Mojolicious::Controller', -signatures; + +sub create($self) { + my $thread_id = $self->param('thread_id'); + + $self->thread->bump($thread_id); + $self->flash(info => "Thread #$thread_id has been bumped.🔝"); + + $self->redirect_to('threads_list'); +} + +1; diff --git a/lib/PostText/Model/Bump.pm b/lib/PostText/Model/Bump.pm new file mode 100644 index 0000000..e69de29 diff --git a/t/bump.t b/t/bump.t new file mode 100644 index 0000000..4321244 --- /dev/null +++ b/t/bump.t @@ -0,0 +1,14 @@ +use Mojo::Base -strict; +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('PostText'); + +subtest 'Bumping thread', sub { + $t->get_ok('/list')->status_is(200) + ->element_exists('a[href~="bump"]') + ->text_like(h2 => qr/Threads List/); + + $t->get_ok('/bump/1')->status_is(302) + ->header_like(Location => qr/list/); +}; diff --git a/t/remark.t b/t/remark.t index 43ff3c7..5bb6919 100644 --- a/t/remark.t +++ b/t/remark.t @@ -1,5 +1,3 @@ -#!/usr/bin/env perl - use Mojo::Base -strict; use Test::More; use Test::Mojo; @@ -19,9 +17,9 @@ subtest 'View single remark', sub { $t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/); }; -$t->ua->max_redirects(1); - subtest 'Post new remark', sub { + $t->ua->max_redirects(1); + # GET $t->get_ok('/post/1')->status_is(200) ->element_exists('form input[name="author"]' ) diff --git a/t/root.t b/t/root.t index 7f13989..df43724 100644 --- a/t/root.t +++ b/t/root.t @@ -1,5 +1,3 @@ -#!/usr/bin/env perl - use Mojo::Base -strict; use Test::More; use Test::Mojo; diff --git a/t/thread.t b/t/thread.t index 1dfd845..7f1a10a 100644 --- a/t/thread.t +++ b/t/thread.t @@ -1,5 +1,3 @@ -#!/usr/bin/env perl - use Mojo::Base -strict; use Test::More; use Test::Mojo; @@ -32,9 +30,9 @@ subtest 'View single thread', sub { $t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/); }; -$t->ua->max_redirects(1); - subtest 'Post new thread', sub { + $t->ua->max_redirects(1); + # GET $t->get_ok('/post')->status_is(200) ->element_exists('form input[name="author"]' )