Changeset 5201
- Timestamp:
- 09/29/06 07:34:02 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (4 diffs)
- trunk/actionpack/lib/action_controller/components.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml (modified) (1 diff)
- trunk/actionpack/lib/action_controller/verification.rb (modified) (1 diff)
- trunk/actionpack/lib/action_view/base.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/action_pack_assertions_test.rb (modified) (27 diffs)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/render_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/verification_test.rb (modified) (1 diff)
- trunk/actionpack/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml (copied) (copied from trunk/actionpack/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml) (1 diff)
- trunk/actionpack/test/fixtures/deprecated_instance_variables/_request_method.rhtml (copied) (copied from trunk/actionpack/test/fixtures/deprecated_instance_variables/_session_method.rhtml) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r5199 r5201 1 1 *SVN* 2 3 * Deprecation: @request will be removed after 1.2. Use the request method instead. [Jeremy Kemper] 2 4 3 5 * 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 295 295 # Holds the request object that's primarily used to get environment variables through access like 296 296 # <tt>request.env["REQUEST_URI"]</tt>. 297 attr_ accessor:request297 attr_internal :request 298 298 299 299 # Holds a hash of all the GET, POST, and Url parameters passed to the action. Accessed like <tt>params["post_id"]</tt> … … 1015 1015 1016 1016 def assign_shortcuts(request, response) 1017 @ request, @_params, @cookies = request, request.parameters, request.cookies1017 @_request, @_params, @cookies = request, request.parameters, request.cookies 1018 1018 1019 1019 @response = response … … 1031 1031 1032 1032 # 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) 1034 1034 1035 1035 # Gone after 1.2. … … 1129 1129 else 1130 1130 %w(@assigns @performed_redirect @performed_render 1131 @ request @response @_params @_session @session1131 @_request @request @response @_params @params @_session @session 1132 1132 @cookies @template @request_origin @parent_controller) 1133 1133 end trunk/actionpack/lib/action_controller/components.rb
r4699 r5201 140 140 end 141 141 end 142 142 143 143 # Create a new request object based on the current request. 144 144 # The new request inherits the session from the current request, 145 145 # bypassing any session options set for the component controller's class 146 146 def request_for_component(controller_name, options) 147 request = @request.dup148 request.session = @request.session149 150 request.instance_variable_set(147 new_request = request.dup 148 new_request.session = request.session 149 150 new_request.instance_variable_set( 151 151 :@parameters, 152 152 (options[:params] || {}).with_indifferent_access.update( … … 154 154 ) 155 155 ) 156 157 request156 157 new_request 158 158 end 159 159 trunk/actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
r4158 r5201 1 1 <h1> 2 2 <%=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 %> 5 5 <% end %> 6 6 </h1> trunk/actionpack/lib/action_controller/verification.rb
r4996 r5201 86 86 if !prereqs_invalid && options[:method] 87 87 prereqs_invalid ||= 88 [*options[:method]].all? { |v| @request.method != v.to_sym }88 [*options[:method]].all? { |v| request.method != v.to_sym } 89 89 end 90 90 trunk/actionpack/lib/action_view/base.rb
r5129 r5201 148 148 attr_accessor :controller 149 149 150 attr_reader :logger, :re quest, :response, :headers151 attr_internal :flash, :params, :session150 attr_reader :logger, :response, :headers 151 attr_internal *ActionController::Base::DEPRECATED_INSTANCE_VARIABLES 152 152 153 153 # Specify trim mode for the ERB compiler. Defaults to '-'. … … 441 441 body = case extension.to_sym 442 442 when :rxml 443 " @controller.response.content_type ||= 'application/xml'\n" +443 "controller.response.content_type ||= 'application/xml'\n" + 444 444 "xml = Builder::XmlMarkup.new(:indent => 2)\n" + 445 445 template 446 446 when :rjs 447 " @controller.response.content_type ||= 'text/javascript'\n" +447 "controller.response.content_type ||= 'text/javascript'\n" + 448 448 "update_page do |page|\n#{template}\nend" 449 449 end trunk/actionpack/test/controller/action_pack_assertions_test.rb
r5129 r5201 12 12 # a standard template 13 13 def hello_xml_world() render "test/hello_xml_world"; end 14 14 15 15 # a redirect to an internal location 16 16 def redirect_internal() redirect_to "/nothing"; end … … 23 23 24 24 def redirect_to_named_route() redirect_to route_one_url end 25 25 26 26 # a redirect to an external location 27 27 def redirect_external() redirect_to_url "http://www.rubyonrails.org"; end 28 28 29 29 # a 404 30 30 def response404() render_text "", "404 AWOL"; end … … 71 71 render_text "ho ho ho" 72 72 end 73 73 74 74 # raises exception on get requests 75 75 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']}" 78 78 end 79 79 80 80 # raises exception on post requests 81 81 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 86 86 def get_valid_record 87 @record = Class.new do 87 @record = Class.new do 88 88 def valid? 89 89 true … … 91 91 92 92 def errors 93 Class.new do 94 def full_messages; []; end 93 Class.new do 94 def full_messages; []; end 95 95 end.new 96 end 97 96 end 97 98 98 end.new 99 100 render :nothing => true 99 100 render :nothing => true 101 101 end 102 102 103 103 104 104 def get_invalid_record 105 @record = Class.new do 106 105 @record = Class.new do 106 107 107 def valid? 108 108 false 109 109 end 110 110 111 111 def errors 112 Class.new do 113 def full_messages; ['...stuff...']; end 112 Class.new do 113 def full_messages; ['...stuff...']; end 114 114 end.new 115 115 end 116 end.new 117 118 render :nothing => true 116 end.new 117 118 render :nothing => true 119 119 end 120 120 … … 146 146 147 147 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 150 150 # production environment 151 151 ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" … … 154 154 # a test case to exercise the new capabilities TestRequest & TestResponse 155 155 class ActionPackAssertionsControllerTest < Test::Unit::TestCase 156 # let's get this party started 156 # let's get this party started 157 157 def setup 158 158 @controller = ActionPackAssertionsController.new 159 159 @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 160 160 end 161 161 162 162 # -- assertion-based testing ------------------------------------------------ 163 163 … … 173 173 assert_deprecated_assertion { assert_session_has_no 'halloween' } 174 174 end 175 175 176 176 # test the get method, make sure the request really was a get 177 177 def test_get … … 187 187 assert_equal @response.body, 'request method: POST' 188 188 end 189 189 190 190 # the following test fails because the request_method is now cached on the request instance 191 191 # test the get/post switch within one test action … … 213 213 assert_deprecated_assertion { assert_template_has_no 'howdy' } 214 214 end 215 215 216 216 # test the redirection assertions 217 217 def test_assert_redirect … … 235 235 end 236 236 end 237 237 238 238 # test the redirection pattern matching on a pattern 239 239 def test_assert_redirect_url_match_pattern … … 313 313 assert_deprecated_assertion { assert_flash_has_no 'qwerty' } 314 314 end 315 316 # test the assert_rendered_file 315 316 # test the assert_rendered_file 317 317 def test_assert_rendered_file 318 318 assert_deprecated(/render/) { process :hello_world } … … 320 320 assert_deprecated_assertion { assert_rendered_file 'hello_world' } 321 321 end 322 322 323 323 # test the assert_success assertion 324 324 def test_assert_success … … 326 326 assert_deprecated_assertion { assert_success } 327 327 end 328 328 329 329 # -- standard request/response object testing -------------------------------- 330 330 331 331 # ensure our session is working properly 332 332 def test_session_objects … … 336 336 assert !@response.has_session_object?('easter') 337 337 end 338 338 339 339 # make sure that the template objects exist 340 340 def test_template_objects_alive … … 343 343 assert @response.has_template_object?('howdy') 344 344 end 345 345 346 346 # make sure we don't have template objects when we shouldn't 347 347 def test_template_object_missing … … 349 349 assert_nil @response.template_objects['howdy'] 350 350 end 351 351 352 352 def test_assigned_equal 353 353 process :assign_this … … 377 377 assert_nil @response.flash['hello'] 378 378 end 379 379 380 380 # examine that the flash objects are what we expect 381 381 def test_flash_equals … … 385 385 end 386 386 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? 389 389 def test_rendered_action 390 390 process :nothing … … 395 395 assert 'hello_world', @response.rendered_file 396 396 end 397 397 398 398 # check the redirection location 399 399 def test_redirection_location … … 407 407 assert_nil @response.redirect_url 408 408 end 409 410 411 # check server errors 409 410 411 # check server errors 412 412 def test_server_error_response_code 413 413 process :response500 414 414 assert @response.server_error? 415 415 416 416 process :response599 417 417 assert @response.server_error? 418 418 419 419 process :response404 420 420 assert !@response.server_error? 421 421 end 422 422 423 423 # check a 404 response code 424 424 def test_missing_response_code … … 436 436 assert !@response.redirect_url_match?(/perloffrails/) 437 437 end 438 438 439 439 # check for a redirection 440 440 def test_redirection … … 448 448 assert !@response.redirect? 449 449 end 450 450 451 451 # check a successful response code 452 452 def test_successful_response_code 453 453 process :nothing 454 454 assert @response.success? 455 end 456 455 end 456 457 457 # a basic check to make sure we have a TestResponse object 458 458 def test_has_response … … 460 460 assert_kind_of ActionController::TestResponse, @response 461 461 end 462 462 463 463 def test_render_based_on_parameters 464 464 process :render_based_on_parameters, "name" => "David" … … 492 492 process :redirect_to_action 493 493 assert_redirected_to :action => "flash_me" 494 494 495 495 follow_redirect 496 496 assert_equal 1, @request.parameters["id"].to_i … … 535 535 get :redirect_to_absolute_controller 536 536 assert_redirected_to :controller => 'content' 537 537 538 538 get :redirect_to_fellow_controller 539 539 assert_redirected_to :controller => 'admin/user' 540 end 541 540 end 541 542 542 def test_assert_valid 543 543 get :get_valid_record 544 assert_valid assigns('record') 545 end 546 544 assert_valid assigns('record') 545 end 546 547 547 def test_assert_valid_failing 548 548 get :get_invalid_record 549 549 550 550 begin 551 assert_valid assigns('record') 551 assert_valid assigns('record') 552 552 assert false 553 rescue Test::Unit::AssertionFailedError => e 553 rescue Test::Unit::AssertionFailedError => e 554 554 end 555 555 end … … 561 561 end 562 562 563 class ActionPackHeaderTest < Test::Unit::TestCase 563 class ActionPackHeaderTest < Test::Unit::TestCase 564 564 def setup 565 565 @controller = ActionPackAssertionsController.new … … 578 578 end 579 579 580 580 581 581 def test_render_text_with_custom_content_type 582 582 get :render_text_with_custom_content_type trunk/actionpack/test/controller/new_render_test.rb
r5200 r5201 423 423 424 424 get :hello_world 425 assert _nil(assigns["request"])425 assert !assigns.include?('request'), 'request should not be in assigns' 426 426 427 427 ActionController::Base.view_controller_internals = true … … 429 429 430 430 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 433 441 ActionController::Base.view_controller_internals = view_internals_old_value 434 442 ActionController::Base.protected_variables_cache = nil 435 443 end 436 444 437 445 def test_render_xml 438 446 get :render_xml_hello trunk/actionpack/test/controller/render_test.rb
r5044 r5201 169 169 end 170 170 171 def test_access_to_request_in_view172 view_internals_old_value = ActionController::Base.view_controller_internals173 174 ActionController::Base.view_controller_internals = false175 ActionController::Base.protected_variables_cache = nil176 177 get :hello_world178 assert_nil assigns["request"]179 180 ActionController::Base.view_controller_internals = true181 ActionController::Base.protected_variables_cache = nil182 183 get :hello_world184 assert_kind_of ActionController::AbstractRequest, assigns["request"]185 186 ActionController::Base.view_controller_internals = view_internals_old_value187 ActionController::Base.protected_variables_cache = nil188 end189 190 171 def test_render_xml 191 172 assert_deprecated_render { get :render_xml_hello } trunk/actionpack/test/controller/verification_test.rb
r5196 r5201 60 60 61 61 def guarded_by_method 62 render :text => "#{ @request.method}"62 render :text => "#{request.method}" 63 63 end 64 64 65 65 def guarded_by_xhr 66 render :text => "#{ @request.xhr?}"66 render :text => "#{request.xhr?}" 67 67 end 68 68 69 69 def guarded_by_not_xhr 70 render :text => "#{ @request.xhr?}"70 render :text => "#{request.xhr?}" 71 71 end 72 72 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 %>