Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4755

Show
Ignore:
Timestamp:
08/13/06 04:15:22 (2 years ago)
Author:
ulysses
Message:

Invoke method_missing directly for hidden actions. Closes #3030.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4734 r4755  
    11*SVN* 
     2 
     3* Invoke method_missing directly on hidden actions. Closes #3030. [Nicholas Seckar] 
    24 
    35* Require Tempfile explicitly for TestUploadedFile due to changes in class auto loading.  [Rick Olson] 
  • trunk/actionpack/lib/action_controller/base.rb

    r4728 r4755  
    975975        end 
    976976      end 
    977      
     977       
    978978      def perform_action 
    979         if self.class.action_methods.include?(action_name) || self.class.action_methods.include?('method_missing') 
     979        if self.class.action_methods.include?(action_name) 
    980980          send(action_name) 
     981          render unless performed? 
     982        elsif respond_to? :method_missing 
     983          send(:method_missing, action_name) 
    981984          render unless performed? 
    982985        elsif template_exists? && template_public? 
  • trunk/actionpack/test/controller/base_test.rb

    r4664 r4755  
    1313    hide_action :hidden_action 
    1414    def hidden_action 
     15      raise "Noooo!" 
    1516    end 
    1617     
     
    3233  def hidden_action 
    3334  end 
     35end 
     36 
     37class MethodMissingController < ActionController::Base 
     38   
     39  hide_action :shouldnt_be_called 
     40  def shouldnt_be_called 
     41    raise "NO WAY!" 
     42  end 
     43   
     44protected 
     45   
     46  def method_missing(selector) 
     47    render :text => selector.to_s 
     48  end 
     49   
    3450end 
    3551 
     
    6581    end 
    6682  end 
     83   
    6784end 
     85 
     86 
     87class PerformActionTest < Test::Unit::TestCase 
     88  def use_controller(controller_class) 
     89    @controller = controller_class.new 
     90 
     91    # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get 
     92    # a more accurate simulation of what happens in "real life". 
     93    @controller.logger = Logger.new(nil) 
     94 
     95    @request    = ActionController::TestRequest.new 
     96    @response   = ActionController::TestResponse.new 
     97 
     98    @request.host = "www.nextangle.com" 
     99  end 
     100   
     101  def test_get_on_priv_should_show_selector 
     102    use_controller MethodMissingController 
     103    get :shouldnt_be_called 
     104    assert_response :success 
     105    assert_equal 'shouldnt_be_called', @response.body 
     106  end 
     107   
     108  def test_method_missing_is_not_an_action_name 
     109    use_controller MethodMissingController 
     110    assert ! @controller.send(:action_methods).include?('method_missing') 
     111     
     112    get :method_missing 
     113    assert_response :success 
     114    assert_equal 'method_missing', @response.body 
     115  end 
     116   
     117  def test_get_on_hidden_should_fail 
     118    use_controller NonEmptyController 
     119    get :hidden_action 
     120    assert_response 404 
     121     
     122    get :another_hidden_action 
     123    assert_response 404 
     124  end 
     125end