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

Bugfix for custom HTTP status codes #561

Merged
merged 2 commits into from Feb 24, 2018
Merged

Conversation

bquorning
Copy link
Collaborator

Fixes #560.

When Rails/HttpStatus is configured to use symbolic style, a custom HTTP status code (e.g. 550) that couldn't be found in Rack's SYMBOL_TO_STATUS_CODE hash would result in an error:

^^^ Prefer `nil` over `550` to describe HTTP status code.

This is solved by allowing integer values that are not present in SYMBOL_TO_STATUS_CODE when using the symbolic stile.

For this to work, I found that the Rails/HttpStatus cop couldn’t continue to be flexible in its dependency on Rack. But we cannot allow rubocop-rspec to have a hard dependency on Rack either. So I’m suggesting that we rescue LoadError either in the cop itself, or in the rspec_cops.rb file, right after require_relative 'rspec/rails/http_status'.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes.
  • The build (bundle exec rake) is passing.

If Rack isn't loaded, the cop just isn't available.
When Rails/HttpStatus is configured to use `symbolic` style, a custom HTTP
status code (e.g. 550) that couldn't be found in Rack's `SYMBOL_TO_STATUS_CODE`
hash would result in an error:

    ^^^ Prefer `nil` over `550` to describe HTTP status code.
@Darhazer
Copy link
Member

I was thinking the same - this false positive can be fixed only if rack is available (and generally whoever uses this cop will have it available). Not loading the cop at all, when there is no rack available, seems reasonable.

@bquorning bquorning merged commit c52c41f into master Feb 24, 2018
@bquorning bquorning deleted the bquorning_http_status-bugfix branch February 24, 2018 20:43
@bquorning
Copy link
Collaborator Author

cc @anthony-robin

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.

None yet

2 participants