Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- '3.3'
- '3.4'
- '4.0'
- 'ruby-head'
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
- name: Set up Ruby
Expand Down
12 changes: 5 additions & 7 deletions lib/rage/router/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions spec/openapi/parsers/ext/blueprinter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions spec/router/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading