Skip to content

Commit

Permalink
Add a failing test case for rendering a partial with a block from phlex
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Apr 5, 2024
1 parent 2ac2756 commit 15bc835
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/dummy/app/controllers/rendering_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RenderingController < ApplicationController
def partial_from_phlex
render Rendering::PartialFromPhlex.new
end

def view_component_from_phlex
render Rendering::ViewComponentFromPhlex.new
end
end
3 changes: 3 additions & 0 deletions test/dummy/app/views/rendering/_partial.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="erb">
<%= yield %>
</div>
9 changes: 9 additions & 0 deletions test/dummy/app/views/rendering/partial_from_phlex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Rendering
class PartialFromPhlex < ApplicationView
def view_template
render "partial" do
h1(id: "phlex") { "Partial from Phlex" }
end
end
end
end
11 changes: 11 additions & 0 deletions test/dummy/app/views/rendering/vc_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Rendering
class VcComponent < ViewComponent::Base
renders_one :slot

def call
if slot?
slot
end
end
end
end
11 changes: 11 additions & 0 deletions test/dummy/app/views/rendering/view_component_from_phlex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Rendering
class ViewComponentFromPhlex < ApplicationView
def view_template
render VcComponent.new do |component|
component.slot do
p { "Rendered from Phlex" }
end
end
end
end
end
3 changes: 3 additions & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
get "/helpers/form_with", to: "helpers#form_with"
get "/helpers/tag", to: "helpers#tag"
get "/helpers/missing_helper", to: "helpers#missing_helper"

get "/rendering/partial_from_phlex", to: "rendering#partial_from_phlex"
get "/rendering/view_component_from_phlex", to: "rendering#view_component_from_phlex"
end
16 changes: 16 additions & 0 deletions test/phlex/render_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "test_helper"

class RenderTest < ActionDispatch::IntegrationTest
test "rendering partial from Phlex view" do
get "/rendering/partial_from_phlex"
assert_response :success
assert_select "#erb>h1#phlex", "Partial from Phlex"
end

test "rendering view_component component from Phlex view" do
get "/rendering/view_component_from_phlex"
assert_response :success
end
end

0 comments on commit 15bc835

Please sign in to comment.