Skip to content

Commit

Permalink
Add failing test case when rendering blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv committed Oct 15, 2024
1 parent 7dee942 commit 66f757d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/phlex/rails/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def helpers

def render(*args, **kwargs, &block)
renderable = args[0]
# Something like this could fix the issue
# renderable = args[0] || (block if kwargs[:partial].blank?)

case renderable
when Phlex::SGML, Proc, Method, String
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/controllers/rendering_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

class RenderingController < ApplicationController
def standard_phlex
render Rendering::StandardPhlex.new
end

def partial_from_phlex
render Rendering::PartialFromPhlex.new
end
Expand Down
17 changes: 17 additions & 0 deletions test/dummy/app/views/rendering/standard_phlex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Rendering
class StandardPhlex < ApplicationView
def view_template
render Header do
h1(id: "title") { "Hello Phlex!" }
end
end

class Header < ApplicationComponent
def view_template(&)
render(&)
end
end
end
end
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get "/helpers/missing_helper", to: "helpers#missing_helper"
get "/helpers/notice", to: "helpers#notice_test"

get "/rendering/standard_phlex", to: "rendering#standard_phlex"
get "/rendering/partial_from_phlex", to: "rendering#partial_from_phlex"
get "/rendering/view_component_from_phlex", to: "rendering#view_component_from_phlex"
get "/rendering/phlex_component_from_erb", to: "rendering#phlex_component_from_erb"
Expand Down
6 changes: 6 additions & 0 deletions test/phlex/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
require "test_helper"

class RenderTest < ActionDispatch::IntegrationTest
test "rendering standard phlex" do
get "/rendering/standard_phlex"
assert_response :success
assert_select "h1#title", "Hello Phlex!"
end

test "rendering partial from Phlex view" do
get "/rendering/partial_from_phlex"
assert_response :success
Expand Down

0 comments on commit 66f757d

Please sign in to comment.