From 50826c98fa9c98ab9a1bfd1de7c99e35370b42e7 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Tue, 31 Dec 2024 20:34:53 -0700 Subject: [PATCH] Add Ruby 3.4 support (#276) * Add csv to dependencies * Add Ruby 3.4's Hash#inspect symbol change, rename file to fix typo * Add Ruby 3.4 to CI matrix --- .github/workflows/ci.yml | 1 + hanami-router.gemspec | 1 + ...pec.rb => body_parsing_middleware_spec.rb} | 49 ++++++++++++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) rename spec/integration/hanami/router/{body_parsing_middelware_spec.rb => body_parsing_middleware_spec.rb} (71%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be5abcb5..95e0d216 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: fail-fast: false matrix: ruby: + - "3.4" - "3.3" - "3.2" - "3.1" diff --git a/hanami-router.gemspec b/hanami-router.gemspec index c8be1458..4160a6cb 100644 --- a/hanami-router.gemspec +++ b/hanami-router.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |spec| spec.add_dependency "rack", "~> 2.0" spec.add_dependency "mustermann", "~> 3.0" spec.add_dependency "mustermann-contrib", "~> 3.0" + spec.add_dependency "csv", "~> 3.3" spec.add_development_dependency "bundler", ">= 1.6", "< 3" spec.add_development_dependency "rake", "~> 13" diff --git a/spec/integration/hanami/router/body_parsing_middelware_spec.rb b/spec/integration/hanami/router/body_parsing_middleware_spec.rb similarity index 71% rename from spec/integration/hanami/router/body_parsing_middelware_spec.rb rename to spec/integration/hanami/router/body_parsing_middleware_spec.rb index c00932d1..f4af682b 100644 --- a/spec/integration/hanami/router/body_parsing_middelware_spec.rb +++ b/spec/integration/hanami/router/body_parsing_middleware_spec.rb @@ -36,7 +36,12 @@ response = @app.patch("/books/23", "CONTENT_TYPE" => "application/json", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:published=>"true", :id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:published=>"true", :id=>"23"})) + else + expect(response.body).to eq(%({published: "true", id: "23"})) + end end # See https://github.com/hanami/router/issues/124 @@ -45,7 +50,12 @@ response = @app.patch("/books/23", "CONTENT_TYPE" => "application/json", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:id=>"23"})) + else + expect(response.body).to eq(%({id: "23"})) + end end it "is successful (JSON as array)" do @@ -53,7 +63,12 @@ response = @app.patch("/books/23", "CONTENT_TYPE" => "application/json", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:_=>["alpha", "beta"], :id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:_=>["alpha", "beta"], :id=>"23"})) + else + expect(response.body).to eq(%({_: ["alpha", "beta"], id: "23"})) + end end # See https://github.com/hanami/utils/issues/169 @@ -62,7 +77,12 @@ response = @app.patch("/books/23", "CONTENT_TYPE" => "application/json", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:json_class=>"Foo", :id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:json_class=>"Foo", :id=>"23"})) + else + expect(response.body).to eq(%({json_class: "Foo", id: "23"})) + end end it "is idempotent" do @@ -71,7 +91,12 @@ response = @app.patch("/books/23", "CONTENT_TYPE" => "application/json", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:published=>"true", :id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:published=>"true", :id=>"23"})) + else + expect(response.body).to eq(%({published: "true", id: "23"})) + end end end end @@ -82,7 +107,12 @@ response = @app.patch("/authors/23", "CONTENT_TYPE" => "application/xml", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:name=>"LG", :id=>"23"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:name=>"LG", :id=>"23"})) + else + expect(response.body).to eq(%({name: "LG", id: "23"})) + end end it "is successful (XML aliased mime)" do @@ -90,7 +120,12 @@ response = @app.patch("/authors/15", "CONTENT_TYPE" => "text/xml", "rack.input" => body, lint: true) expect(response.status).to eq(200) - expect(response.body).to eq(%({:name=>"MGF", :id=>"15"})) + + if RUBY_VERSION < "3.4" + expect(response.body).to eq(%({:name=>"MGF", :id=>"15"})) + else + expect(response.body).to eq(%({name: "MGF", id: "15"})) + end end end end