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 custom_request, remove duplication #184

Merged
merged 3 commits into from
Jul 26, 2017
Merged

Add custom_request, remove duplication #184

merged 3 commits into from
Jul 26, 2017

Conversation

iGEL
Copy link
Contributor

@iGEL iGEL commented Jun 6, 2017

I believe, it's not useful to support every HTTP verb defined everywhere with a custom method. But it should be possible to use those verbs, thus we should introduce a method to trigger requests with a custom verb. Unfortunately, there is already a public request method, so I had to choose a different name.

As requested, this is a rebased & updated version of #111. I wanted to asked to reopen that one, but my changes didn't show up after force pushing, so I opened a new PR.

@dennissivia
Copy link

@iGEL Thanks for the PR. Just to make sure I am getting it right. The primary focus of the PR is to have a nicer syntax for non "standard verbs" like thiscustom_request("link", "/uri"), right?
Just want to make sure that I understand the trade off correctly.

@iGEL
Copy link
Contributor Author

iGEL commented Jun 6, 2017

@scepticulous Actually, I don't remember the exact details of this PR that I opened almost 3 years ago. I just rebased it and adjusted so the work wouldn't be lost. 😊

From what I remember and read from the changes here, it's not possible to send custom http verbs at all with rack-test (except of course using private APIs with send 😱). There are some very rarely used verbs in the standards out there and I think, rack-test should allow to use the in some way.

Also, I removed some duplication at the same time, which is also a (small) improvement.

@perlun
Copy link
Contributor

perlun commented Jul 18, 2017

@iGEL sorry, but I think we'll have to rebase it again. 😇 Can it be done?

@scepticulous - what do you think about the change per se?

@dennissivia
Copy link

@perlun @iGEL I agree with the objection of the PR but I am not quiet sure about the method name for a public API . I would rather prefer a lot of verb liked names and something like request or http_request as public API.
My other concern is the test syntax. I would like to avoid public_send as the execution step. Can we improve these two points somehow ?

@iGEL
Copy link
Contributor Author

iGEL commented Jul 18, 2017

@scepticulous As mentioned in the description, request is already present. I'm not sure how useful it is (since it allows to make requests without a verb), but I would rather avoid breaking the API for this. Keeping the API stable and introducing the new behavior into request is a pretty awkward. To keep the "verb uri params env" form, which seems pretty natural to me, I would have to do something like this:

def request(verb_or_uri, uri_or_env = nil, params = {}, env_or_nothing = {}, &block)
  if uri_or_env.is_a(String)
    uri = uri_or_env
    env = env_for(uri, env_or_nothing.merge(:method => verb_or_uri.to_s.upcase, :params => params))
  else
    uri = verb_or_uri
    env = env_for(uri, uri_or_env)
  end

  uri = parse_uri(uri, env)  
  process_request(uri, env, &block)
end

So, I could rename custom_request to http_request or make_request. No really good options left 😞 WDYT?

To your second comment: I don't really get it. I basically just moved the spec to a better place (the shared example is only used here) and improved it a bit. public_send is still meta programming, but at least you can't call private methods like send before. Can you specify more, what I should do here?

@dennissivia
Copy link

@iGEL thanks a lot for the i depth explanation. And sorry I did not read the diff correctly with regards to the test. So refining my two complains:

  1. I think you are right and we should be able to support custom requests. And I think custom_request is still a better name, than my suggestions and I would definitely not change request this way.
  2. Sorry for the confusion. I think your change improves the tests with regards to location and the public_send. So that is fine with me.

@perlun @junaruga I suggest merging the PR after a final rebase, since it is an improvement in two ways. However it also showed that the touched code needs general improvement, however I would not block this PR because of that but would try to find time to take a look at it myself before we release 1.0.
Please ACK so that I know if you agree with me here.

@junaruga
Copy link
Contributor

@scepticulous
Sorry. I have no time to check the code right now.
I agree with you. :)

iGEL added 3 commits July 19, 2017 10:14
I believe, it's not useful to support every HTTP verb defined
everywhere with a custom method. But it should be possible to use those
verbs, thus we should introduce a method to trigger requests with a
custom verb. Unfortunately, there is already a public request method, so
I had to choose a different name.
RSpec is encouraging very long blocks, so I don't think there's a way
around them.

The block in the gemspec is just configuration.
@iGEL
Copy link
Contributor Author

iGEL commented Jul 19, 2017

@scepticulous @junaruga @perlun Thanks for the review 😄

I rebased the commit now, but I also added c32207e, because rubocop was complaining about very long blocks in the specs, which I don't consider a bad thing. WDYT?

codeclimate is failing, because it uses an outdated version of rubocop. %i[] is now preferred over %i().

@dennissivia
Copy link

@iGEL thanks. I agree with you about the block length but not exactly with disabling it. In my opinion it is fine to have a higher value for tests but I would not disable it. Can you find the value that is appropriate / necessary at the moment, so something like 2-5 to the number necessary to make rubocop happy?.
When that is done, we can merge. We will address the codeclimate/robucop inconsistency on our own later.

@perlun
Copy link
Contributor

perlun commented Jul 24, 2017

@scepticulous I think it's fine to disable it for specs. Most test suites (like rspec etc) are based on block-based syntax, which tends to generate quite long blocks.

So I am fine with the way @iGEL disabled it, for specs only which is exactly what c32207e did. 👍 on that part from my end.

@dennissivia dennissivia merged commit 43a3ccf into rack:master Jul 26, 2017
@iGEL iGEL deleted the dry branch July 28, 2017 14:41
@iGEL
Copy link
Contributor Author

iGEL commented Jul 28, 2017

Thank you 😊

alex-damian-negru pushed a commit to alex-damian-negru/rack-test that referenced this pull request Apr 5, 2021
* Introduce custom_request to support all verbs

I believe, it's not useful to support every HTTP verb defined
everywhere with a custom method. But it should be possible to use those
verbs, thus we should introduce a method to trigger requests with a
custom verb. Unfortunately, there is already a public request method, so
I had to choose a different name.

* Avoid parsing the URI twice [Fixes rack#104]

* Allow long blocks in spec & gemspec

RSpec is encouraging very long blocks, so I don't think there's a way
around them.

The block in the gemspec is just configuration.
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.

4 participants