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 rack to runtime dependency #36

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rubocop-rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rubocop'
require 'rack/utils'

require_relative 'rubocop/rails/version'
require_relative 'rubocop/cop/rails_cops'
23 changes: 2 additions & 21 deletions lib/rubocop/cop/rails/http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ module Rails
# redirect_to root_url, status: 301
#
class HttpStatus < Cop
begin
require 'rack/utils'
RACK_LOADED = true
rescue LoadError
RACK_LOADED = false
end

include ConfigurableEnforcedStyle

def_node_matcher :http_status, <<-PATTERN
Expand All @@ -64,10 +57,6 @@ def on_send(node)
end
end

def support_autocorrect?
RACK_LOADED
end

def autocorrect(node)
lambda do |corrector|
checker = checker_class.new(node)
Expand Down Expand Up @@ -110,11 +99,7 @@ def offensive?
end

def message
if RACK_LOADED
format(MSG, prefer: preferred_style, current: number.to_s)
else
DEFAULT_MSG
end
format(MSG, prefer: preferred_style, current: number.to_s)
end

def preferred_style
Expand Down Expand Up @@ -155,11 +140,7 @@ def offensive?
end

def message
if RACK_LOADED
format(MSG, prefer: preferred_style, current: symbol.inspect)
else
DEFAULT_MSG
end
format(MSG, prefer: preferred_style, current: symbol.inspect)
end

def preferred_style
Expand Down
2 changes: 1 addition & 1 deletion rubocop-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |s|
'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-rails/issues'
}

s.add_runtime_dependency 'rack', '>= 2.0'
s.add_runtime_dependency 'rubocop', '>= 0.58.0'
s.add_development_dependency('rack', '>= 2.0')
end
# rubocop:enable Metrics/BlockLength
41 changes: 0 additions & 41 deletions spec/rubocop/cop/rails/http_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,6 @@
redirect_to root_url, status: 550
RUBY
end

context 'when rack is not loaded' do
before { stub_const("#{described_class}::RACK_LOADED", false) }

it 'registers an offense and does not correct using numeric value' do
expect_offense(<<-RUBY)
render :foo, status: 200
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
render json: { foo: 'bar' }, status: 404
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
render plain: 'foo/bar', status: 304
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
redirect_to root_url, status: 301
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
RUBY

expect_correction(<<-RUBY)
render :foo, status: 200
render json: { foo: 'bar' }, status: 404
render plain: 'foo/bar', status: 304
redirect_to root_url, status: 301
RUBY
end
end
end

context 'when EnforcedStyle is `numeric`' do
Expand Down Expand Up @@ -121,22 +97,5 @@
render :foo, status: :redirect
RUBY
end

context 'when rack is not loaded' do
before { stub_const("#{described_class}::RACK_LOADED", false) }

it 'registers an offense and corrects using symbolic value' do
expect_offense(<<-RUBY)
render :foo, status: :ok
^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
render json: { foo: 'bar' }, status: :not_found
^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
render plain: 'foo/bar', status: :not_modified
^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
redirect_to root_url, status: :moved_permanently
^^^^^^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
RUBY
end
end
end
end