From a8c824733dd1b91aceac16c86d4d5494d4546389 Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Tue, 1 Sep 2026 20:13:33 +0100 Subject: [PATCH 1/4] Enable Ruby 4.1 tests --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4b36ffe..31c8c87c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,7 @@ jobs: - '3.3' - '3.4' - '4.0' + - 'ruby-head' steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 - name: Set up Ruby From d5c410aabe02121af3e27d28f381959b25f6ccfe Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Tue, 1 Sep 2026 20:27:30 +0100 Subject: [PATCH 2/4] Avoid mutating strings --- lib/rage/router/dsl.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rage/router/dsl.rb b/lib/rage/router/dsl.rb index e040f9db..02a4752d 100644 --- a/lib/rage/router/dsl.rb +++ b/lib/rage/router/dsl.rb @@ -420,11 +420,11 @@ def mount(app, at:, via: :all) at = at.delete_suffix("/") if at.end_with?("/") http_methods = if via == :all || via.nil? - @default_match_methods.map { |method| method.to_s.upcase! } + @default_match_methods.map { |method| method.to_s.upcase } else - Array(via).map! do |method| + Array(via).map do |method| raise ArgumentError, "Invalid HTTP method: #{method}" unless @default_match_methods.include?(method) - method.to_s.upcase! + method.to_s.upcase end end From 94ad6e069da5cbbd42d7b49a087e433fc4c158b5 Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Tue, 1 Sep 2026 20:27:49 +0100 Subject: [PATCH 3/4] Remove unnecessary caching --- lib/rage/router/dsl.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/rage/router/dsl.rb b/lib/rage/router/dsl.rb index 02a4752d..acdd8c4a 100644 --- a/lib/rage/router/dsl.rb +++ b/lib/rage/router/dsl.rb @@ -501,8 +501,7 @@ def __resource_scope(resource, path, mod, &block) end def to_singular(str) - @active_support_loaded ||= str.respond_to?(:singularize) || :false - return str.singularize if @active_support_loaded != :false + return str.singularize if str.respond_to?(:singularize) @endings ||= { "ves" => "fe", @@ -519,8 +518,7 @@ def to_singular(str) end def to_plural(str) - @active_support_loaded ||= str.respond_to?(:pluralize) || :false - return str.pluralize if @active_support_loaded != :false + return str.pluralize if str.respond_to?(:pluralize) str.end_with?("s") ? str : "#{str}s" end From 3d8778977e944c50ad606b750c629fa38d7a7feb Mon Sep 17 00:00:00 2001 From: Roman Samoilov <2270393+rsamoilov@users.noreply.github.com> Date: Tue, 1 Sep 2026 20:29:48 +0100 Subject: [PATCH 4/4] Fix tests --- spec/openapi/parsers/ext/blueprinter_spec.rb | 16 ++++++++++++---- spec/router/dsl_spec.rb | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/openapi/parsers/ext/blueprinter_spec.rb b/spec/openapi/parsers/ext/blueprinter_spec.rb index ec21c8a6..2f6cdb81 100644 --- a/spec/openapi/parsers/ext/blueprinter_spec.rb +++ b/spec/openapi/parsers/ext/blueprinter_spec.rb @@ -883,8 +883,12 @@ end before do - allow_any_instance_of(String).to receive(:respond_to?).and_call_original - allow_any_instance_of(String).to receive(:respond_to?).with(:singularize).and_return(false) + String.alias_method(:__singularize__, :singularize) + String.undef_method(:singularize) + end + + after do + String.alias_method(:singularize, :__singularize__) end it "falls back to array, since cardinality cannot be determined without singularize" do @@ -2573,8 +2577,12 @@ end before do - allow_any_instance_of(String).to receive(:respond_to?).and_call_original - allow_any_instance_of(String).to receive(:respond_to?).with(:singularize).and_return(false) + String.alias_method(:__singularize__, :singularize) + String.undef_method(:singularize) + end + + after do + String.alias_method(:singularize, :__singularize__) end it "falls back to array, since cardinality cannot be determined without singularize" do diff --git a/spec/router/dsl_spec.rb b/spec/router/dsl_spec.rb index 69e04467..a9040e90 100644 --- a/spec/router/dsl_spec.rb +++ b/spec/router/dsl_spec.rb @@ -764,12 +764,13 @@ def call(env) end it "uses activesupport" do - allow_any_instance_of(String).to receive(:singularize).and_return("image") + _resource = +"photos" + allow(_resource).to receive(:singularize).and_return("image") expect(router).to receive(:on).with("POST", "/photos/:image_id/mark", "photos#mark", instance_of(Hash)) dsl.draw do - resources :photos, only: [] do + resources _resource, only: [] do post :mark end end