Skip to content

Commit a39332f

Browse files
committed
Remove code duplication and improve message
1 parent 0821d25 commit a39332f

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,23 +216,21 @@ def normalize_options!(options, path_params, modyoule)
216216

217217
if to.respond_to?(:action) || to.respond_to?(:call)
218218
options
219-
elsif to.nil?
220-
controller = default_controller
221-
action = default_action
222-
223-
controller = add_controller_module(controller, modyoule)
224-
225-
options.merge! check_controller_and_action(path_params, controller, action)
226-
elsif to.is_a?(String) && to.include?("#")
227-
to_endpoint = to.split("#").map!(&:-@)
228-
controller = to_endpoint[0]
229-
action = to_endpoint[1]
219+
else
220+
if to.nil?
221+
controller = default_controller
222+
action = default_action
223+
elsif to.is_a?(String) && to.include?("#")
224+
to_endpoint = to.split("#").map!(&:-@)
225+
controller = to_endpoint[0]
226+
action = to_endpoint[1]
227+
else
228+
raise ArgumentError, ":to must respond to `action` or `call`, or it must be a String that includes '#'"
229+
end
230230

231231
controller = add_controller_module(controller, modyoule)
232232

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

actionpack/test/dispatch/routing_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,7 +4054,7 @@ def test_missing_controller_with_to
40544054
get "/foo/bar", to: "foo"
40554055
end
40564056
}
4057-
assert_match(/:to must respond_to/, ex.message)
4057+
assert_match(/:to must respond to/, ex.message)
40584058
end
40594059

40604060
def test_to_is_a_symbol
@@ -4063,7 +4063,7 @@ def test_to_is_a_symbol
40634063
get "/foo/bar", to: :foo
40644064
end
40654065
}
4066-
assert_match(/:to must respond_to/, ex.message)
4066+
assert_match(/:to must respond to/, ex.message)
40674067
end
40684068

40694069
def test_missing_action_on_hash

0 commit comments

Comments
 (0)