public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
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: Michael Koziarski <michael@koziarski.com>
[#111 state:resolved]
yizzreel (author)
Mon May 05 00:53:30 -0700 2008
NZKoz (committer)
Tue May 06 02:48:07 -0700 2008
commit  2c39836dc3c06813fce031d1bb390149b53ebd1c
tree    84a6e5a1f873ed3eedebc5722890a4a7adabbf41
parent  8ded457b1b31b157d6fe89b553749579e5ac4a27
...
524
525
526
527
528
529
530
531
 
 
 
532
533
534
...
524
525
526
 
 
 
 
 
527
528
529
530
531
532
0
@@ -524,11 +524,9 @@ module ActionController
0
         resource.member_methods.each do |method, actions|
0
           actions.each do |action|
0
             action_options = action_options_for(action, resource, method)
0
-            action_path = action
0
-            if resource.options[:path_names]
0
-              action_path = resource.options[:path_names][action]
0
-              action_path ||= Base.resources_path_names[action] || action
0
-            end
0
+
0
+            action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
0
+            action_path ||= Base.resources_path_names[action] || action
0
 
0
             map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
0
             map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
...
226
227
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
230
231
...
691
692
693
694
695
 
 
696
697
698
 
 
699
700
701
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
...
713
714
715
 
 
716
717
718
 
 
719
720
721
722
723
0
@@ -226,6 +226,28 @@ class ResourcesTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  def test_member_when_changed_default_restful_actions_and_path_names_not_specified
0
+    default_path_names = ActionController::Base.resources_path_names
0
+    ActionController::Base.resources_path_names = {:new => 'nuevo', :edit => 'editar'}
0
+
0
+    with_restful_routing :messages do
0
+      new_options = { :action => 'new', :controller => 'messages' }
0
+      new_path = "/messages/nuevo"
0
+      edit_options = { :action => 'edit', :id => '1', :controller => 'messages' }
0
+      edit_path = "/messages/1/editar"
0
+
0
+      assert_restful_routes_for :messages do |options|
0
+        assert_recognizes(options.merge(new_options), :path => new_path, :method => :get)
0
+      end
0
+
0
+      assert_restful_routes_for :messages do |options|
0
+        assert_recognizes(options.merge(edit_options), :path => edit_path, :method => :get)
0
+      end
0
+    end
0
+  ensure
0
+    ActionController::Base.resources_path_names = default_path_names
0
+  end
0
+
0
   def test_with_two_member_actions_with_same_method
0
     [:put, :post].each do |method|
0
       with_restful_routing :messages, :member => { :mark => method, :unmark => method } do
0
@@ -691,11 +713,11 @@ class ResourcesTest < Test::Unit::TestCase
0
       options[:options] ||= {}
0
       options[:options][:controller] = options[:controller] || controller_name.to_s
0
 
0
-      new_action    = "new"
0
-      edit_action   = "edit"
0
+      new_action    = ActionController::Base.resources_path_names[:new] || "new"
0
+      edit_action   = ActionController::Base.resources_path_names[:edit] || "edit"
0
       if options[:path_names]
0
-        new_action  = options[:path_names][:new]  || "new"
0
-        edit_action = options[:path_names][:edit] || "edit"
0
+        new_action  = options[:path_names][:new] if options[:path_names][:new]
0
+        edit_action = options[:path_names][:edit] if options[:path_names][:edit]
0
       end
0
 
0
       collection_path            = "/#{options[:path_prefix]}#{options[:as] || controller_name}"

Comments