add test case demonstrating how newline in template caused issue

This commit is contained in:
Joel Hawksley 2021-05-10 08:52:19 -06:00
Родитель 35c3949c13
Коммит 30296ef802
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 1BBA4349888F4C0D
3 изменённых файлов: 30 добавлений и 11 удалений

Просмотреть файл

@ -1 +1 @@
<span>Hello, world!</span>
<span>Hello, world!</span>

Просмотреть файл

@ -51,6 +51,28 @@ def with_preview_controller(new_value)
app.reloader.reload!
end
def with_new_cache
begin
old_cache = ViewComponent::CompileCache.cache
ViewComponent::CompileCache.cache = Set.new
ActionView::Base.cache_template_loading = false
yield
ensure
ActionView::Base.cache_template_loading = true
ViewComponent::CompileCache.cache = old_cache
end
end
def without_template_annotations
old_value = ActionView::Base.annotate_rendered_view_with_filenames
ActionView::Base.annotate_rendered_view_with_filenames = false
app.reloader.reload!
yield
ActionView::Base.annotate_rendered_view_with_filenames = old_value
app.reloader.reload!
end
def modify_file(file, content)
filename = Rails.root.join(file)
old_content = File.read(filename)

Просмотреть файл

@ -57,11 +57,7 @@ class IntegrationTest < ActionDispatch::IntegrationTest
end
def test_template_changes_are_reflected_on_new_request_when_cache_template_loading_is_false
begin
old_cache = ViewComponent::CompileCache.cache
ViewComponent::CompileCache.cache = Set.new
ActionView::Base.cache_template_loading = false
with_new_cache do
get "/controller_inline"
assert_select("div", "bar")
assert_response :success
@ -75,9 +71,6 @@ class IntegrationTest < ActionDispatch::IntegrationTest
get "/controller_inline"
assert_select("div", "bar")
assert_response :success
ensure
ActionView::Base.cache_template_loading = true
ViewComponent::CompileCache.cache = old_cache
end
end
@ -444,8 +437,12 @@ class IntegrationTest < ActionDispatch::IntegrationTest
end
def test_does_not_render_additional_newline
get "/rails/view_components/display_inline_component/with_newline"
assert_includes response.body, "<span>Hello, world!</span><span>Hello, world!</span>"
without_template_annotations do
with_new_cache do
get "/rails/view_components/display_inline_component/with_newline"
assert_includes response.body, "<span>Hello, world!</span><span>Hello, world!</span>"
end
end
end
def test_renders_the_preview_example_with_its_own_template_and_a_layout