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

Allow setting method when using the test helper #1805

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Jul 18, 2023

What are you trying to accomplish?

We have components whose logic varies depending based on the request method, which is not easy to test with the current with_request_url helper.

What approach did you choose and why?

This adds a new method option to with_request_url. This follows the pattern previously established with the host option which exists to similarly specify the host associated with the test request.

@BlakeWilliams
Copy link
Contributor

BlakeWilliams commented Jul 18, 2023

We have components whose logic varies depending based on the request method, which is not easy to test with the current with_request_url helper.

Can you share a real world example/use case? I'd like to understand the use case better before we move forward here.

@aduth
Copy link
Contributor Author

aduth commented Jul 19, 2023

We have components whose logic varies depending based on the request method, which is not easy to test with the current with_request_url helper.

Can you share a real world example/use case? I'd like to understand the use case better before we move forward here.

Sure thing. We have a component which renders a set of navigation links and highlights the current page. It's implemented by comparing the current request's handler (request[:controller] and request[:action]) against what would be the handler for a given link, using recognize_path.

There's some challenge in forms with both a new and create action, using the same path and GET and POST methods respectively. We want to render :new for an invalid form. To support this, the component needs to consider the request method when calling recognize_path to be able to compare against the current request handler. It's currently difficult to simulate this in tests for the component.

Maybe easier to share the actual code, effect, and our current workaround:

@reeganviljoen
Copy link
Collaborator

@Spone @aduth any updates on this pr

@aduth aduth force-pushed the aduth-with-request-url-method branch from 6672224 to 292b21b Compare September 25, 2023 19:46
@aduth
Copy link
Contributor Author

aduth commented Sep 25, 2023

@reeganviljoen From my perspective, I'm expecting this to be ready for review as-is. Based on the discussion at #1805 (comment), I don't have a clear sense that there's a suggested rename, and I'm reasonably happy with the current naming absent any objections.

I rebased the branch to resolve merge conflicts that existed due to drift.

Happy to make any revisions if suggestions are made!

@reeganviljoen
Copy link
Collaborator

@Spone any insights ?

@Spone
Copy link
Collaborator

Spone commented Nov 6, 2023

Looks good to me. Maybe @BlakeWilliams can review this too?

@aduth can you please resolve the conflicts?

@aduth aduth force-pushed the aduth-with-request-url-method branch from 292b21b to 30b6dd2 Compare November 6, 2023 15:02
@aduth
Copy link
Contributor Author

aduth commented Nov 6, 2023

@aduth can you please resolve the conflicts?

Done 👍

@camertron camertron merged commit b11ba1f into ViewComponent:main Nov 6, 2023
23 checks passed
claudiob pushed a commit to claudiob/view_component that referenced this pull request Dec 22, 2023
claudiob pushed a commit to claudiob/view_component that referenced this pull request Jan 3, 2024
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.

5 participants