diff --git a/README.md b/README.md
index 7b6b92b..958487f 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,10 @@ Now try requesting http://localhost:3000
## Testing
-Run the tests locally (against development environment):
+First, create a valid first thread and first remark to the first
+thread. The tests rely on the existence of thread #1 and remark #1
+being the first remark to that first thread. Then you can run the
+tests locally:
prove -l
diff --git a/lib/PostText.pm b/lib/PostText.pm
index 0e17054..f7baeaa 100644
--- a/lib/PostText.pm
+++ b/lib/PostText.pm
@@ -156,6 +156,7 @@ sub startup($self) {
my $remark = $r->any('/remark');
$remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/])
+ ->any('/:remark_id', [remark_id => qr/\d+/], {remark_id => 0})
->to('remark#create')
->name('post_remark');
diff --git a/lib/PostText/Controller/Remark.pm b/lib/PostText/Controller/Remark.pm
index 48bdb85..6b6b019 100644
--- a/lib/PostText/Controller/Remark.pm
+++ b/lib/PostText/Controller/Remark.pm
@@ -15,7 +15,9 @@ sub by_id($self) {
}
sub create($self) {
- my ($thread_id, $v) = ($self->param('thread_id'), undef);
+ my $thread_id = $self->param('thread_id');
+ my $remark_id = $self->param('remark_id');
+ my $v;
$v = $self->validation if $self->req->method eq 'POST';
@@ -50,7 +52,9 @@ sub create($self) {
}
my $thread = $self->thread->by_id($thread_id);
- my $last_remark = $self->remark->last_for($thread_id);
+ my $last_remark = $remark_id
+ ? $self->remark->by_id($remark_id)
+ : $self->remark->last_for($thread_id);
$self->stash(
thread => $thread,
diff --git a/t/remark.t b/t/remark.t
index cf91296..175fb39 100644
--- a/t/remark.t
+++ b/t/remark.t
@@ -16,7 +16,8 @@ my %invalid_remark = (
subtest 'View single remark', sub {
$t->get_ok('/remark/single/1')->status_is(200)
- ->text_like(h2 => qr/Remark #1/);
+ ->text_like(h2 => qr/Remark #1/)
+ ->element_exists('a[href$="/remark/post/1/1"]')
};
$t->ua->max_redirects(1);
@@ -28,6 +29,13 @@ subtest 'Post new remark', sub {
->element_exists('form textarea[name="body"]')
->element_exists('form button[type="submit"]' )
->text_like(h2 => qr/Remark on Thread #/);
+ # Test the remark-to-remark thing
+ $t->get_ok('/remark/post/1/1')->status_is(200)
+ ->element_exists('form input[name="author"]' )
+ ->element_exists('form textarea[name="body"]')
+ ->element_exists('form button[type="submit"]' )
+ ->element_exists('a[href$="/remark/single/1"]')
+ ->text_like(h3 => qr/Last Remark/);
# POST
$t->post_ok('/remark/post/1')->status_is(200)
diff --git a/t/thread.t b/t/thread.t
index da9e6ff..a3c3a2e 100644
--- a/t/thread.t
+++ b/t/thread.t
@@ -34,8 +34,9 @@ subtest 'View single thread', sub {
$t->get_ok('/thread/single/1')->status_is(200)
->text_like(h2 => qr/Thread #1/);
+ # Test the thread_page and remark_id params
$t->get_ok('/thread/single/1/1')->status_is(200)
- ->text_like(h2 => qr/Thread #1/);
+ ->element_exists('a[href$="/remark/post/1/1"]');
$t->get_ok('/thread/single/65536')->status_is(404)
->text_like(p => qr/Thread not found/);
diff --git a/templates/remark/by_id.html.ep b/templates/remark/by_id.html.ep
index 721e2de..bb8327b 100644
--- a/templates/remark/by_id.html.ep
+++ b/templates/remark/by_id.html.ep
@@ -29,7 +29,8 @@
<%= link_to Thread => single_thread =>
{thread_id => $remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Remark => post_remark =>
- {thread_id => $remark->{'thread_id'}}, (class => 'click') %>
+ {thread_id => $remark->{'thread_id'}, remark_id => $remark->{'id'}},
+ (class => 'click') %>
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}},
(class => 'click') %>
diff --git a/templates/remark/create.html.ep b/templates/remark/create.html.ep
index 9cf19c9..f687bc5 100644
--- a/templates/remark/create.html.ep
+++ b/templates/remark/create.html.ep
@@ -48,6 +48,43 @@
+<%# Putting this first above the thread body (nested if, yucky sry) %>
+<% if (keys %{$last_remark}) { =%>
+
+<% } =%><%# Close the last_remark 'if' %>
-<% } =%>
-<% if (keys %{$last_remark}) { =%>
-
-<% } =%>
+<% } =%><%# Close the thread 'if' %>
diff --git a/templates/thread/by_id.html.ep b/templates/thread/by_id.html.ep
index 7dd3e83..f0616a4 100644
--- a/templates/thread/by_id.html.ep
+++ b/templates/thread/by_id.html.ep
@@ -66,7 +66,8 @@
<%== markdown $remark->{'body'} =%>