Code review feedback
This commit is contained in:
Родитель
c02e4166e7
Коммит
311a0807d6
|
@ -88,9 +88,9 @@ module ViewComponent
|
|||
options = app.config.view_component
|
||||
|
||||
if options.show_previews
|
||||
preview_controller = options.preview_controller.sub(/Controller$/, "").underscore
|
||||
|
||||
app.routes.append do
|
||||
preview_controller = options.preview_controller.sub(/Controller$/, "").underscore
|
||||
|
||||
get options.preview_route, to: "#{preview_controller}#index", as: :preview_view_components, internal: true
|
||||
get "#{options.preview_route}/*path", to: "#{preview_controller}#previews", as: :preview_view_component, internal: true
|
||||
end
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MyPreviewController < ViewComponentsController
|
||||
|
||||
def index
|
||||
if params[:custom_controller].present?
|
||||
render plain: "Custom controller"
|
||||
else
|
||||
super
|
||||
end
|
||||
render plain: "Custom controller"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ Dummy::Application.configure do
|
|||
config.view_component.preview_paths << "#{Rails.root}/lib/component_previews"
|
||||
config.view_component.render_monkey_patch_enabled = true
|
||||
config.view_component.test_controller = "IntegrationExamplesController"
|
||||
config.view_component.preview_controller = "MyPreviewController"
|
||||
# config.view_component.preview_controller = "MyPreviewController"
|
||||
|
||||
# Tell Action Mailer not to deliver emails to the real world.
|
||||
# The :test delivery method accumulates sent emails in the
|
||||
|
|
|
@ -30,6 +30,15 @@ def with_preview_route(new_value)
|
|||
app.reloader.reload!
|
||||
end
|
||||
|
||||
def with_preview_controller(new_value)
|
||||
old_value = Rails.application.config.view_component.preview_controller
|
||||
Rails.application.config.view_component.preview_controller = new_value
|
||||
app.reloader.reload!
|
||||
yield
|
||||
Rails.application.config.view_component.preview_controller = old_value
|
||||
app.reloader.reload!
|
||||
end
|
||||
|
||||
def modify_file(file, content)
|
||||
filename = Rails.root.join(file)
|
||||
old_content = File.read(filename)
|
||||
|
|
|
@ -344,8 +344,10 @@ class IntegrationTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_renders_the_previews_in_the_configured_controller
|
||||
get "/rails/view_components/?custom_controller=true"
|
||||
assert_equal response.body, "Custom controller"
|
||||
with_preview_controller("MyPreviewController") do
|
||||
get "/rails/view_components"
|
||||
assert_equal response.body, "Custom controller"
|
||||
end
|
||||
end
|
||||
|
||||
def test_renders_singular_and_collection_slots_with_arguments
|
||||
|
|
Загрузка…
Ссылка в новой задаче