Skip to content

Commit dea8939

Browse files
authored
Merge pull request #36 from pocke/add-runtime-dependency-rack
Add `rack` to runtime dependency
2 parents f093fc6 + 3c9500f commit dea8939

File tree

4 files changed

+4
-63
lines changed

4 files changed

+4
-63
lines changed

lib/rubocop-rails.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'rubocop'
4+
require 'rack/utils'
45

56
require_relative 'rubocop/rails/version'
67
require_relative 'rubocop/cop/rails_cops'

lib/rubocop/cop/rails/http_status.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ module Rails
3232
# redirect_to root_url, status: 301
3333
#
3434
class HttpStatus < Cop
35-
begin
36-
require 'rack/utils'
37-
RACK_LOADED = true
38-
rescue LoadError
39-
RACK_LOADED = false
40-
end
41-
4235
include ConfigurableEnforcedStyle
4336

4437
def_node_matcher :http_status, <<-PATTERN
@@ -64,10 +57,6 @@ def on_send(node)
6457
end
6558
end
6659

67-
def support_autocorrect?
68-
RACK_LOADED
69-
end
70-
7160
def autocorrect(node)
7261
lambda do |corrector|
7362
checker = checker_class.new(node)
@@ -110,11 +99,7 @@ def offensive?
11099
end
111100

112101
def message
113-
if RACK_LOADED
114-
format(MSG, prefer: preferred_style, current: number.to_s)
115-
else
116-
DEFAULT_MSG
117-
end
102+
format(MSG, prefer: preferred_style, current: number.to_s)
118103
end
119104

120105
def preferred_style
@@ -155,11 +140,7 @@ def offensive?
155140
end
156141

157142
def message
158-
if RACK_LOADED
159-
format(MSG, prefer: preferred_style, current: symbol.inspect)
160-
else
161-
DEFAULT_MSG
162-
end
143+
format(MSG, prefer: preferred_style, current: symbol.inspect)
163144
end
164145

165146
def preferred_style

rubocop-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
3131
'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-rails/issues'
3232
}
3333

34+
s.add_runtime_dependency 'rack', '>= 2.0'
3435
s.add_runtime_dependency 'rubocop', '>= 0.58.0'
35-
s.add_development_dependency('rack', '>= 2.0')
3636
end
3737
# rubocop:enable Metrics/BlockLength

spec/rubocop/cop/rails/http_status_spec.rb

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,6 @@
4949
redirect_to root_url, status: 550
5050
RUBY
5151
end
52-
53-
context 'when rack is not loaded' do
54-
before { stub_const("#{described_class}::RACK_LOADED", false) }
55-
56-
it 'registers an offense and does not correct using numeric value' do
57-
expect_offense(<<-RUBY)
58-
render :foo, status: 200
59-
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
60-
render json: { foo: 'bar' }, status: 404
61-
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
62-
render plain: 'foo/bar', status: 304
63-
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
64-
redirect_to root_url, status: 301
65-
^^^ Prefer `symbolic` over `numeric` to define HTTP status code.
66-
RUBY
67-
68-
expect_correction(<<-RUBY)
69-
render :foo, status: 200
70-
render json: { foo: 'bar' }, status: 404
71-
render plain: 'foo/bar', status: 304
72-
redirect_to root_url, status: 301
73-
RUBY
74-
end
75-
end
7652
end
7753

7854
context 'when EnforcedStyle is `numeric`' do
@@ -121,22 +97,5 @@
12197
render :foo, status: :redirect
12298
RUBY
12399
end
124-
125-
context 'when rack is not loaded' do
126-
before { stub_const("#{described_class}::RACK_LOADED", false) }
127-
128-
it 'registers an offense and corrects using symbolic value' do
129-
expect_offense(<<-RUBY)
130-
render :foo, status: :ok
131-
^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
132-
render json: { foo: 'bar' }, status: :not_found
133-
^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
134-
render plain: 'foo/bar', status: :not_modified
135-
^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
136-
redirect_to root_url, status: :moved_permanently
137-
^^^^^^^^^^^^^^^^^^ Prefer `numeric` over `symbolic` to define HTTP status code.
138-
RUBY
139-
end
140-
end
141100
end
142101
end

0 commit comments

Comments
 (0)