提交 2c39836d 编写于 作者: M Marcos Arias 提交者: Michael Koziarski

Refactored and fixed Resources.map_member_actions to make use of custom...

Refactored and fixed Resources.map_member_actions to make use of custom ActionController::Base.resources_path_names when the option :path_names is not directly specified. Added a specific test for this functionality and fixed assert_restful_routes_for test helper to make use of ActionController::Base.resources_path_names instead of just "new" or "edit".
Signed-off-by: NMichael Koziarski <michael@koziarski.com>
[#111 state:resolved]
上级 8ded457b
......@@ -524,11 +524,9 @@ def map_member_actions(map, resource)
resource.member_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
action_path = action
if resource.options[:path_names]
action_path = resource.options[:path_names][action]
action_path ||= Base.resources_path_names[action] || action
end
action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
action_path ||= Base.resources_path_names[action] || action
map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
......
......@@ -226,6 +226,28 @@ def test_member_when_override_paths_for_default_restful_actions_with
end
end
def test_member_when_changed_default_restful_actions_and_path_names_not_specified
default_path_names = ActionController::Base.resources_path_names
ActionController::Base.resources_path_names = {:new => 'nuevo', :edit => 'editar'}
with_restful_routing :messages do
new_options = { :action => 'new', :controller => 'messages' }
new_path = "/messages/nuevo"
edit_options = { :action => 'edit', :id => '1', :controller => 'messages' }
edit_path = "/messages/1/editar"
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(new_options), :path => new_path, :method => :get)
end
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(edit_options), :path => edit_path, :method => :get)
end
end
ensure
ActionController::Base.resources_path_names = default_path_names
end
def test_with_two_member_actions_with_same_method
[:put, :post].each do |method|
with_restful_routing :messages, :member => { :mark => method, :unmark => method } do
......@@ -691,11 +713,11 @@ def assert_restful_routes_for(controller_name, options = {})
options[:options] ||= {}
options[:options][:controller] = options[:controller] || controller_name.to_s
new_action = "new"
edit_action = "edit"
new_action = ActionController::Base.resources_path_names[:new] || "new"
edit_action = ActionController::Base.resources_path_names[:edit] || "edit"
if options[:path_names]
new_action = options[:path_names][:new] || "new"
edit_action = options[:path_names][:edit] || "edit"
new_action = options[:path_names][:new] if options[:path_names][:new]
edit_action = options[:path_names][:edit] if options[:path_names][:edit]
end
collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册