Преглед на файлове

Embed a post again, by calling posts() with the arguments that it takes

embed() in Trog::Renderer::html called posts({...}, sub { }, 1). That
was right when 2110a4d added embeds and posts() took a render callback.
28cd69b removed the callback from the signature of posts(), but not
from this caller. So each embed died with "Too many arguments". Xslate
catches an exception from a template function, so the page rendered
anyway, with an empty string where the embedded post should be.

No test embedded a post. The lifecycle test now saves a blog post whose
body embeds another, and renders it. It makes sure that the embedded
body is in place, in the embed style, once, and with no warning. Before
the fix, the last three assertions failed, and the warning was the one
above.

Closes #380

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot преди 4 дни
родител
ревизия
55b043bf2d
променени са 2 файла, в които са добавени 25 реда и са изтрити 1 реда
  1. 0 1
      lib/Trog/Renderer/html.pm
  2. 25 0
      t/Trog-Routes-HTML-series-lifecycle.t

+ 0 - 1
lib/Trog/Renderer/html.pm

@@ -28,7 +28,6 @@ sub render (%options) {
                 return Text::Xslate::mark_raw(
                     Trog::Routes::HTML::posts(
                         { route => "/post/$this_id", style => $style },
-                        sub { },
                         1
                     )
                 );

+ 25 - 0
t/Trog-Routes-HTML-series-lifecycle.t

@@ -1114,6 +1114,31 @@ subtest 'blog' => sub {
     unlike( $body, qr/Spec[ ]Payee[ ]Entity/, 'no bleed from the entities series' );
 };
 
+subtest 'a post that embeds another' => sub {
+    my $embedded = find_post('Spec Blog Child') or return fail('the blog child is there to embed');
+    my $host     = save_post(
+        'embedding post',
+        form       => 'blog.tx',
+        title      => 'Spec Embedding Post',
+        data       => "Before the embed. <: embed('$embedded->{id}') :> After the embed.",
+        visibility => 'public',
+        tags       => ['specblog'],
+        to         => '/specblog',
+    ) or return;
+
+    my @warned;
+    local $SIG{__WARN__} = sub { push @warned, @_ };
+    my ( $code, $page, $err ) = render( anon( route => "/posts/$host->{id}", id => $host->{id} ), \&Trog::Routes::HTML::posts );
+    is( $code, 200, 'the post renders' ) or return diag($err);
+
+    my ($data) = $page =~ m{id="postData-\Q$host->{id}\E">(.*?)After[ ]the[ ]embed}s;
+    ok( defined $data, 'with its own body' ) or return;
+    like( $data, qr/Spec[ ]blog[ ]body[ ]text[.]/, 'and the body of the post it embeds, in place' );
+    my $embeds = () = $data =~ m/class="post[ ]embed"/g;
+    is( $embeds,         1, 'in the embed style, and only that one post' );
+    is( scalar(@warned), 0, 'without a warning' ) or diag( explain( \@warned ) );
+};
+
 subtest 'microblog' => sub {
     my $title = 'Spec Microblog Series';
     make_series( qw{microblog specmicroblog microblog.tx}, $title ) or return;