Skip to content
This repository
Browse code

Include process methods in ActionController::TestCase only. No need t…

…o alias_method_chain :process either.
  • Loading branch information...
commit 35fa00731329120fa1d0c2a9d66af6813203195a 1 parent 0f9e65b
Jeremy Kemper jeremy authored
3  actionpack/lib/action_controller/test_case.rb
... ... @@ -1,4 +1,5 @@
1 1 require 'active_support/test_case'
  2 +require 'action_controller/test_process'
2 3
3 4 module ActionController
4 5 # Superclass for ActionController functional tests. Functional tests allow you to
@@ -102,6 +103,8 @@ module ActionController
102 103 #
103 104 # assert_redirected_to page_url(:title => 'foo')
104 105 class TestCase < ActiveSupport::TestCase
  106 + include TestProcess
  107 +
105 108 module Assertions
106 109 %w(response selector tag dom routing model).each do |kind|
107 110 include ActionController::Assertions.const_get("#{kind.camelize}Assertions")
54 actionpack/lib/action_controller/test_process.rb
... ... @@ -1,32 +1,4 @@
1   -require 'action_controller/test_case'
2   -
3 1 module ActionController #:nodoc:
4   - class Base
5   - attr_reader :assigns
6   -
7   - # Process a test request called with a TestRequest object.
8   - def self.process_test(request)
9   - new.process_test(request)
10   - end
11   -
12   - def process_test(request) #:nodoc:
13   - process(request, TestResponse.new)
14   - end
15   -
16   - def process_with_test(*args)
17   - returning process_without_test(*args) do
18   - @assigns = {}
19   - (instance_variable_names - @@protected_instance_variables).each do |var|
20   - value = instance_variable_get(var)
21   - @assigns[var[1..-1]] = value
22   - response.template.assigns[var[1..-1]] = value if response
23   - end
24   - end
25   - end
26   -
27   - alias_method_chain :process, :test
28   - end
29   -
30 2 class TestRequest < Request #:nodoc:
31 3 attr_accessor :cookies, :session_options
32 4 attr_accessor :query_parameters, :path, :session
@@ -433,7 +405,9 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
433 405 @request.session = ActionController::TestSession.new(session) unless session.nil?
434 406 @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
435 407 build_request_uri(action, parameters)
436   - @controller.process(@request, @response)
  408 +
  409 + Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest
  410 + @controller.process_with_test(@request, @response)
437 411 end
438 412
439 413 def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
@@ -545,12 +519,24 @@ def with_routing
545 519 ActionController::Routing.const_set(:Routes, real_routes) if real_routes
546 520 end
547 521 end
548   -end
549 522
550   -module Test
551   - module Unit
552   - class TestCase #:nodoc:
553   - include ActionController::TestProcess
  523 + module ProcessWithTest #:nodoc:
  524 + def self.included(base)
  525 + base.class_eval { attr_reader :assigns }
  526 + end
  527 +
  528 + def process_with_test(*args)
  529 + process(*args).tap { set_test_assigns }
554 530 end
  531 +
  532 + private
  533 + def set_test_assigns
  534 + @assigns = {}
  535 + (instance_variable_names - self.class.protected_instance_variables).each do |var|
  536 + name, value = var[1..-1], instance_variable_get(var)
  537 + @assigns[name] = value
  538 + response.template.assigns[name] = value if response
  539 + end
  540 + end
555 541 end
556 542 end
1  actionpack/lib/action_view/test_case.rb
@@ -23,6 +23,7 @@ def render(view, local_assigns = {})
23 23
24 24 class TestCase < ActiveSupport::TestCase
25 25 include ActionController::TestCase::Assertions
  26 + include ActionController::TestProcess
26 27
27 28 class_inheritable_accessor :helper_class
28 29 @@helper_class = nil
9 actionpack/test/controller/addresses_render_test.rb
@@ -19,17 +19,14 @@ def self.controller_name; "addresses"; end
19 19 def self.controller_path; "addresses"; end
20 20 end
21 21
22   -class AddressesTest < Test::Unit::TestCase
23   - def setup
24   - @controller = AddressesTestController.new
  22 +class AddressesTest < ActionController::TestCase
  23 + tests AddressesTestController
25 24
  25 + def setup
26 26 # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
27 27 # a more accurate simulation of what happens in "real life".
28 28 @controller.logger = Logger.new(nil)
29 29
30   - @request = ActionController::TestRequest.new
31   - @response = ActionController::TestResponse.new
32   -
33 30 @request.host = "www.nextangle.com"
34 31 end
35 32
22 actionpack/test/controller/base_test.rb
@@ -129,6 +129,8 @@ def use_controller(controller_class)
129 129 @response = ActionController::TestResponse.new
130 130
131 131 @request.host = "www.nextangle.com"
  132 +
  133 + rescue_action_in_public!
132 134 end
133 135
134 136 def test_get_on_priv_should_show_selector
@@ -164,14 +166,12 @@ def test_namespaced_action_should_log_module_name
164 166 end
165 167 end
166 168
167   -class DefaultUrlOptionsTest < Test::Unit::TestCase
168   - def setup
169   - @controller = DefaultUrlOptionsController.new
170   -
171   - @request = ActionController::TestRequest.new
172   - @response = ActionController::TestResponse.new
  169 +class DefaultUrlOptionsTest < ActionController::TestCase
  170 + tests DefaultUrlOptionsController
173 171
  172 + def setup
174 173 @request.host = 'www.example.com'
  174 + rescue_action_in_public!
175 175 end
176 176
177 177 def test_default_url_options_are_used_if_set
@@ -189,14 +189,12 @@ def test_default_url_options_are_used_if_set
189 189 end
190 190 end
191 191
192   -class EmptyUrlOptionsTest < Test::Unit::TestCase
193   - def setup
194   - @controller = NonEmptyController.new
195   -
196   - @request = ActionController::TestRequest.new
197   - @response = ActionController::TestResponse.new
  192 +class EmptyUrlOptionsTest < ActionController::TestCase
  193 + tests NonEmptyController
198 194
  195 + def setup
199 196 @request.host = 'www.example.com'
  197 + rescue_action_in_public!
200 198 end
201 199
202 200 def test_ensure_url_for_works_as_expected_when_called_with_no_options_if_default_url_options_is_not_set
6 actionpack/test/controller/benchmark_test.rb
@@ -11,17 +11,17 @@ def rescue_action(e)
11 11 end
12 12 end
13 13
14   -class BenchmarkTest < Test::Unit::TestCase
  14 +class BenchmarkTest < ActionController::TestCase
  15 + tests BenchmarkedController
  16 +
15 17 class MockLogger
16 18 def method_missing(*args)
17 19 end
18 20 end
19 21
20 22 def setup
21   - @controller = BenchmarkedController.new
22 23 # benchmark doesn't do anything unless a logger is set
23 24 @controller.logger = MockLogger.new
24   - @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
25 25 @request.host = "test.actioncontroller.i"
26 26 end
27 27
9 actionpack/test/controller/capture_test.rb
@@ -23,17 +23,14 @@ def non_erb_block_content_for
23 23 def rescue_action(e) raise end
24 24 end
25 25
26   -class CaptureTest < Test::Unit::TestCase
27   - def setup
28   - @controller = CaptureController.new
  26 +class CaptureTest < ActionController::TestCase
  27 + tests CaptureController
29 28
  29 + def setup
30 30 # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
31 31 # a more accurate simulation of what happens in "real life".
32 32 @controller.logger = Logger.new(nil)
33 33
34   - @request = ActionController::TestRequest.new
35   - @response = ActionController::TestResponse.new
36   -
37 34 @request.host = "www.nextangle.com"
38 35 end
39 36
9 actionpack/test/controller/content_type_test.rb
@@ -50,16 +50,13 @@ def render_default_content_types_for_respond_to
50 50 def rescue_action(e) raise end
51 51 end
52 52
53   -class ContentTypeTest < Test::Unit::TestCase
54   - def setup
55   - @controller = ContentTypeController.new
  53 +class ContentTypeTest < ActionController::TestCase
  54 + tests ContentTypeController
56 55
  56 + def setup
57 57 # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
58 58 # a more accurate simulation of what happens in "real life".
59 59 @controller.logger = Logger.new(nil)
60   -
61   - @request = ActionController::TestRequest.new
62   - @response = ActionController::TestResponse.new
63 60 end
64 61
65 62 def test_render_defaults
8 actionpack/test/controller/cookie_test.rb
... ... @@ -1,6 +1,6 @@
@@ -41,11 +41,9 @@ def rescue_action(e)
8 actionpack/test/controller/filters_test.rb
@@ -634,9 +634,11 @@ def test_a_rescuing_around_filter
634 634
635 635 private
636 636 def test_process(controller, action = "show")
  637 + ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
637 638 request = ActionController::TestRequest.new
638 639 request.action = action
639   - controller.process(request, ActionController::TestResponse.new)
  640 + controller = controller.new if controller.is_a?(Class)
  641 + controller.process_with_test(request, ActionController::TestResponse.new)
640 642 end
641 643 end
642 644
@@ -874,8 +876,10 @@ def test_last_filter_in_multiple_before_filter_chain_halts
874 876
875 877 protected
876 878 def test_process(controller, action = "show")
  879 + ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest
877 880 request = ActionController::TestRequest.new
878 881 request.action = action
879   - controller.process(request, ActionController::TestResponse.new)
  882 + controller = controller.new if controller.is_a?(Class)
  883 + controller.process_with_test(request, ActionController::TestResponse.new)
880 884 end
881 885 end
8 actionpack/test/controller/flash_test.rb
... ... @@ -1,6 +1,6 @@
1 1 require 'abstract_unit'
2 2
3   -class FlashTest < Test::Unit::TestCase
  3 +class FlashTest < ActionController::TestCase
4 4 class TestController < ActionController::Base
5 5 def set_flash
6 6 flash["that"] = "hello"
@@ -73,11 +73,7 @@ def halt_and_redir
73 73 end
74 74 end
75 75
76   - def setup
77   - @request = ActionController::TestRequest.new
78   - @response = ActionController::TestResponse.new
79   - @controller = TestController.new
80   - end
  76 + tests TestController
81 77
82 78 def test_flash
83 79 get :set_flash
3  actionpack/test/controller/send_file_test.rb
@@ -19,7 +19,8 @@ def data() send_data(file_data, options) end
19 19 def rescue_action(e) raise end
20 20 end
21 21
22   -class SendFileTest < Test::Unit::TestCase
  22 +class SendFileTest < ActionController::TestCase
  23 + tests SendFileController
23 24 include TestFileUtils
24 25
25 26 Mime::Type.register "image/png", :png unless defined? Mime::PNG
2  railties/lib/test_help.rb
@@ -3,7 +3,7 @@
3 3 silence_warnings { RAILS_ENV = "test" }
4 4
5 5 require 'test/unit'
6   -require 'action_controller/test_process'
  6 +require 'action_controller/test_case'
7 7 require 'action_view/test_case'
8 8 require 'action_controller/integration'
9 9 require 'action_mailer/test_case' if defined?(ActionMailer)

0 comments on commit 35fa007

Please sign in to comment.
Something went wrong with that request. Please try again.