Skip to content

Commit

Permalink
Use Rack.release over Rack::RELEASE
Browse files Browse the repository at this point in the history
The constant Rack::RELEASE was introduced only in rack version 2
(specifically: rack/rack@a2fe30a)
Earlier versions provided the class method Rack.release which still
exists.

puma#3061 has introduced usage of
Rack::RELEASE and therefore broke compatibility with rack 1.6.X.
  • Loading branch information
severin committed May 15, 2023
1 parent 898dc44 commit d55227f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/puma/rack_default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.default(options = {})
end
end
end
elsif Object.const_defined?(:Rack) && Rack::RELEASE < '3'
elsif Object.const_defined?(:Rack) && Rack.release < '3'
module Rack
module Handler
def self.default(options = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/handler/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class << self
end
end
else
do_register = Object.const_defined?(:Rack) && Rack::RELEASE < '3'
do_register = Object.const_defined?(:Rack) && Rack.release < '3'
module Rack
module Handler
module Puma
Expand Down
4 changes: 2 additions & 2 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def skip_if(*engs, suffix: '', bt: caller)
when :fork then "Skipped if Kernel.fork exists" if HAS_FORK
when :unix then "Skipped if UNIXSocket exists" if Puma::HAS_UNIX_SOCKET
when :aunix then "Skipped if abstract UNIXSocket" if Puma.abstract_unix_socket?
when :rack3 then "Skipped if Rack 3.x" if Rack::RELEASE >= '3'
when :rack3 then "Skipped if Rack 3.x" if Rack.release >= '3'
else false
end
skip skip_msg, bt if skip_msg
Expand All @@ -201,7 +201,7 @@ def skip_unless(eng, bt: caller)
when :fork then MSG_FORK unless HAS_FORK
when :unix then MSG_UNIX unless Puma::HAS_UNIX_SOCKET
when :aunix then MSG_AUNIX unless Puma.abstract_unix_socket?
when :rack3 then "Skipped unless Rack >= 3.x" unless ::Rack::RELEASE >= '3'
when :rack3 then "Skipped unless Rack >= 3.x" unless ::Rack.release >= '3'
else false
end
skip skip_msg, bt if skip_msg
Expand Down
2 changes: 1 addition & 1 deletion test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_default_max_threads
end

def test_app_from_rackup
if Rack::RELEASE >= '3'
if Rack.release >= '3'
fn = "test/rackup/hello-bind_rack3.ru"
bind = "tcp://0.0.0.0:9292"
else
Expand Down
8 changes: 4 additions & 4 deletions test/test_rack_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Rack::Chunked is loaded by Rack v2, needs to be required by Rack 3.0,
# and is removed in Rack 3.1
require "rack/chunked" if Rack::RELEASE.start_with? '3.0'
require "rack/chunked" if Rack.release.start_with? '3.0'

require "nio"

Expand Down Expand Up @@ -41,7 +41,7 @@ def call(env)

class ServerLint < Rack::Lint
def call(env)
if Rack::RELEASE < '3'
if Rack.release < '3'
check_env env
else
Wrapper.new(@app, env).check_environment env
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_rack_chunked_array1
resp = Net::HTTP.get_response URI(@tcp)
assert_equal 'chunked', resp['transfer-encoding']
assert_equal STR_1KB, resp.body.force_encoding(Encoding::UTF_8)
end if Rack::RELEASE < '3.1'
end if Rack.release < '3.1'

def test_rack_chunked_array10
body = Array.new 10, STR_1KB
Expand All @@ -253,7 +253,7 @@ def test_rack_chunked_array10
resp = Net::HTTP.get_response URI(@tcp)
assert_equal 'chunked', resp['transfer-encoding']
assert_equal STR_1KB * 10, resp.body.force_encoding(Encoding::UTF_8)
end if Rack::RELEASE < '3.1'
end if Rack.release < '3.1'

def test_puma_enum
body = Array.new(10, STR_1KB).to_enum
Expand Down

0 comments on commit d55227f

Please sign in to comment.