Skip to content

Commit

Permalink
Integration Test: use response helper
Browse files Browse the repository at this point in the history
Access `response.body` through `response` helper method instead of
directly reading from the `@response` instance variable.
  • Loading branch information
seanpdoyle committed Jan 29, 2023
1 parent d7bd577 commit a303bc1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/drive/drive_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
class Turbo::DriveHelperTest < ActionDispatch::IntegrationTest
test "opting out of the default cache" do
get trays_path
assert_match(/<meta name="turbo-cache-control" content="no-cache">/, @response.body)
assert_match(/<meta name="turbo-cache-control" content="no-cache">/, response.body)
end

test "requiring reload" do
get trays_path
assert_match(/<meta name="turbo-visit-control" content="reload">/, @response.body)
assert_match(/<meta name="turbo-visit-control" content="reload">/, response.body)
end
end
8 changes: 4 additions & 4 deletions test/frames/frame_request_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest

test "frame requests get a unique etag" do
get tray_path(id: 1)
etag_without_frame = @response.headers["ETag"]
etag_without_frame = response.headers["ETag"]

get tray_path(id: 1), headers: { "Turbo-Frame" => "true" }
etag_with_frame = @response.headers["ETag"]
etag_with_frame = response.headers["ETag"]

assert_not_equal etag_with_frame, etag_without_frame
end
Expand All @@ -23,9 +23,9 @@ class Turbo::FrameRequestControllerTest < ActionDispatch::IntegrationTest
turbo_frame_request_id = "test_frame_id"

get tray_path(id: 1)
assert_no_match /#{turbo_frame_request_id}/, @response.body
assert_no_match /#{turbo_frame_request_id}/, response.body

get tray_path(id: 1), headers: { "Turbo-Frame" => turbo_frame_request_id }
assert_match /#{turbo_frame_request_id}/, @response.body
assert_match /#{turbo_frame_request_id}/, response.body
end
end
10 changes: 5 additions & 5 deletions test/streams/streams_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest

get message_path(id: 1), as: :turbo_stream

assert_dom_equal <<~HTML, @response.body
assert_dom_equal <<~HTML, response.body
<turbo-stream action="remove" target="message_1"></turbo-stream>
<turbo-stream action="replace" target="message_1"><template>#{render(message_1)}</template></turbo-stream>
<turbo-stream action="replace" target="message_1"><template>Something else</template></turbo-stream>
Expand All @@ -40,7 +40,7 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest
assert_turbo_stream action: :replace, targets: "#message_4" do
assert_select 'template', 'Something fourth'
end
assert_dom_equal <<~HTML, @response.body
assert_dom_equal <<~HTML, response.body
<turbo-stream action="remove" targets="#message_1"></turbo-stream>
<turbo-stream action="replace" targets="#message_1"><template>#{render(message_1)}</template></turbo-stream>
<turbo-stream action="replace" targets="#message_1"><template>Something else</template></turbo-stream>
Expand All @@ -55,7 +55,7 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest

test "includes html format when rendering turbo_stream actions" do
post posts_path, as: :turbo_stream
assert_dom_equal <<~HTML.chomp, @response.body
assert_dom_equal <<~HTML.chomp, response.body
<turbo-stream action="update" target="form-area"><template>
Form
</template></turbo-stream>
Expand All @@ -64,15 +64,15 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest

test "render correct partial for namespaced models" do
get users_profile_path(id: 1), as: :turbo_stream
assert_dom_equal <<~HTML, @response.body.remove(/\n(?=<\/)/)
assert_dom_equal <<~HTML, response.body.remove(/\n(?=<\/)/)
<turbo-stream action="replace" target="users_profile_1"><template><p>David</p></template></turbo-stream>
<turbo-stream action="update" target="users_profile_1"><template><p>David</p></template></turbo-stream>
HTML
end

test "render correct partial and I18n with a custom view path in the controller" do
get admin_company_path(id: 1), as: :turbo_stream
assert_dom_equal <<~HTML, @response.body.remove(/\n(?=<\/)/)
assert_dom_equal <<~HTML, response.body.remove(/\n(?=<\/)/)
<turbo-stream action="replace" target="company_1"><template><p>Company:</p>
<p>Basecamp</p></template></turbo-stream>
HTML
Expand Down

0 comments on commit a303bc1

Please sign in to comment.