Implement migration for bump
This commit is contained in:
parent
c3abf0e771
commit
451e751aae
|
@ -35,7 +35,7 @@ sub startup($self) {
|
||||||
# Finish configuring some things
|
# Finish configuring some things
|
||||||
$self->secrets($self->config->{'secrets'}) || die $@;
|
$self->secrets($self->config->{'secrets'}) || die $@;
|
||||||
|
|
||||||
$self->pg->migrations->from_dir('migrations')->migrate(5);
|
$self->pg->migrations->from_dir('migrations')->migrate(6);
|
||||||
|
|
||||||
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
|
if (my $threads_per_page = $self->config->{'threads_per_page'}) {
|
||||||
$self->thread->per_page($threads_per_page)
|
$self->thread->per_page($threads_per_page)
|
||||||
|
@ -93,7 +93,7 @@ sub startup($self) {
|
||||||
# Bump
|
# Bump
|
||||||
my $bump_thread = $r->under('/bump');
|
my $bump_thread = $r->under('/bump');
|
||||||
$bump_thread->get('/:thread_id', [thread_id => qr/[0-9]+/])
|
$bump_thread->get('/:thread_id', [thread_id => qr/[0-9]+/])
|
||||||
->to('bump#create')
|
->to('thread#bump')
|
||||||
->name('bump_thread');
|
->name('bump_thread');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
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;
|
|
|
@ -85,4 +85,13 @@ sub by_page($self) {
|
||||||
$self->render;
|
$self->render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub bump($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;
|
1;
|
||||||
|
|
2
migrations/6/down.sql
Normal file
2
migrations/6/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE threads
|
||||||
|
DROP COLUMN bump_count;
|
12
migrations/6/up.sql
Normal file
12
migrations/6/up.sql
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
ALTER TABLE threads
|
||||||
|
ADD COLUMN bump_count INTEGER
|
||||||
|
NOT NULL
|
||||||
|
DEFAULT 0;
|
||||||
|
|
||||||
|
UPDATE threads t
|
||||||
|
SET bump_count = r.remark_count
|
||||||
|
FROM (SELECT COUNT(*) AS remark_count,
|
||||||
|
thread_id
|
||||||
|
FROM remarks
|
||||||
|
GROUP BY thread_id) AS r
|
||||||
|
WHERE t.thread_id = r.thread_id;
|
14
t/bump.t
14
t/bump.t
|
@ -1,14 +0,0 @@
|
||||||
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/);
|
|
||||||
};
|
|
|
@ -30,6 +30,15 @@ subtest 'View single thread', sub {
|
||||||
$t->get_ok('/thread/1/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/);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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/);
|
||||||
|
};
|
||||||
|
|
||||||
subtest 'Post new thread', sub {
|
subtest 'Post new thread', sub {
|
||||||
$t->ua->max_redirects(1);
|
$t->ua->max_redirects(1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue