actionpack 1.12.5 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (179) hide show
  1. data/CHANGELOG +517 -15
  2. data/MIT-LICENSE +1 -1
  3. data/README +18 -20
  4. data/Rakefile +7 -4
  5. data/examples/address_book_controller.rb +3 -3
  6. data/examples/blog_controller.cgi +3 -3
  7. data/examples/debate_controller.cgi +5 -5
  8. data/lib/action_controller.rb +2 -2
  9. data/lib/action_controller/assertions.rb +73 -311
  10. data/lib/action_controller/{deprecated_assertions.rb → assertions/deprecated_assertions.rb} +32 -8
  11. data/lib/action_controller/assertions/dom_assertions.rb +25 -0
  12. data/lib/action_controller/assertions/model_assertions.rb +12 -0
  13. data/lib/action_controller/assertions/response_assertions.rb +140 -0
  14. data/lib/action_controller/assertions/routing_assertions.rb +82 -0
  15. data/lib/action_controller/assertions/selector_assertions.rb +571 -0
  16. data/lib/action_controller/assertions/tag_assertions.rb +117 -0
  17. data/lib/action_controller/base.rb +334 -163
  18. data/lib/action_controller/benchmarking.rb +3 -6
  19. data/lib/action_controller/caching.rb +83 -22
  20. data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -7
  21. data/lib/action_controller/cgi_ext/cgi_methods.rb +167 -173
  22. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +43 -22
  23. data/lib/action_controller/cgi_process.rb +50 -27
  24. data/lib/action_controller/components.rb +21 -25
  25. data/lib/action_controller/cookies.rb +10 -9
  26. data/lib/action_controller/{dependencies.rb → deprecated_dependencies.rb} +9 -27
  27. data/lib/action_controller/filters.rb +448 -225
  28. data/lib/action_controller/flash.rb +24 -20
  29. data/lib/action_controller/helpers.rb +2 -5
  30. data/lib/action_controller/integration.rb +40 -16
  31. data/lib/action_controller/layout.rb +11 -8
  32. data/lib/action_controller/macros/auto_complete.rb +3 -2
  33. data/lib/action_controller/macros/in_place_editing.rb +3 -2
  34. data/lib/action_controller/mime_responds.rb +41 -29
  35. data/lib/action_controller/mime_type.rb +68 -10
  36. data/lib/action_controller/pagination.rb +4 -3
  37. data/lib/action_controller/request.rb +22 -14
  38. data/lib/action_controller/rescue.rb +25 -22
  39. data/lib/action_controller/resources.rb +302 -0
  40. data/lib/action_controller/response.rb +20 -2
  41. data/lib/action_controller/response.rb.rej +17 -0
  42. data/lib/action_controller/routing.rb +1165 -567
  43. data/lib/action_controller/scaffolding.rb +30 -31
  44. data/lib/action_controller/session/active_record_store.rb +2 -0
  45. data/lib/action_controller/session/drb_store.rb +4 -0
  46. data/lib/action_controller/session/mem_cache_store.rb +4 -0
  47. data/lib/action_controller/session_management.rb +6 -9
  48. data/lib/action_controller/status_codes.rb +89 -0
  49. data/lib/action_controller/streaming.rb +6 -15
  50. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +5 -5
  51. data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -2
  52. data/lib/action_controller/templates/rescues/routing_error.rhtml +4 -4
  53. data/lib/action_controller/templates/rescues/template_error.rhtml +1 -1
  54. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  55. data/lib/action_controller/test_process.rb +52 -30
  56. data/lib/action_controller/url_rewriter.rb +63 -29
  57. data/lib/action_controller/vendor/html-scanner/html/document.rb +1 -0
  58. data/lib/action_controller/vendor/html-scanner/html/node.rb +3 -4
  59. data/lib/action_controller/vendor/html-scanner/html/selector.rb +822 -0
  60. data/lib/action_controller/verification.rb +22 -11
  61. data/lib/action_pack.rb +1 -1
  62. data/lib/action_pack/version.rb +2 -2
  63. data/lib/action_view.rb +1 -1
  64. data/lib/action_view/base.rb +46 -43
  65. data/lib/action_view/compiled_templates.rb +1 -1
  66. data/lib/action_view/helpers/active_record_helper.rb +54 -17
  67. data/lib/action_view/helpers/asset_tag_helper.rb +97 -46
  68. data/lib/action_view/helpers/capture_helper.rb +1 -1
  69. data/lib/action_view/helpers/date_helper.rb +258 -136
  70. data/lib/action_view/helpers/debug_helper.rb +1 -1
  71. data/lib/action_view/helpers/deprecated_helper.rb +34 -0
  72. data/lib/action_view/helpers/form_helper.rb +75 -35
  73. data/lib/action_view/helpers/form_options_helper.rb +7 -5
  74. data/lib/action_view/helpers/form_tag_helper.rb +44 -6
  75. data/lib/action_view/helpers/java_script_macros_helper.rb +59 -46
  76. data/lib/action_view/helpers/javascript_helper.rb +71 -10
  77. data/lib/action_view/helpers/javascripts/controls.js +41 -23
  78. data/lib/action_view/helpers/javascripts/dragdrop.js +105 -76
  79. data/lib/action_view/helpers/javascripts/effects.js +293 -163
  80. data/lib/action_view/helpers/javascripts/prototype.js +897 -389
  81. data/lib/action_view/helpers/javascripts/prototype.js.rej +561 -0
  82. data/lib/action_view/helpers/number_helper.rb +111 -65
  83. data/lib/action_view/helpers/prototype_helper.rb +84 -109
  84. data/lib/action_view/helpers/scriptaculous_helper.rb +5 -0
  85. data/lib/action_view/helpers/tag_helper.rb +69 -16
  86. data/lib/action_view/helpers/text_helper.rb +149 -112
  87. data/lib/action_view/helpers/url_helper.rb +200 -107
  88. data/lib/action_view/template_error.rb +66 -42
  89. data/test/abstract_unit.rb +4 -2
  90. data/test/active_record_unit.rb +84 -56
  91. data/test/activerecord/active_record_assertions_test.rb +26 -18
  92. data/test/activerecord/active_record_store_test.rb +4 -36
  93. data/test/activerecord/pagination_test.rb +1 -6
  94. data/test/controller/action_pack_assertions_test.rb +230 -113
  95. data/test/controller/addresses_render_test.rb +2 -6
  96. data/test/controller/assert_select_test.rb +576 -0
  97. data/test/controller/base_test.rb +73 -3
  98. data/test/controller/caching_test.rb +228 -0
  99. data/test/controller/capture_test.rb +12 -10
  100. data/test/controller/cgi_test.rb +89 -12
  101. data/test/controller/components_test.rb +24 -2
  102. data/test/controller/content_type_test.rb +139 -0
  103. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  104. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  105. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  106. data/test/controller/cookie_test.rb +33 -25
  107. data/test/controller/deprecated_instance_variables_test.rb +48 -0
  108. data/test/controller/deprecation/deprecated_base_methods_test.rb +60 -0
  109. data/test/controller/fake_controllers.rb +0 -1
  110. data/test/controller/filters_test.rb +301 -16
  111. data/test/controller/flash_test.rb +19 -2
  112. data/test/controller/helper_test.rb +2 -2
  113. data/test/controller/integration_test.rb +154 -0
  114. data/test/controller/layout_test.rb +115 -1
  115. data/test/controller/mime_responds_test.rb +94 -0
  116. data/test/controller/mime_type_test.rb +9 -0
  117. data/test/controller/new_render_test.rb +161 -11
  118. data/test/controller/raw_post_test.rb +52 -15
  119. data/test/controller/redirect_test.rb +27 -14
  120. data/test/controller/render_test.rb +76 -29
  121. data/test/controller/request_test.rb +55 -4
  122. data/test/controller/resources_test.rb +274 -0
  123. data/test/controller/routing_test.rb +1533 -824
  124. data/test/controller/selector_test.rb +628 -0
  125. data/test/controller/send_file_test.rb +9 -1
  126. data/test/controller/session_management_test.rb +51 -0
  127. data/test/controller/test_test.rb +113 -29
  128. data/test/controller/url_rewriter_test.rb +86 -17
  129. data/test/controller/verification_test.rb +19 -17
  130. data/test/controller/webservice_test.rb +0 -7
  131. data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
  132. data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
  133. data/test/fixtures/content_type/render_default_for_rjs.rjs +1 -0
  134. data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
  135. data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +1 -0
  136. data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +1 -0
  137. data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +1 -0
  138. data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +1 -0
  139. data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +1 -0
  140. data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +1 -0
  141. data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +1 -0
  142. data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +1 -0
  143. data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +1 -0
  144. data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +1 -0
  145. data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +1 -0
  146. data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +1 -0
  147. data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +1 -0
  148. data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +1 -0
  149. data/test/fixtures/multipart/binary_file +0 -0
  150. data/test/fixtures/public/javascripts/application.js +1 -0
  151. data/test/fixtures/test/_hello.rxml +1 -0
  152. data/test/fixtures/test/hello_world_container.rxml +3 -0
  153. data/test/fixtures/topic.rb +2 -2
  154. data/test/template/active_record_helper_test.rb +83 -12
  155. data/test/template/asset_tag_helper_test.rb +75 -95
  156. data/test/template/compiled_templates_test.rb +1 -0
  157. data/test/template/date_helper_test.rb +873 -181
  158. data/test/template/deprecated_helper_test.rb +36 -0
  159. data/test/template/deprecated_instance_variables_test.rb +43 -0
  160. data/test/template/form_helper_test.rb +77 -1
  161. data/test/template/form_options_helper_test.rb +4 -0
  162. data/test/template/form_tag_helper_test.rb +66 -2
  163. data/test/template/java_script_macros_helper_test.rb +4 -1
  164. data/test/template/javascript_helper_test.rb +29 -0
  165. data/test/template/number_helper_test.rb +63 -27
  166. data/test/template/prototype_helper_test.rb +77 -34
  167. data/test/template/tag_helper_test.rb +34 -6
  168. data/test/template/text_helper_test.rb +69 -34
  169. data/test/template/url_helper_test.rb +168 -16
  170. data/test/testing_sandbox.rb +7 -22
  171. metadata +66 -20
  172. data/filler.txt +0 -50
  173. data/lib/action_controller/code_generation.rb +0 -235
  174. data/lib/action_controller/vendor/xml_simple.rb +0 -1019
  175. data/test/controller/caching_filestore.rb +0 -74
  176. data/test/fixtures/application_root/app/controllers/a_class_that_contains_a_controller/poorly_placed_controller.rb +0 -7
  177. data/test/fixtures/application_root/app/controllers/module_that_holds_controllers/nested_controller.rb +0 -3
  178. data/test/fixtures/application_root/app/models/a_class_that_contains_a_controller.rb +0 -7
  179. data/test/fixtures/dont_load.rb +0 -3
@@ -6,9 +6,11 @@ require 'yaml'
6
6
  require 'test/unit'
7
7
  require 'action_controller'
8
8
  require 'breakpoint'
9
-
10
9
  require 'action_controller/test_process'
11
10
 
11
+ # Show backtraces for deprecated behavior for quicker cleanup.
12
+ ActiveSupport::Deprecation.debug = true
13
+
12
14
  ActionController::Base.logger = nil
13
15
  ActionController::Base.ignore_missing_templates = false
14
- ActionController::Routing::Routes.reload rescue nil
16
+ ActionController::Routing::Routes.reload rescue nil
@@ -4,85 +4,113 @@ require File.dirname(__FILE__) + '/abstract_unit'
4
4
  class ActiveRecordTestConnector
5
5
  cattr_accessor :able_to_connect
6
6
  cattr_accessor :connected
7
-
7
+
8
8
  # Set our defaults
9
9
  self.connected = false
10
10
  self.able_to_connect = true
11
11
  end
12
12
 
13
13
  # Try to grab AR
14
- begin
15
- PATH_TO_AR = File.dirname(__FILE__) + '/../../activerecord'
16
- require "#{PATH_TO_AR}/lib/active_record" unless Object.const_defined?(:ActiveRecord)
17
- require "#{PATH_TO_AR}/lib/active_record/fixtures" unless Object.const_defined?(:Fixtures)
18
- rescue Object => e
19
- $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
20
- ActiveRecordTestConnector.able_to_connect = false
14
+ if defined?(ActiveRecord) && defined?(Fixtures)
15
+ $stderr.puts 'Active Record is already loaded, running tests'
16
+ else
17
+ $stderr.print 'Attempting to load Active Record... '
18
+ begin
19
+ PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
20
+ raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
21
+ $LOAD_PATH.unshift PATH_TO_AR
22
+ require 'active_record'
23
+ require 'active_record/fixtures'
24
+ $stderr.puts 'success'
25
+ rescue LoadError => e
26
+ $stderr.print "failed. Skipping Active Record assertion tests: #{e}"
27
+ ActiveRecordTestConnector.able_to_connect = false
28
+ end
21
29
  end
30
+ $stderr.flush
31
+
32
+
22
33
 
23
34
  # Define the rest of the connector
24
- class ActiveRecordTestConnector
25
- def self.setup
26
- unless self.connected || !self.able_to_connect
27
- setup_connection
28
- load_schema
29
- self.connected = true
35
+ class ActiveRecordTestConnector
36
+ class << self
37
+ def setup
38
+ unless self.connected || !self.able_to_connect
39
+ setup_connection
40
+ load_schema
41
+ require_fixture_models
42
+ self.connected = true
43
+ end
44
+ rescue Exception => e # errors from ActiveRecord setup
45
+ $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
46
+ #$stderr.puts " #{e.backtrace.join("\n ")}\n"
47
+ self.able_to_connect = false
30
48
  end
31
- rescue Object => e
32
- $stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
33
- #$stderr.puts " #{e.backtrace.join("\n ")}\n"
34
- self.able_to_connect = false
35
- end
36
-
37
- private
38
-
39
- def self.setup_connection
40
- if Object.const_defined?(:ActiveRecord)
41
-
42
- begin
43
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:')
44
- ActiveRecord::Base.connection
45
- rescue Object
46
- $stderr.puts 'SQLite 3 unavailable; falling to SQLite 2.'
47
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite', :dbfile => ':memory:')
48
- ActiveRecord::Base.connection
49
+
50
+ private
51
+
52
+ def setup_connection
53
+ if Object.const_defined?(:ActiveRecord)
54
+ begin
55
+ connection_options = {:adapter => 'sqlite3', :dbfile => ':memory:'}
56
+ ActiveRecord::Base.establish_connection(connection_options)
57
+ ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => connection_options }
58
+ ActiveRecord::Base.connection
59
+ rescue Exception # errors from establishing a connection
60
+ $stderr.puts 'SQLite 3 unavailable; falling to SQLite 2.'
61
+ connection_options = {:adapter => 'sqlite', :dbfile => ':memory:'}
62
+ ActiveRecord::Base.establish_connection(connection_options)
63
+ ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => connection_options }
64
+ ActiveRecord::Base.connection
65
+ end
66
+
67
+ Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
68
+ else
69
+ raise "Couldn't locate ActiveRecord."
49
70
  end
50
-
51
- Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
52
- else
53
- raise "Couldn't locate ActiveRecord."
54
71
  end
55
- end
56
-
57
- # Load actionpack sqlite tables
58
- def self.load_schema
59
- File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
60
- ActiveRecord::Base.connection.execute(sql) unless sql.blank?
72
+
73
+ # Load actionpack sqlite tables
74
+ def load_schema
75
+ File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
76
+ ActiveRecord::Base.connection.execute(sql) unless sql.blank?
77
+ end
78
+ end
79
+
80
+ def require_fixture_models
81
+ Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f}
61
82
  end
62
83
  end
63
84
  end
64
-
65
- # Test case for inheiritance
85
+
86
+ # Test case for inheiritance
66
87
  class ActiveRecordTestCase < Test::Unit::TestCase
67
88
  # Set our fixture path
68
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
69
-
89
+ if ActiveRecordTestConnector.able_to_connect
90
+ self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
91
+ self.use_transactional_fixtures = false
92
+ end
93
+
94
+ def self.fixtures(*args)
95
+ super if ActiveRecordTestConnector.connected
96
+ end
97
+
70
98
  def setup
71
- abort_tests unless ActiveRecordTestConnector.connected = true
99
+ abort_tests unless ActiveRecordTestConnector.connected
72
100
  end
73
-
101
+
74
102
  # Default so Test::Unit::TestCase doesn't complain
75
103
  def test_truth
76
104
  end
77
-
105
+
78
106
  private
79
-
80
- # If things go wrong, we don't want to run our test cases. We'll just define them to test nothing.
81
- def abort_tests
82
- self.class.public_instance_methods.grep(/^test./).each do |method|
83
- self.class.class_eval { define_method(method.to_sym){} }
107
+ # If things go wrong, we don't want to run our test cases. We'll just define them to test nothing.
108
+ def abort_tests
109
+ $stderr.puts 'No Active Record connection, aborting tests.'
110
+ self.class.public_instance_methods.grep(/^test./).each do |method|
111
+ self.class.class_eval { define_method(method.to_sym){} }
112
+ end
84
113
  end
85
- end
86
114
  end
87
115
 
88
- ActiveRecordTestConnector.setup
116
+ ActiveRecordTestConnector.setup
@@ -1,5 +1,4 @@
1
1
  require "#{File.dirname(__FILE__)}/../active_record_unit"
2
- require 'fixtures/company'
3
2
 
4
3
  class ActiveRecordAssertionsController < ActionController::Base
5
4
  self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
@@ -37,10 +36,10 @@ class ActiveRecordAssertionsController < ActionController::Base
37
36
  # the safety dance......
38
37
  def rescue_action(e) raise; end
39
38
  end
40
-
39
+
41
40
  class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
42
41
  fixtures :companies
43
-
42
+
44
43
  def setup
45
44
  @request = ActionController::TestRequest.new
46
45
  @response = ActionController::TestResponse.new
@@ -51,34 +50,43 @@ class ActiveRecordAssertionsControllerTest < ActiveRecordTestCase
51
50
  # test for 1 bad apple column
52
51
  def test_some_invalid_columns
53
52
  process :nasty_columns_1
54
- assert_success
55
- assert_invalid_record 'company'
56
- assert_invalid_column_on_record 'company', 'rating'
57
- assert_valid_column_on_record 'company', 'name'
58
- assert_valid_column_on_record 'company', %w(name id)
53
+ assert_response :success
54
+
55
+ assert_deprecated_assertion { assert_invalid_record 'company' }
56
+ assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' }
57
+ assert_deprecated_assertion { assert_valid_column_on_record 'company', 'name' }
58
+ assert_deprecated_assertion { assert_valid_column_on_record 'company', %w(name id) }
59
59
  end
60
60
 
61
61
  # test for 2 bad apples columns
62
62
  def test_all_invalid_columns
63
63
  process :nasty_columns_2
64
- assert_success
65
- assert_invalid_record 'company'
66
- assert_invalid_column_on_record 'company', 'rating'
67
- assert_invalid_column_on_record 'company', 'name'
68
- assert_invalid_column_on_record 'company', %w(name rating)
64
+ assert_response :success
65
+
66
+ assert_deprecated_assertion { assert_invalid_record 'company' }
67
+ assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'rating' }
68
+ assert_deprecated_assertion { assert_invalid_column_on_record 'company', 'name' }
69
+ assert_deprecated_assertion { assert_invalid_column_on_record 'company', %w(name rating) }
69
70
  end
70
71
 
71
72
  # ensure we have no problems with an ActiveRecord
72
73
  def test_valid_record
73
74
  process :good_company
74
- assert_success
75
- assert_valid_record 'company'
75
+ assert_response :success
76
+
77
+ assert_deprecated_assertion { assert_valid_record 'company' }
76
78
  end
77
79
 
78
80
  # ensure we have problems with an ActiveRecord
79
81
  def test_invalid_record
80
82
  process :bad_company
81
- assert_success
82
- assert_invalid_record 'company'
83
+ assert_response :success
84
+
85
+ assert_deprecated_assertion { assert_invalid_record 'company' }
83
86
  end
84
- end
87
+
88
+ protected
89
+ def assert_deprecated_assertion(message = nil, &block)
90
+ assert_deprecated(/assert_.*from test_/, &block)
91
+ end
92
+ end
@@ -1,33 +1,8 @@
1
- # Unfurl the safety net.
2
- path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
3
- if Object.const_defined?(:ActiveRecord) or File.exist?(path_to_ar)
4
- begin
5
-
6
1
  # These tests exercise CGI::Session::ActiveRecordStore, so you're going to
7
2
  # need AR in a sibling directory to AP and have SQLite installed.
8
-
9
- unless Object.const_defined?(:ActiveRecord)
10
- require File.join(path_to_ar, 'lib', 'active_record')
11
- end
12
-
13
- require File.dirname(__FILE__) + '/../abstract_unit'
3
+ require File.dirname(__FILE__) + '/../active_record_unit'
14
4
  require 'action_controller/session/active_record_store'
15
5
 
16
- #ActiveRecord::Base.logger = Logger.new($stdout)
17
- begin
18
- CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
19
- CGI::Session::ActiveRecordStore::Session.connection
20
- rescue Object
21
- $stderr.puts 'SQLite 3 unavailable; falling back to SQLite 2.'
22
- begin
23
- CGI::Session::ActiveRecordStore::Session.establish_connection(:adapter => 'sqlite', :database => ':memory:')
24
- CGI::Session::ActiveRecordStore::Session.connection
25
- rescue Object
26
- $stderr.puts 'SQLite 2 unavailable; skipping ActiveRecordStore test suite.'
27
- raise SystemExit
28
- end
29
- end
30
-
31
6
 
32
7
  module CommonActiveRecordStoreTests
33
8
  def test_basics
@@ -55,7 +30,7 @@ module CommonActiveRecordStoreTests
55
30
  end
56
31
  end
57
32
 
58
- class ActiveRecordStoreTest < Test::Unit::TestCase
33
+ class ActiveRecordStoreTest < ActiveRecordTestCase
59
34
  include CommonActiveRecordStoreTests
60
35
 
61
36
  def session_class
@@ -70,6 +45,7 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
70
45
  session_class.create_table!
71
46
 
72
47
  ENV['REQUEST_METHOD'] = 'GET'
48
+ ENV['REQUEST_URI'] = '/'
73
49
  CGI::Session::ActiveRecordStore.session_class = session_class
74
50
 
75
51
  @cgi = CGI.new
@@ -107,7 +83,7 @@ class ActiveRecordStoreTest < Test::Unit::TestCase
107
83
  end
108
84
  end
109
85
 
110
- class ColumnLimitTest < Test::Unit::TestCase
86
+ class ColumnLimitTest < ActiveRecordTestCase
111
87
  def setup
112
88
  @session_class = CGI::Session::ActiveRecordStore::Session
113
89
  @session_class.create_table!
@@ -164,11 +140,3 @@ class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
164
140
  assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
165
141
  end
166
142
  end
167
-
168
-
169
- # End of safety net.
170
- rescue Object => e
171
- $stderr.puts "Skipping CGI::Session::ActiveRecordStore tests: #{e}"
172
- #$stderr.puts " #{e.backtrace.join("\n ")}"
173
- end
174
- end
@@ -1,13 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../active_record_unit'
2
2
 
3
- require 'fixtures/topic'
4
- require 'fixtures/reply'
5
- require 'fixtures/developer'
6
- require 'fixtures/project'
7
-
8
3
  class PaginationTest < ActiveRecordTestCase
9
4
  fixtures :topics, :replies, :developers, :projects, :developers_projects
10
-
5
+
11
6
  class PaginationController < ActionController::Base
12
7
  self.template_root = "#{File.dirname(__FILE__)}/../fixtures/"
13
8
 
@@ -4,14 +4,14 @@ require File.dirname(__FILE__) + '/../abstract_unit'
4
4
  class ActionPackAssertionsController < ActionController::Base
5
5
 
6
6
  # this does absolutely nothing
7
- def nothing() render_text ""; end
7
+ def nothing() head :ok end
8
8
 
9
9
  # a standard template
10
10
  def hello_world() render "test/hello_world"; end
11
11
 
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
17
17
 
@@ -22,18 +22,18 @@ class ActionPackAssertionsController < ActionController::Base
22
22
  def redirect_to_path() redirect_to '/some/path' 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
- def response404() render_text "", "404 AWOL"; end
30
+ def response404() head '404 AWOL' end
31
31
 
32
32
  # a 500
33
- def response500() render_text "", "500 Sorry"; end
33
+ def response500() head '500 Sorry' end
34
34
 
35
35
  # a fictional 599
36
- def response599() render_text "", "599 Whoah!"; end
36
+ def response599() head '599 Whoah!' end
37
37
 
38
38
  # putting stuff in the flash
39
39
  def flash_me
@@ -54,64 +54,68 @@ class ActionPackAssertionsController < ActionController::Base
54
54
  end
55
55
 
56
56
  def render_based_on_parameters
57
- render_text "Mr. #{@params["name"]}"
57
+ render_text "Mr. #{params[:name]}"
58
58
  end
59
59
 
60
60
  def render_url
61
61
  render_text "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>"
62
62
  end
63
63
 
64
+ def render_text_with_custom_content_type
65
+ render :text => "Hello!", :content_type => Mime::RSS
66
+ end
67
+
64
68
  # puts something in the session
65
69
  def session_stuffing
66
70
  session['xmas'] = 'turkey'
67
71
  render_text "ho ho ho"
68
72
  end
69
-
73
+
70
74
  # raises exception on get requests
71
75
  def raise_on_get
72
- raise "get" if @request.get?
73
- render_text "request method: #{@request.env['REQUEST_METHOD']}"
76
+ raise "get" if request.get?
77
+ render_text "request method: #{request.env['REQUEST_METHOD']}"
74
78
  end
75
79
 
76
80
  # raises exception on post requests
77
81
  def raise_on_post
78
- raise "post" if @request.post?
79
- render_text "request method: #{@request.env['REQUEST_METHOD']}"
80
- end
81
-
82
+ raise "post" if request.post?
83
+ render_text "request method: #{request.env['REQUEST_METHOD']}"
84
+ end
85
+
82
86
  def get_valid_record
83
- @record = Class.new do
87
+ @record = Class.new do
84
88
  def valid?
85
89
  true
86
90
  end
87
91
 
88
92
  def errors
89
- Class.new do
90
- def full_messages; []; end
93
+ Class.new do
94
+ def full_messages; []; end
91
95
  end.new
92
- end
93
-
96
+ end
97
+
94
98
  end.new
95
-
96
- render :nothing => true
99
+
100
+ render :nothing => true
97
101
  end
98
102
 
99
103
 
100
104
  def get_invalid_record
101
- @record = Class.new do
102
-
105
+ @record = Class.new do
106
+
103
107
  def valid?
104
108
  false
105
109
  end
106
-
110
+
107
111
  def errors
108
- Class.new do
109
- def full_messages; ['...stuff...']; end
112
+ Class.new do
113
+ def full_messages; ['...stuff...']; end
110
114
  end.new
111
115
  end
112
- end.new
113
-
114
- render :nothing => true
116
+ end.new
117
+
118
+ render :nothing => true
115
119
  end
116
120
 
117
121
  # 911
@@ -120,32 +124,51 @@ end
120
124
 
121
125
  module Admin
122
126
  class InnerModuleController < ActionController::Base
127
+ def index
128
+ render :nothing => true
129
+ end
130
+
131
+ def redirect_to_index
132
+ redirect_to admin_inner_module_path
133
+ end
134
+
123
135
  def redirect_to_absolute_controller
124
136
  redirect_to :controller => '/content'
125
137
  end
138
+
126
139
  def redirect_to_fellow_controller
127
140
  redirect_to :controller => 'user'
128
141
  end
142
+
143
+ def redirect_to_top_level_named_route
144
+ redirect_to top_level_url(:id => "foo")
145
+ end
129
146
  end
130
147
  end
131
148
 
132
149
  # ---------------------------------------------------------------------------
133
150
 
134
151
 
135
- # tell the controller where to find its templates but start from parent
136
- # directory of test_request_response to simulate the behaviour of a
152
+ # tell the controller where to find its templates but start from parent
153
+ # directory of test_request_response to simulate the behaviour of a
137
154
  # production environment
138
155
  ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/"
139
156
 
140
157
 
141
158
  # a test case to exercise the new capabilities TestRequest & TestResponse
142
159
  class ActionPackAssertionsControllerTest < Test::Unit::TestCase
143
- # let's get this party started
160
+ # let's get this party started
144
161
  def setup
162
+ ActionController::Routing::Routes.reload
163
+ ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user))
145
164
  @controller = ActionPackAssertionsController.new
146
165
  @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
147
166
  end
148
-
167
+
168
+ def teardown
169
+ ActionController::Routing::Routes.reload
170
+ end
171
+
149
172
  # -- assertion-based testing ------------------------------------------------
150
173
 
151
174
  def test_assert_tag_and_url_for
@@ -156,10 +179,10 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
156
179
  # test the session assertion to make sure something is there.
157
180
  def test_assert_session_has
158
181
  process :session_stuffing
159
- assert_session_has 'xmas'
160
- assert_session_has_no 'halloween'
182
+ assert_deprecated_assertion { assert_session_has 'xmas' }
183
+ assert_deprecated_assertion { assert_session_has_no 'halloween' }
161
184
  end
162
-
185
+
163
186
  # test the get method, make sure the request really was a get
164
187
  def test_get
165
188
  assert_raise(RuntimeError) { get :raise_on_get }
@@ -173,7 +196,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
173
196
  post :raise_on_get
174
197
  assert_equal @response.body, 'request method: POST'
175
198
  end
176
-
199
+
177
200
  # the following test fails because the request_method is now cached on the request instance
178
201
  # test the get/post switch within one test action
179
202
  # def test_get_post_switch
@@ -190,106 +213,168 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
190
213
  # test the assertion of goodies in the template
191
214
  def test_assert_template_has
192
215
  process :assign_this
193
- assert_template_has 'howdy'
216
+ assert_deprecated_assertion { assert_template_has 'howdy' }
194
217
  end
195
218
 
196
219
  # test the assertion for goodies that shouldn't exist in the template
197
220
  def test_assert_template_has_no
198
221
  process :nothing
199
- assert_template_has_no 'maple syrup'
200
- assert_template_has_no 'howdy'
222
+ assert_deprecated_assertion { assert_template_has_no 'maple syrup' }
223
+ assert_deprecated_assertion { assert_template_has_no 'howdy' }
201
224
  end
202
-
225
+
203
226
  # test the redirection assertions
204
227
  def test_assert_redirect
205
228
  process :redirect_internal
206
- assert_redirect
229
+ assert_deprecated_assertion { assert_redirect }
207
230
  end
208
231
 
209
232
  # test the redirect url string
210
233
  def test_assert_redirect_url
211
234
  process :redirect_external
212
- assert_redirect_url 'http://www.rubyonrails.org'
235
+ assert_deprecated_assertion do
236
+ assert_redirect_url 'http://www.rubyonrails.org'
237
+ end
213
238
  end
214
239
 
215
240
  # test the redirection pattern matching on a string
216
241
  def test_assert_redirect_url_match_string
217
242
  process :redirect_external
218
- assert_redirect_url_match 'rails.org'
243
+ assert_deprecated_assertion do
244
+ assert_redirect_url_match 'rails.org'
245
+ end
219
246
  end
220
-
247
+
221
248
  # test the redirection pattern matching on a pattern
222
249
  def test_assert_redirect_url_match_pattern
223
250
  process :redirect_external
224
- assert_redirect_url_match /ruby/
251
+ assert_deprecated_assertion do
252
+ assert_redirect_url_match /ruby/
253
+ end
225
254
  end
226
255
 
227
256
  # test the redirection to a named route
228
257
  def test_assert_redirect_to_named_route
229
- process :redirect_to_named_route
230
- assert_raise(Test::Unit::AssertionFailedError) do
231
- assert_redirected_to 'http://test.host/route_two'
258
+ with_routing do |set|
259
+ set.draw do |map|
260
+ map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
261
+ map.connect ':controller/:action/:id'
262
+ end
263
+ set.named_routes.install
264
+
265
+ process :redirect_to_named_route
266
+ assert_redirected_to 'http://test.host/route_one'
267
+ assert_redirected_to route_one_url
268
+ assert_redirected_to :route_one_url
269
+ end
270
+ end
271
+
272
+ def test_assert_redirect_to_named_route_failure
273
+ with_routing do |set|
274
+ set.draw do |map|
275
+ map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'one'
276
+ map.route_two 'route_two', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
277
+ map.connect ':controller/:action/:id'
278
+ end
279
+ process :redirect_to_named_route
280
+ assert_raise(Test::Unit::AssertionFailedError) do
281
+ assert_redirected_to 'http://test.host/route_two'
282
+ end
283
+ assert_raise(Test::Unit::AssertionFailedError) do
284
+ assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
285
+ end
286
+ assert_raise(Test::Unit::AssertionFailedError) do
287
+ assert_redirected_to route_two_url
288
+ end
289
+ assert_raise(Test::Unit::AssertionFailedError) do
290
+ assert_redirected_to :route_two_url
291
+ end
232
292
  end
233
293
  end
234
-
294
+
295
+ def test_assert_redirect_to_nested_named_route
296
+ with_routing do |set|
297
+ set.draw do |map|
298
+ map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
299
+ map.connect ':controller/:action/:id'
300
+ end
301
+ @controller = Admin::InnerModuleController.new
302
+ process :redirect_to_index
303
+ # redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
304
+ assert_redirected_to admin_inner_module_path
305
+ end
306
+ end
307
+
308
+ def test_assert_redirected_to_top_level_named_route_from_nested_controller
309
+ with_routing do |set|
310
+ set.draw do |map|
311
+ map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index'
312
+ map.connect ':controller/:action/:id'
313
+ end
314
+ @controller = Admin::InnerModuleController.new
315
+ process :redirect_to_top_level_named_route
316
+ # passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo"
317
+ assert_redirected_to "/action_pack_assertions/foo"
318
+ end
319
+ end
320
+
235
321
  # test the flash-based assertions with something is in the flash
236
322
  def test_flash_assertions_full
237
323
  process :flash_me
238
324
  assert @response.has_flash_with_contents?
239
- assert_flash_exists
240
- assert_flash_not_empty
241
- assert_flash_has 'hello'
242
- assert_flash_has_no 'stds'
325
+ assert_deprecated_assertion { assert_flash_exists }
326
+ assert_deprecated_assertion { assert_flash_not_empty }
327
+ assert_deprecated_assertion { assert_flash_has 'hello' }
328
+ assert_deprecated_assertion { assert_flash_has_no 'stds' }
243
329
  end
244
330
 
245
331
  # test the flash-based assertions with no flash at all
246
332
  def test_flash_assertions_negative
247
333
  process :nothing
248
- assert_flash_empty
249
- assert_flash_has_no 'hello'
250
- assert_flash_has_no 'qwerty'
334
+ assert_deprecated_assertion { assert_flash_empty }
335
+ assert_deprecated_assertion { assert_flash_has_no 'hello' }
336
+ assert_deprecated_assertion { assert_flash_has_no 'qwerty' }
251
337
  end
252
-
253
- # test the assert_rendered_file
338
+
339
+ # test the assert_rendered_file
254
340
  def test_assert_rendered_file
255
- process :hello_world
256
- assert_rendered_file 'test/hello_world'
257
- assert_rendered_file 'hello_world'
341
+ assert_deprecated(/render/) { process :hello_world }
342
+ assert_deprecated_assertion { assert_rendered_file 'test/hello_world' }
343
+ assert_deprecated_assertion { assert_rendered_file 'hello_world' }
258
344
  end
259
-
345
+
260
346
  # test the assert_success assertion
261
347
  def test_assert_success
262
348
  process :nothing
263
- assert_success
264
- assert_rendered_file
349
+ assert_deprecated_assertion { assert_success }
265
350
  end
266
-
351
+
267
352
  # -- standard request/response object testing --------------------------------
268
-
353
+
269
354
  # ensure our session is working properly
270
355
  def test_session_objects
271
356
  process :session_stuffing
272
357
  assert @response.has_session_object?('xmas')
273
- assert_session_equal 'turkey', 'xmas'
358
+ assert_deprecated_assertion { assert_session_equal 'turkey', 'xmas' }
274
359
  assert !@response.has_session_object?('easter')
275
360
  end
276
-
361
+
277
362
  # make sure that the template objects exist
278
363
  def test_template_objects_alive
279
364
  process :assign_this
280
365
  assert !@response.has_template_object?('hi')
281
366
  assert @response.has_template_object?('howdy')
282
367
  end
283
-
368
+
284
369
  # make sure we don't have template objects when we shouldn't
285
370
  def test_template_object_missing
286
371
  process :nothing
287
372
  assert_nil @response.template_objects['howdy']
288
373
  end
289
-
374
+
290
375
  def test_assigned_equal
291
376
  process :assign_this
292
- assert_assigned_equal "ho", :howdy
377
+ assert_deprecated_assertion { assert_assigned_equal "ho", :howdy }
293
378
  end
294
379
 
295
380
  # check the empty flashing
@@ -314,24 +399,25 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
314
399
  assert !@response.has_flash_with_contents?
315
400
  assert_nil @response.flash['hello']
316
401
  end
317
-
402
+
318
403
  # examine that the flash objects are what we expect
319
404
  def test_flash_equals
320
405
  process :flash_me
321
- assert_flash_equal 'my name is inigo montoya...', 'hello'
406
+ assert_deprecated_assertion do
407
+ assert_flash_equal 'my name is inigo montoya...', 'hello'
408
+ end
322
409
  end
323
-
324
-
325
- # check if we were rendered by a file-based template?
410
+
411
+ # check if we were rendered by a file-based template?
326
412
  def test_rendered_action
327
413
  process :nothing
328
414
  assert !@response.rendered_with_file?
329
415
 
330
- process :hello_world
416
+ assert_deprecated(/render/) { process :hello_world }
331
417
  assert @response.rendered_with_file?
332
418
  assert 'hello_world', @response.rendered_file
333
419
  end
334
-
420
+
335
421
  # check the redirection location
336
422
  def test_redirection_location
337
423
  process :redirect_internal
@@ -339,24 +425,26 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
339
425
 
340
426
  process :redirect_external
341
427
  assert_equal 'http://www.rubyonrails.org', @response.redirect_url
428
+ end
342
429
 
430
+ def test_no_redirect_url
343
431
  process :nothing
344
432
  assert_nil @response.redirect_url
345
433
  end
346
-
347
-
348
- # check server errors
434
+
435
+
436
+ # check server errors
349
437
  def test_server_error_response_code
350
438
  process :response500
351
439
  assert @response.server_error?
352
-
440
+
353
441
  process :response599
354
442
  assert @response.server_error?
355
-
443
+
356
444
  process :response404
357
445
  assert !@response.server_error?
358
446
  end
359
-
447
+
360
448
  # check a 404 response code
361
449
  def test_missing_response_code
362
450
  process :response404
@@ -372,7 +460,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
372
460
  assert !@response.redirect_url_match?("phpoffrails")
373
461
  assert !@response.redirect_url_match?(/perloffrails/)
374
462
  end
375
-
463
+
376
464
  # check for a redirection
377
465
  def test_redirection
378
466
  process :redirect_internal
@@ -384,51 +472,57 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
384
472
  process :nothing
385
473
  assert !@response.redirect?
386
474
  end
387
-
475
+
388
476
  # check a successful response code
389
477
  def test_successful_response_code
390
478
  process :nothing
391
479
  assert @response.success?
392
- end
393
-
480
+ end
481
+
394
482
  # a basic check to make sure we have a TestResponse object
395
483
  def test_has_response
396
484
  process :nothing
397
485
  assert_kind_of ActionController::TestResponse, @response
398
486
  end
399
-
487
+
400
488
  def test_render_based_on_parameters
401
489
  process :render_based_on_parameters, "name" => "David"
402
490
  assert_equal "Mr. David", @response.body
403
491
  end
404
492
 
405
493
  def test_assert_template_xpath_match_no_matches
406
- process :hello_xml_world
494
+ assert_deprecated(/render/) { process :hello_xml_world }
407
495
  assert_raises Test::Unit::AssertionFailedError do
408
- assert_template_xpath_match('/no/such/node/in/document')
496
+ assert_deprecated_assertion do
497
+ assert_template_xpath_match('/no/such/node/in/document')
498
+ end
409
499
  end
410
500
  end
411
501
 
412
502
  def test_simple_one_element_xpath_match
413
- process :hello_xml_world
414
- assert_template_xpath_match('//title', "Hello World")
503
+ assert_deprecated(/render/) { process :hello_xml_world }
504
+ assert_deprecated_assertion do
505
+ assert_template_xpath_match('//title', "Hello World")
506
+ end
415
507
  end
416
508
 
417
509
  def test_array_of_elements_in_xpath_match
418
- process :hello_xml_world
419
- assert_template_xpath_match('//p', %w( abes monks wiseguys ))
510
+ assert_deprecated(/render/) { process :hello_xml_world }
511
+ assert_deprecated_assertion do
512
+ assert_template_xpath_match('//p', %w( abes monks wiseguys ))
513
+ end
420
514
  end
421
515
 
422
516
  def test_follow_redirect
423
517
  process :redirect_to_action
424
518
  assert_redirected_to :action => "flash_me"
425
-
519
+
426
520
  follow_redirect
427
521
  assert_equal 1, @request.parameters["id"].to_i
428
522
 
429
523
  assert "Inconceivable!", @response.body
430
524
  end
431
-
525
+
432
526
  def test_follow_redirect_outside_current_action
433
527
  process :redirect_to_controller
434
528
  assert_redirected_to :controller => "elsewhere", :action => "flash_me"
@@ -436,6 +530,18 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
436
530
  assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") { follow_redirect }
437
531
  end
438
532
 
533
+ def test_assert_redirection_fails_with_incorrect_controller
534
+ process :redirect_to_controller
535
+ assert_raise(Test::Unit::AssertionFailedError) do
536
+ assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
537
+ end
538
+ end
539
+
540
+ def test_assert_redirection_with_extra_controller_option
541
+ get :redirect_to_action
542
+ assert_redirected_to :controller => 'action_pack_assertions', :action => "flash_me", :id => 1, :params => { :panda => 'fun' }
543
+ end
544
+
439
545
  def test_redirected_to_url_leadling_slash
440
546
  process :redirect_to_path
441
547
  assert_redirected_to '/some/path'
@@ -453,41 +559,52 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
453
559
  @controller = Admin::InnerModuleController.new
454
560
  get :redirect_to_absolute_controller
455
561
  assert_redirected_to :controller => 'content'
456
-
562
+
457
563
  get :redirect_to_fellow_controller
458
564
  assert_redirected_to :controller => 'admin/user'
459
- end
460
-
565
+ end
566
+
461
567
  def test_assert_valid
462
568
  get :get_valid_record
463
- assert_valid assigns('record')
464
- end
465
-
569
+ assert_valid assigns('record')
570
+ end
571
+
466
572
  def test_assert_valid_failing
467
573
  get :get_invalid_record
468
-
574
+
469
575
  begin
470
- assert_valid assigns('record')
576
+ assert_valid assigns('record')
471
577
  assert false
472
- rescue Test::Unit::AssertionFailedError => e
578
+ rescue Test::Unit::AssertionFailedError => e
473
579
  end
474
580
  end
581
+
582
+ protected
583
+ def assert_deprecated_assertion(&block)
584
+ assert_deprecated(/assert/, &block)
585
+ end
475
586
  end
476
587
 
477
- class ActionPackHeaderTest < Test::Unit::TestCase
588
+ class ActionPackHeaderTest < Test::Unit::TestCase
478
589
  def setup
479
590
  @controller = ActionPackAssertionsController.new
480
591
  @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
481
592
  end
482
593
 
483
594
  def test_rendering_xml_sets_content_type
484
- process :hello_xml_world
485
- assert_equal('application/xml', @controller.headers['Content-Type'])
595
+ assert_deprecated(/render/) { process :hello_xml_world }
596
+ assert_equal('application/xml; charset=utf-8', @controller.headers['Content-Type'])
486
597
  end
487
598
 
488
599
  def test_rendering_xml_respects_content_type
489
600
  @response.headers['Content-Type'] = 'application/pdf'
490
- process :hello_xml_world
491
- assert_equal('application/pdf', @controller.headers['Content-Type'])
601
+ assert_deprecated(/render/) { process :hello_xml_world }
602
+ assert_equal('application/pdf; charset=utf-8', @controller.headers['Content-Type'])
603
+ end
604
+
605
+
606
+ def test_render_text_with_custom_content_type
607
+ get :render_text_with_custom_content_type
608
+ assert_equal 'application/rss+xml; charset=utf-8', @response.headers['Content-Type']
492
609
  end
493
610
  end