diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-05-06 12:16:55 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-06 12:16:55 +0100 |
commit | 63e8bcaeb31443cecc5bef5762a45643cc12d481 (patch) | |
tree | 57800132eecace875b1701b79883d179dfb8c021 /actionpack | |
parent | 4a0118d7278687b534edf1e1184d6858cb4d29b8 (diff) | |
parent | e520fd5db7cb839b862c03647effee50f9223d98 (diff) | |
download | rails-63e8bcaeb31443cecc5bef5762a45643cc12d481.tar.gz rails-63e8bcaeb31443cecc5bef5762a45643cc12d481.tar.bz2 rails-63e8bcaeb31443cecc5bef5762a45643cc12d481.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/base.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/new_render_test.rb | 9 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 30 |
4 files changed, 39 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index f686d78ee3..26f75780c1 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -524,11 +524,9 @@ module ActionController 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) diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index a6da81de07..d32c6fbe35 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -185,7 +185,7 @@ module ActionView #:nodoc: attr_internal :request delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers, - :flash, :logger, :to => :controller + :flash, :logger, :action_name, :to => :controller module CompiledTemplates #:nodoc: # holds compiled template code diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index 8e39057f55..6e2c6d90c6 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -246,6 +246,10 @@ class NewRenderTestController < ActionController::Base def accessing_logger_in_template render :inline => "<%= logger.class %>" end + + def accessing_action_name_in_template + render :inline => "<%= action_name %>" + end def accessing_params_in_template_with_layout render :layout => nil, :inline => "Hello: <%= params[:name] %>" @@ -545,6 +549,11 @@ class NewRenderTest < Test::Unit::TestCase get :accessing_logger_in_template assert_equal "Logger", @response.body end + + def test_access_to_action_name_in_view + get :accessing_action_name_in_template + assert_equal "accessing_action_name_in_template", @response.body + end def test_render_xml get :render_xml_hello diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index b138cee29f..0d089d0f23 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -226,6 +226,28 @@ class ResourcesTest < Test::Unit::TestCase 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 @@ class ResourcesTest < Test::Unit::TestCase 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}" |