Skip to content

Commit

Permalink
Remove code duplication and improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 15, 2024
1 parent 0821d25 commit a39332f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,21 @@ def normalize_options!(options, path_params, modyoule)

if to.respond_to?(:action) || to.respond_to?(:call)
options
elsif to.nil?
controller = default_controller
action = default_action

controller = add_controller_module(controller, modyoule)

options.merge! check_controller_and_action(path_params, controller, action)
elsif to.is_a?(String) && to.include?("#")
to_endpoint = to.split("#").map!(&:-@)
controller = to_endpoint[0]
action = to_endpoint[1]
else
if to.nil?
controller = default_controller
action = default_action
elsif to.is_a?(String) && to.include?("#")
to_endpoint = to.split("#").map!(&:-@)
controller = to_endpoint[0]
action = to_endpoint[1]
else
raise ArgumentError, ":to must respond to `action` or `call`, or it must be a String that includes '#'"
end

controller = add_controller_module(controller, modyoule)

options.merge! check_controller_and_action(path_params, controller, action)
else
raise ArgumentError, ":to must respond_to? :action or :call, or it must be a String that includes '#'"
end
end

Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4054,7 +4054,7 @@ def test_missing_controller_with_to
get "/foo/bar", to: "foo"
end
}
assert_match(/:to must respond_to/, ex.message)
assert_match(/:to must respond to/, ex.message)
end

def test_to_is_a_symbol
Expand All @@ -4063,7 +4063,7 @@ def test_to_is_a_symbol
get "/foo/bar", to: :foo
end
}
assert_match(/:to must respond_to/, ex.message)
assert_match(/:to must respond to/, ex.message)
end

def test_missing_action_on_hash
Expand Down

0 comments on commit a39332f

Please sign in to comment.