1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actiontext/test/integration/controller_render_test.rb
Jonathan Hefner 76e111395c Always render Action Text HTML with :html format
Since #40222, Action Text HTML is rendered in the context of the current
request.  This causes the Action Text template format to default to the
request format, which prevents the template from being resolved when the
request format is not `:html` (e.g. `:json`).  Therefore, override the
template format to always be `:html`.

Fixes #40695.
2020-11-27 10:59:24 -06:00

34 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
class ActionText::ControllerRenderTest < ActionDispatch::IntegrationTest
test "uses current request environment" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))
host! "loocalhoost"
get message_path(message)
assert_select "#content img" do |imgs|
imgs.each { |img| assert_match %r"//loocalhoost/", img["src"] }
end
end
test "renders as HTML when the request format is not HTML" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))
host! "loocalhoost"
get message_path(message, format: :json)
content = Nokogiri::HTML::DocumentFragment.parse(response.parsed_body["content"])
assert_select content, "img:match('src', ?)", %r"//loocalhoost/.+/racecar"
end
test "resolves partials when controller is namespaced" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))
get admin_message_path(message)
assert_select "#content-html .trix-content .attachment--jpg"
end
end