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 diff --git a/lib/rage/router/dsl.rb b/lib/rage/router/dsl.rb index e040f9db..acdd8c4a 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 @@ -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 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