From 7e05af4c4bcf36d2e01d3df568978165507b5f07 Mon Sep 17 00:00:00 2001 From: swag Date: Sat, 8 Oct 2022 01:58:18 -0400 Subject: [PATCH] Implement the rest of the stuff for bumps; then some clean up along the way --- README.md | 5 +---- assets/css/PostText.css | 7 ++++++- lib/PostText/Model/Thread.pm | 19 ++++--------------- t/remark.t | 4 ++-- t/thread.t | 21 +++++++++++---------- templates/layouts/main.html.ep | 3 +++ templates/thread/by_page.html.ep | 5 +++++ 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 31b85e3..ca7c147 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ Run the tests locally (against development environment): ## TODOs -1. Bump button/counter (need the migration and model next) 1. Implement [bcrypt](https://metacpan.org/pod/Mojolicious::Plugin::BcryptSecure) 1. Some sort of admin/moderator login and view @@ -48,6 +47,4 @@ Run the tests locally (against development environment): requested](https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#respond_to) (JSON?) 1. Post thread via SMS (twil.io??) -1. CAPTCHA with - [Lingua::EN::Inflexion](https://metacpan.org/pod/Lingua::EN::Inflexion#cardinal()-and-cardinal($threshold)) - (This may not even be necessary with proper admin/moderation stuff) +1. Option to remark without bumping? diff --git a/assets/css/PostText.css b/assets/css/PostText.css index c62e0b9..86c23e5 100644 --- a/assets/css/PostText.css +++ b/assets/css/PostText.css @@ -1,9 +1,14 @@ +.field-with-info { + border-style: solid; + border-color: green; +} + .field-with-error { border-style: solid; border-color: red; } -.thread, .remark, .field-with-error { +.thread, .remark, .field-with-error, .field-with-info { border-style: dotted; border-collapse: collapse; } diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 21eb24c..30ee8a6 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -28,19 +28,6 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) { END_SQL } -sub dump_all($self) { - $self->pg->db->query(<<~'END_SQL', $self->{'date_format'})->hashes - SELECT thread_id AS id, - TO_CHAR(thread_date, ?) AS date, - thread_author AS author, - thread_title AS title, - thread_body AS body - FROM threads - WHERE NOT hidden_status - ORDER BY bump_date DESC; - END_SQL -} - sub by_page($self, $this_page = 1) { my $date_format = $self->{'date_format'}; my $row_count = $self->{'threads_per_page'}; @@ -53,7 +40,8 @@ sub by_page($self, $this_page = 1) { t.thread_author AS author, t.thread_title AS title, t.thread_body AS body, - COUNT(r.*) AS remark_count + COUNT(r.*) AS remark_count, + t.bump_count AS bump_count FROM threads t LEFT JOIN remarks r ON t.thread_id = r.thread_id @@ -103,7 +91,8 @@ sub by_id($self, $thread_id) { sub bump($self, $thread_id) { $self->pg->db->query(<<~'END_SQL', $thread_id) UPDATE threads - SET bump_date = NOW() + SET bump_date = NOW(), + bump_count = bump_count + 1 WHERE thread_id = ?; END_SQL } diff --git a/t/remark.t b/t/remark.t index 5bb6919..f7e7a7f 100644 --- a/t/remark.t +++ b/t/remark.t @@ -17,9 +17,9 @@ subtest 'View single remark', sub { $t->get_ok('/remark/1')->status_is(200)->text_like(h2 => qr/Remark #1/); }; -subtest 'Post new remark', sub { - $t->ua->max_redirects(1); +$t->ua->max_redirects(1); +subtest 'Post new remark', sub { # GET $t->get_ok('/post/1')->status_is(200) ->element_exists('form input[name="author"]' ) diff --git a/t/thread.t b/t/thread.t index 158b00f..41f267a 100644 --- a/t/thread.t +++ b/t/thread.t @@ -30,18 +30,9 @@ subtest 'View single thread', sub { $t->get_ok('/thread/1/1')->status_is(200)->text_like(h2 => qr/Thread #1/); }; -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/); -}; +$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"]' ) @@ -66,4 +57,14 @@ subtest 'Post new thread', sub { ->text_like(h2 => qr/Thread #[0-9]+/); }; +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(200) + ->element_exists('p[class="field-with-info"]') + ->text_like(p => qr/Thread #[0-9]+ has been bumped/); +}; + done_testing(); diff --git a/templates/layouts/main.html.ep b/templates/layouts/main.html.ep index 7972f8a..e09badc 100644 --- a/templates/layouts/main.html.ep +++ b/templates/layouts/main.html.ep @@ -5,6 +5,9 @@ <%= asset 'main.css' %> +<% if (flash 'info') { =%> +

<%= flash 'info' %>

+<% } =%>

Post::Text

+ <% } =%>