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

Changeset 5201

Show
Ignore:
Timestamp:
09/29/06 07:34:02 (2 years ago)
Author:
bitsweat
Message:

Deprecation: @request will be removed after 1.2. Use the request method instead.

Files:

Legend:

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

    r5199 r5201  
    11*SVN* 
     2 
     3* Deprecation: @request will be removed after 1.2. Use the request method instead.  [Jeremy Kemper] 
    24 
    35* Make the :status parameter expand to the default message for that status code if it is an integer. Also support symbol statuses. [Jamis Buck]. Examples: 
  • trunk/actionpack/lib/action_controller/base.rb

    r5200 r5201  
    295295    # Holds the request object that's primarily used to get environment variables through access like 
    296296    # <tt>request.env["REQUEST_URI"]</tt>. 
    297     attr_accessor :request 
     297    attr_internal :request 
    298298 
    299299    # Holds a hash of all the GET, POST, and Url parameters passed to the action. Accessed like <tt>params["post_id"]</tt> 
     
    10151015 
    10161016      def assign_shortcuts(request, response) 
    1017         @request, @_params, @cookies = request, request.parameters, request.cookies 
     1017        @_request, @_params, @cookies = request, request.parameters, request.cookies 
    10181018 
    10191019        @response         = response 
     
    10311031 
    10321032      # TODO: assigns cookies headers params request response template 
    1033       DEPRECATED_INSTANCE_VARIABLES = %w(flash params session) 
     1033      DEPRECATED_INSTANCE_VARIABLES = %w(flash params request session) 
    10341034 
    10351035      # Gone after 1.2. 
     
    11291129        else 
    11301130          %w(@assigns @performed_redirect @performed_render 
    1131              @request @response @_params @_session @session 
     1131             @_request @request @response @_params @params @_session @session 
    11321132             @cookies @template @request_origin @parent_controller) 
    11331133        end 
  • trunk/actionpack/lib/action_controller/components.rb

    r4699 r5201  
    140140          end 
    141141        end 
    142          
     142 
    143143        # Create a new request object based on the current request. 
    144144        # The new request inherits the session from the current request, 
    145145        # bypassing any session options set for the component controller's class 
    146146        def request_for_component(controller_name, options) 
    147           request         = @request.dup 
    148           request.session = @request.session 
    149          
    150           request.instance_variable_set( 
     147          new_request         = request.dup 
     148          new_request.session = request.session 
     149 
     150          new_request.instance_variable_set( 
    151151            :@parameters, 
    152152            (options[:params] || {}).with_indifferent_access.update( 
     
    154154            ) 
    155155          ) 
    156            
    157           request 
     156 
     157          new_request 
    158158        end 
    159159 
  • trunk/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml

    r4158 r5201  
    11<h1> 
    22  <%=h @exception.class.to_s %> 
    3   <% if @request.parameters['controller'] %> 
    4     in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %> 
     3  <% if request.parameters['controller'] %> 
     4    in <%=h request.parameters['controller'].humanize %>Controller<% if request.parameters['action'] %>#<%=h request.parameters['action'] %><% end %> 
    55  <% end %> 
    66</h1> 
  • trunk/actionpack/lib/action_controller/verification.rb

    r4996 r5201  
    8686      if !prereqs_invalid && options[:method] 
    8787        prereqs_invalid ||=  
    88           [*options[:method]].all? { |v| @request.method != v.to_sym } 
     88          [*options[:method]].all? { |v| request.method != v.to_sym } 
    8989      end 
    9090       
  • trunk/actionpack/lib/action_view/base.rb

    r5129 r5201  
    148148    attr_accessor :controller 
    149149 
    150     attr_reader :logger, :request, :response, :headers 
    151     attr_internal :flash, :params, :session 
     150    attr_reader :logger, :response, :headers 
     151    attr_internal *ActionController::Base::DEPRECATED_INSTANCE_VARIABLES 
    152152 
    153153    # Specify trim mode for the ERB compiler. Defaults to '-'. 
     
    441441          body = case extension.to_sym 
    442442            when :rxml 
    443               "@controller.response.content_type ||= 'application/xml'\n" + 
     443              "controller.response.content_type ||= 'application/xml'\n" + 
    444444              "xml = Builder::XmlMarkup.new(:indent => 2)\n" + 
    445445              template 
    446446            when :rjs 
    447               "@controller.response.content_type ||= 'text/javascript'\n" + 
     447              "controller.response.content_type ||= 'text/javascript'\n" + 
    448448              "update_page do |page|\n#{template}\nend" 
    449449          end 
  • trunk/actionpack/test/controller/action_pack_assertions_test.rb

    r5129 r5201  
    1212  # a standard template 
    1313  def hello_xml_world() render "test/hello_xml_world"; end 
    14   
     14 
    1515  # a redirect to an internal location 
    1616  def redirect_internal() redirect_to "/nothing"; end 
     
    2323 
    2424  def redirect_to_named_route() redirect_to route_one_url end 
    25    
     25 
    2626  # a redirect to an external location 
    2727  def redirect_external() redirect_to_url "http://www.rubyonrails.org"; end 
    28    
     28 
    2929  # a 404 
    3030  def response404() render_text "", "404 AWOL"; end 
     
    7171    render_text "ho ho ho" 
    7272  end 
    73    
     73 
    7474  # raises exception on get requests 
    7575  def raise_on_get 
    76     raise "get" if @request.get? 
    77     render_text "request method: #{@request.env['REQUEST_METHOD']}" 
     76    raise "get" if request.get? 
     77    render_text "request method: #{request.env['REQUEST_METHOD']}" 
    7878  end 
    7979 
    8080  # raises exception on post requests 
    8181  def raise_on_post 
    82     raise "post" if @request.post? 
    83     render_text "request method: #{@request.env['REQUEST_METHOD']}" 
    84   end        
    85    
     82    raise "post" if request.post? 
     83    render_text "request method: #{request.env['REQUEST_METHOD']}" 
     84  end 
     85 
    8686  def get_valid_record 
    87     @record = Class.new do        
     87    @record = Class.new do 
    8888      def valid? 
    8989        true 
     
    9191 
    9292      def errors 
    93         Class.new do  
    94            def full_messages; []; end           
     93        Class.new do 
     94           def full_messages; []; end 
    9595        end.new 
    96       end     
    97      
     96      end 
     97 
    9898    end.new 
    99          
    100     render :nothing => true     
     99 
     100    render :nothing => true 
    101101  end 
    102102 
    103103 
    104104  def get_invalid_record 
    105     @record = Class.new do  
    106        
     105    @record = Class.new do 
     106 
    107107      def valid? 
    108108        false 
    109109      end 
    110        
     110 
    111111      def errors 
    112         Class.new do  
    113            def full_messages; ['...stuff...']; end           
     112        Class.new do 
     113           def full_messages; ['...stuff...']; end 
    114114        end.new 
    115115      end 
    116     end.new                 
    117      
    118     render :nothing => true     
     116    end.new 
     117 
     118    render :nothing => true 
    119119  end 
    120120 
     
    146146 
    147147 
    148 # tell the controller where to find its templates but start from parent  
    149 # directory of test_request_response to simulate the behaviour of a  
     148# tell the controller where to find its templates but start from parent 
     149# directory of test_request_response to simulate the behaviour of a 
    150150# production environment 
    151151ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" 
     
    154154# a test case to exercise the new capabilities TestRequest & TestResponse 
    155155class ActionPackAssertionsControllerTest < Test::Unit::TestCase 
    156   # let's get this party started   
     156  # let's get this party started 
    157157  def setup 
    158158    @controller = ActionPackAssertionsController.new 
    159159    @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 
    160160  end 
    161   
     161 
    162162  # -- assertion-based testing ------------------------------------------------ 
    163163 
     
    173173    assert_deprecated_assertion { assert_session_has_no 'halloween' } 
    174174  end 
    175    
     175 
    176176  # test the get method, make sure the request really was a get 
    177177  def test_get 
     
    187187    assert_equal @response.body, 'request method: POST' 
    188188  end 
    189    
     189 
    190190#   the following test fails because the request_method is now cached on the request instance 
    191191#   test the get/post switch within one test action 
     
    213213    assert_deprecated_assertion { assert_template_has_no 'howdy' } 
    214214  end 
    215    
     215 
    216216  # test the redirection assertions 
    217217  def test_assert_redirect 
     
    235235    end 
    236236  end 
    237    
     237 
    238238  # test the redirection pattern matching on a pattern 
    239239  def test_assert_redirect_url_match_pattern 
     
    313313    assert_deprecated_assertion { assert_flash_has_no 'qwerty' } 
    314314  end 
    315    
    316   # test the assert_rendered_file  
     315 
     316  # test the assert_rendered_file 
    317317  def test_assert_rendered_file 
    318318    assert_deprecated(/render/) { process :hello_world } 
     
    320320    assert_deprecated_assertion { assert_rendered_file 'hello_world' } 
    321321  end 
    322    
     322 
    323323  # test the assert_success assertion 
    324324  def test_assert_success 
     
    326326    assert_deprecated_assertion { assert_success } 
    327327  end 
    328    
     328 
    329329  # -- standard request/response object testing -------------------------------- 
    330   
     330 
    331331  # ensure our session is working properly 
    332332  def test_session_objects 
     
    336336    assert !@response.has_session_object?('easter') 
    337337  end 
    338    
     338 
    339339  # make sure that the template objects exist 
    340340  def test_template_objects_alive 
     
    343343    assert @response.has_template_object?('howdy') 
    344344  end 
    345    
     345 
    346346  # make sure we don't have template objects when we shouldn't 
    347347  def test_template_object_missing 
     
    349349    assert_nil @response.template_objects['howdy'] 
    350350  end 
    351    
     351 
    352352  def test_assigned_equal 
    353353    process :assign_this 
     
    377377    assert_nil @response.flash['hello'] 
    378378  end 
    379    
     379 
    380380  # examine that the flash objects are what we expect 
    381381  def test_flash_equals 
     
    385385    end 
    386386  end 
    387    
    388   # check if we were rendered by a file-based template?  
     387 
     388  # check if we were rendered by a file-based template? 
    389389  def test_rendered_action 
    390390    process :nothing 
     
    395395    assert 'hello_world', @response.rendered_file 
    396396  end 
    397    
     397 
    398398  # check the redirection location 
    399399  def test_redirection_location 
     
    407407    assert_nil @response.redirect_url 
    408408  end 
    409    
    410   
    411   # check server errors  
     409 
     410 
     411  # check server errors 
    412412  def test_server_error_response_code 
    413413    process :response500 
    414414    assert @response.server_error? 
    415      
     415 
    416416    process :response599 
    417417    assert @response.server_error? 
    418      
     418 
    419419    process :response404 
    420420    assert !@response.server_error? 
    421421  end 
    422    
     422 
    423423  # check a 404 response code 
    424424  def test_missing_response_code 
     
    436436    assert !@response.redirect_url_match?(/perloffrails/) 
    437437  end 
    438    
     438 
    439439  # check for a redirection 
    440440  def test_redirection 
     
    448448    assert !@response.redirect? 
    449449  end 
    450    
     450 
    451451  # check a successful response code 
    452452  def test_successful_response_code 
    453453    process :nothing 
    454454    assert @response.success? 
    455   end  
    456    
     455  end 
     456 
    457457  # a basic check to make sure we have a TestResponse object 
    458458  def test_has_response 
     
    460460    assert_kind_of ActionController::TestResponse, @response 
    461461  end 
    462    
     462 
    463463  def test_render_based_on_parameters 
    464464    process :render_based_on_parameters, "name" => "David" 
     
    492492    process :redirect_to_action 
    493493    assert_redirected_to :action => "flash_me" 
    494      
     494 
    495495    follow_redirect 
    496496    assert_equal 1, @request.parameters["id"].to_i 
     
    535535    get :redirect_to_absolute_controller 
    536536    assert_redirected_to :controller => 'content' 
    537      
     537 
    538538    get :redirect_to_fellow_controller 
    539539    assert_redirected_to :controller => 'admin/user' 
    540   end                  
    541    
     540  end 
     541 
    542542  def test_assert_valid 
    543543    get :get_valid_record 
    544     assert_valid assigns('record')     
    545   end                 
    546    
     544    assert_valid assigns('record') 
     545  end 
     546 
    547547  def test_assert_valid_failing 
    548548    get :get_invalid_record 
    549      
     549 
    550550    begin 
    551       assert_valid assigns('record')     
     551      assert_valid assigns('record') 
    552552      assert false 
    553     rescue Test::Unit::AssertionFailedError => e              
     553    rescue Test::Unit::AssertionFailedError => e 
    554554    end 
    555555  end 
     
    561561end 
    562562 
    563 class ActionPackHeaderTest < Test::Unit::TestCase   
     563class ActionPackHeaderTest < Test::Unit::TestCase 
    564564  def setup 
    565565    @controller = ActionPackAssertionsController.new 
     
    578578  end 
    579579 
    580    
     580 
    581581  def test_render_text_with_custom_content_type 
    582582    get :render_text_with_custom_content_type 
  • trunk/actionpack/test/controller/new_render_test.rb

    r5200 r5201  
    423423 
    424424    get :hello_world 
    425     assert_nil(assigns["request"]) 
     425    assert !assigns.include?('request'), 'request should not be in assigns' 
    426426 
    427427    ActionController::Base.view_controller_internals = true 
     
    429429 
    430430    get :hello_world 
    431     assert_kind_of ActionController::AbstractRequest, assigns["request"] 
    432  
     431    assert assigns.include?('request'), 'request should be in assigns' 
     432    assert_deprecated 'request' do 
     433      assert_kind_of ActionController::AbstractRequest, assigns['request'] 
     434    end 
     435    assert_not_deprecated do 
     436      assert_kind_of ActionController::AbstractRequest, @response.template.request 
     437      assert_kind_of ActionController::AbstractRequest, assigns['_request'] 
     438    end 
     439 
     440  ensure 
    433441    ActionController::Base.view_controller_internals = view_internals_old_value 
    434442    ActionController::Base.protected_variables_cache = nil 
    435443  end 
    436    
     444 
    437445  def test_render_xml 
    438446    get :render_xml_hello 
  • trunk/actionpack/test/controller/render_test.rb

    r5044 r5201  
    169169  end 
    170170 
    171   def test_access_to_request_in_view 
    172     view_internals_old_value = ActionController::Base.view_controller_internals 
    173  
    174     ActionController::Base.view_controller_internals = false 
    175     ActionController::Base.protected_variables_cache = nil 
    176  
    177     get :hello_world 
    178     assert_nil assigns["request"] 
    179  
    180     ActionController::Base.view_controller_internals = true 
    181     ActionController::Base.protected_variables_cache = nil 
    182  
    183     get :hello_world 
    184     assert_kind_of ActionController::AbstractRequest,  assigns["request"] 
    185  
    186     ActionController::Base.view_controller_internals = view_internals_old_value 
    187     ActionController::Base.protected_variables_cache = nil 
    188   end 
    189  
    190171  def test_render_xml 
    191172    assert_deprecated_render { get :render_xml_hello } 
  • trunk/actionpack/test/controller/verification_test.rb

    r5196 r5201  
    6060 
    6161    def guarded_by_method 
    62       render :text => "#{@request.method}" 
     62      render :text => "#{request.method}" 
    6363    end 
    6464     
    6565    def guarded_by_xhr 
    66       render :text => "#{@request.xhr?}" 
     66      render :text => "#{request.xhr?}" 
    6767    end 
    6868     
    6969    def guarded_by_not_xhr 
    70       render :text => "#{@request.xhr?}" 
     70      render :text => "#{request.xhr?}" 
    7171    end 
    7272 
  • trunk/actionpack/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml

    r4824 r5201  
    1 <%= @session[:test] %> 
     1<%= @request.method %> 
  • trunk/actionpack/test/fixtures/deprecated_instance_variables/_request_method.rhtml

    r4824 r5201  
    1 <%= session[:test] %> 
     1<%= request.method %>