Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cable_ready.integration_test_request_encoding initializer #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tcannonfodder
Copy link

Type of PR

Enhancement

Description

Why should this be added

This makes it easier for folks to write tests for their CableReady actions, making the gem fit into the larger ecosystem

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing

* This has been adapted from https://github.com/hotwired/turbo-rails/blob/9b17a3be3705786d72c3ae77fde5a9b3006555d7/lib/turbo/engine.rb#L119
* In order to streamline development, Rails integration tests should
	be able to support `as: :cable_ready` to test Cable Ready responses
	* This is done by setting up a new request encoding that
		ActionDispatch's integration tests can use. In this case, the
		encoder is barebones and is largely focused on streamlining how
		the request `Accept` headers are setup
Copy link

netlify bot commented Aug 4, 2024

Deploy Preview for cableready ready!

Name Link
🔨 Latest commit 05c269f
🔍 Latest deploy log https://app.netlify.com/sites/cableready/deploys/66af08dfd8360d00081d2a59
😎 Deploy Preview https://deploy-preview-300--cableready.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

# Support `as: :cable_ready`. Public `register_encoder` API is a little too strict.
class ActionDispatch::RequestEncoder
class CableReadyStreamEncoder < IdentityEncoder
header = [ Mime[:cable_ready], Mime[:html] ].join(",")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tcannonfodder, thanks for this pull request. Should this be :json instead of :html, since the MIME-Type is text/vnd.cable-ready.json:

Suggested change
header = [ Mime[:cable_ready], Mime[:html] ].join(",")
header = [ Mime[:cable_ready], Mime[:json ].join(",")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoroth yeah, that sounds right to me. There's a syntax error in your suggestion though, so it's this:

Suggested change
header = [ Mime[:cable_ready], Mime[:html] ].join(",")
header = [ Mime[:cable_ready], Mime[:json] ].join(",")

Copy link
Member

@marcoroth marcoroth Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are totally @kaspth! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants