From aed365db6aed8085f991a46ca3a5f1f844fde82b Mon Sep 17 00:00:00 2001 From: Stanislav Katkov Date: Thu, 19 Sep 2024 16:16:18 +0200 Subject: [PATCH] test against latest rack v2 as well --- .github/workflows/ci.yml | 17 +++++++++++++---- idempo.gemspec | 4 ++-- lib/idempo.rb | 9 ++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b3966a..f4363d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: ruby: - - '2.7' + - "2.7" steps: - name: Checkout uses: actions/checkout@v4 @@ -40,8 +40,8 @@ jobs: strategy: matrix: ruby: - - '2.7' - - '3.2' + - "2.7" + - "3.2" services: mysql: image: mysql:5.7 @@ -70,7 +70,7 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: RSpec + - name: RSpec with rack v3 run: bundle exec rspec env: MYSQL_HOST: 127.0.0.1 @@ -78,3 +78,12 @@ jobs: PGHOST: localhost PGUSER: postgres PGPASSWORD: postgres + - name: RSpec with rack v2 + run: bundle exec rspec + env: + IDEMPO_RACK_VERSION: "2.0" + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + PGHOST: localhost + PGUSER: postgres + PGPASSWORD: postgres diff --git a/idempo.gemspec b/idempo.gemspec index 278433e..b3fea4b 100644 --- a/idempo.gemspec +++ b/idempo.gemspec @@ -36,7 +36,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem - spec.add_dependency "rack" + spec.add_dependency "rack", "~> #{ENV.fetch('IDEMPO_RACK_VERSION', '3.0')}" spec.add_dependency "msgpack" spec.add_dependency "measurometer", "~> 1.3" @@ -45,7 +45,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "redis", "~> 4" spec.add_development_dependency "rack-test" spec.add_development_dependency "activerecord" - spec.add_development_dependency "mysql2" + #spec.add_development_dependency "mysql2" spec.add_development_dependency "pg" spec.add_development_dependency "standard" diff --git a/lib/idempo.rb b/lib/idempo.rb index 93abf28..a240715 100644 --- a/lib/idempo.rb +++ b/lib/idempo.rb @@ -7,6 +7,7 @@ require "msgpack" require "zlib" require "set" +require 'rack' require "idempo/version" @@ -55,9 +56,11 @@ def call(env) end status, headers, body = @app.call(env) - # `body` could be of type `ActionDispatch::Response::RackBody` and idempo will not even attempt to store it, - # we're converting ActionDispatch::Response::RackBody to a storable array format. - body = body.try(:to_ary) || body + if Gem::Version.new(Rack.release) >= Gem::Version.new('3.0') + # `body` could be of type `ActionDispatch::Response::RackBody` and idempo will not even attempt to store it, + # we're converting ActionDispatch::Response::RackBody to a storable array format. + body = body.try(:to_ary) if body.respond_to?(:to_ary) + end expires_in_seconds = (headers.delete("X-Idempo-Persist-For-Seconds") || @persist_for_seconds).to_i if response_may_be_persisted?(status, headers, body)