actionpack 2.1.2 → 2.2.2

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 (200) hide show
  1. data/CHANGELOG +223 -7
  2. data/README +6 -12
  3. data/Rakefile +11 -11
  4. data/lib/action_controller.rb +9 -9
  5. data/lib/action_controller/assertions/response_assertions.rb +29 -78
  6. data/lib/action_controller/assertions/routing_assertions.rb +33 -33
  7. data/lib/action_controller/assertions/selector_assertions.rb +9 -5
  8. data/lib/action_controller/base.rb +227 -161
  9. data/lib/action_controller/benchmarking.rb +37 -24
  10. data/lib/action_controller/caching/actions.rb +53 -21
  11. data/lib/action_controller/caching/fragments.rb +10 -36
  12. data/lib/action_controller/caching/sweeping.rb +3 -3
  13. data/lib/action_controller/cgi_ext/session.rb +2 -22
  14. data/lib/action_controller/cgi_process.rb +8 -46
  15. data/lib/action_controller/components.rb +4 -1
  16. data/lib/action_controller/cookies.rb +10 -0
  17. data/lib/action_controller/dispatcher.rb +49 -15
  18. data/lib/action_controller/filters.rb +48 -10
  19. data/lib/action_controller/headers.rb +16 -14
  20. data/lib/action_controller/helpers.rb +2 -2
  21. data/lib/action_controller/http_authentication.rb +1 -1
  22. data/lib/action_controller/integration.rb +57 -60
  23. data/lib/action_controller/layout.rb +27 -53
  24. data/lib/action_controller/mime_responds.rb +5 -1
  25. data/lib/action_controller/mime_type.rb +64 -42
  26. data/lib/action_controller/mime_types.rb +2 -1
  27. data/lib/action_controller/performance_test.rb +16 -0
  28. data/lib/action_controller/polymorphic_routes.rb +16 -9
  29. data/lib/action_controller/rack_process.rb +303 -0
  30. data/lib/action_controller/request.rb +205 -97
  31. data/lib/action_controller/request_forgery_protection.rb +2 -2
  32. data/lib/action_controller/request_profiler.rb +0 -0
  33. data/lib/action_controller/rescue.rb +20 -115
  34. data/lib/action_controller/resources.rb +186 -83
  35. data/lib/action_controller/response.rb +140 -26
  36. data/lib/action_controller/routing.rb +28 -30
  37. data/lib/action_controller/routing/builder.rb +45 -54
  38. data/lib/action_controller/routing/optimisations.rb +31 -21
  39. data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
  40. data/lib/action_controller/routing/route.rb +162 -147
  41. data/lib/action_controller/routing/route_set.rb +8 -7
  42. data/lib/action_controller/routing/routing_ext.rb +4 -1
  43. data/lib/action_controller/routing/segments.rb +50 -21
  44. data/lib/action_controller/session/cookie_store.rb +3 -2
  45. data/lib/action_controller/session/drb_server.rb +7 -7
  46. data/lib/action_controller/session_management.rb +6 -2
  47. data/lib/action_controller/streaming.rb +15 -8
  48. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  49. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  50. data/lib/action_controller/test_case.rb +66 -2
  51. data/lib/action_controller/test_process.rb +71 -66
  52. data/lib/action_controller/translation.rb +13 -0
  53. data/lib/action_controller/url_rewriter.rb +90 -13
  54. data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
  55. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
  56. data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
  57. data/lib/action_controller/verification.rb +2 -2
  58. data/lib/action_pack/version.rb +1 -1
  59. data/lib/action_view.rb +19 -11
  60. data/lib/action_view/base.rb +184 -150
  61. data/lib/action_view/helpers.rb +38 -0
  62. data/lib/action_view/helpers/active_record_helper.rb +56 -27
  63. data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
  64. data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
  65. data/lib/action_view/helpers/benchmark_helper.rb +3 -3
  66. data/lib/action_view/helpers/cache_helper.rb +1 -2
  67. data/lib/action_view/helpers/capture_helper.rb +19 -44
  68. data/lib/action_view/helpers/date_helper.rb +486 -296
  69. data/lib/action_view/helpers/debug_helper.rb +20 -13
  70. data/lib/action_view/helpers/form_helper.rb +71 -30
  71. data/lib/action_view/helpers/form_options_helper.rb +15 -85
  72. data/lib/action_view/helpers/form_tag_helper.rb +61 -38
  73. data/lib/action_view/helpers/javascript_helper.rb +80 -89
  74. data/lib/action_view/helpers/number_helper.rb +179 -74
  75. data/lib/action_view/helpers/prototype_helper.rb +216 -201
  76. data/lib/action_view/helpers/record_tag_helper.rb +4 -5
  77. data/lib/action_view/helpers/sanitize_helper.rb +65 -33
  78. data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
  79. data/lib/action_view/helpers/tag_helper.rb +39 -22
  80. data/lib/action_view/helpers/text_helper.rb +212 -118
  81. data/lib/action_view/helpers/translation_helper.rb +21 -0
  82. data/lib/action_view/helpers/url_helper.rb +100 -58
  83. data/lib/action_view/inline_template.rb +13 -14
  84. data/lib/action_view/locale/en.yml +91 -0
  85. data/lib/action_view/partials.rb +100 -55
  86. data/lib/action_view/paths.rb +125 -0
  87. data/lib/action_view/renderable.rb +102 -0
  88. data/lib/action_view/renderable_partial.rb +48 -0
  89. data/lib/action_view/template.rb +90 -101
  90. data/lib/action_view/template_error.rb +11 -21
  91. data/lib/action_view/template_handler.rb +8 -28
  92. data/lib/action_view/template_handlers.rb +45 -0
  93. data/lib/action_view/template_handlers/builder.rb +5 -15
  94. data/lib/action_view/template_handlers/erb.rb +9 -6
  95. data/lib/action_view/template_handlers/rjs.rb +2 -17
  96. data/lib/action_view/test_case.rb +7 -4
  97. data/test/abstract_unit.rb +4 -1
  98. data/test/active_record_unit.rb +28 -30
  99. data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
  100. data/test/controller/action_pack_assertions_test.rb +8 -37
  101. data/test/controller/addresses_render_test.rb +0 -3
  102. data/test/controller/assert_select_test.rb +51 -24
  103. data/test/controller/base_test.rb +4 -4
  104. data/test/controller/caching_test.rb +136 -66
  105. data/test/controller/capture_test.rb +1 -21
  106. data/test/controller/cgi_test.rb +157 -10
  107. data/test/controller/components_test.rb +41 -25
  108. data/test/controller/content_type_test.rb +49 -17
  109. data/test/controller/cookie_test.rb +1 -1
  110. data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
  111. data/test/controller/dispatcher_test.rb +9 -1
  112. data/test/controller/filter_params_test.rb +2 -2
  113. data/test/controller/filters_test.rb +13 -13
  114. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  115. data/test/controller/html-scanner/node_test.rb +21 -0
  116. data/test/controller/html-scanner/sanitizer_test.rb +14 -0
  117. data/test/controller/integration_test.rb +167 -6
  118. data/test/controller/layout_test.rb +11 -68
  119. data/test/controller/logging_test.rb +46 -0
  120. data/test/controller/mime_responds_test.rb +61 -59
  121. data/test/controller/mime_type_test.rb +6 -6
  122. data/test/controller/polymorphic_routes_test.rb +37 -2
  123. data/test/controller/rack_test.rb +323 -0
  124. data/test/controller/redirect_test.rb +72 -71
  125. data/test/controller/render_test.rb +1120 -108
  126. data/test/controller/request_forgery_protection_test.rb +66 -52
  127. data/test/controller/request_test.rb +103 -146
  128. data/test/controller/rescue_test.rb +20 -24
  129. data/test/controller/resources_test.rb +408 -25
  130. data/test/controller/routing_test.rb +1774 -1774
  131. data/test/controller/send_file_test.rb +0 -4
  132. data/test/controller/session/cookie_store_test.rb +53 -1
  133. data/test/controller/test_test.rb +15 -37
  134. data/test/controller/translation_test.rb +26 -0
  135. data/test/controller/url_rewriter_test.rb +27 -28
  136. data/test/controller/view_paths_test.rb +48 -47
  137. data/test/fixtures/_top_level_partial.html.erb +1 -0
  138. data/test/fixtures/_top_level_partial_only.erb +1 -0
  139. data/test/fixtures/developers/_developer.erb +1 -0
  140. data/test/fixtures/fun/games/_game.erb +1 -0
  141. data/test/fixtures/fun/serious/games/_game.erb +1 -0
  142. data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
  143. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
  144. data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
  145. data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
  146. data/test/fixtures/layouts/_column.html.erb +2 -0
  147. data/test/fixtures/projects/_project.erb +1 -0
  148. data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
  149. data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
  150. data/test/fixtures/replies/_reply.erb +1 -0
  151. data/test/fixtures/test/_counter.html.erb +1 -0
  152. data/test/fixtures/test/_customer.erb +1 -1
  153. data/test/fixtures/test/_customer_with_var.erb +1 -0
  154. data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
  155. data/test/fixtures/test/_local_inspector.html.erb +1 -0
  156. data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
  157. data/test/fixtures/test/hello.builder +1 -1
  158. data/test/fixtures/test/hyphen-ated.erb +1 -0
  159. data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
  160. data/test/fixtures/test/nested_layout.erb +3 -0
  161. data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
  162. data/test/fixtures/test/sub_template_raise.html.erb +1 -0
  163. data/test/fixtures/test/template.erb +1 -0
  164. data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
  165. data/test/template/active_record_helper_i18n_test.rb +46 -0
  166. data/test/template/active_record_helper_test.rb +24 -24
  167. data/test/template/asset_tag_helper_test.rb +161 -29
  168. data/test/template/atom_feed_helper_test.rb +114 -5
  169. data/test/template/compiled_templates_test.rb +59 -0
  170. data/test/template/date_helper_i18n_test.rb +113 -0
  171. data/test/template/date_helper_test.rb +403 -109
  172. data/test/template/form_helper_test.rb +213 -154
  173. data/test/template/form_options_helper_test.rb +249 -897
  174. data/test/template/form_tag_helper_test.rb +80 -32
  175. data/test/template/javascript_helper_test.rb +17 -18
  176. data/test/template/number_helper_i18n_test.rb +54 -0
  177. data/test/template/number_helper_test.rb +43 -13
  178. data/test/template/prototype_helper_test.rb +101 -84
  179. data/test/template/record_tag_helper_test.rb +24 -20
  180. data/test/template/render_test.rb +193 -0
  181. data/test/template/sanitize_helper_test.rb +3 -3
  182. data/test/template/tag_helper_test.rb +34 -14
  183. data/test/template/text_helper_test.rb +83 -9
  184. data/test/template/translation_helper_test.rb +28 -0
  185. data/test/template/url_helper_test.rb +55 -18
  186. metadata +57 -18
  187. data/lib/action_view/helpers/javascripts/controls.js +0 -963
  188. data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
  189. data/lib/action_view/helpers/javascripts/effects.js +0 -1120
  190. data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
  191. data/lib/action_view/partial_template.rb +0 -70
  192. data/lib/action_view/template_finder.rb +0 -177
  193. data/lib/action_view/template_handlers/compilable.rb +0 -128
  194. data/test/controller/custom_handler_test.rb +0 -45
  195. data/test/controller/new_render_test.rb +0 -945
  196. data/test/fixtures/test/block_content_for.erb +0 -2
  197. data/test/fixtures/test/erb_content_for.erb +0 -2
  198. data/test/template/deprecated_erb_variable_test.rb +0 -9
  199. data/test/template/template_finder_test.rb +0 -73
  200. data/test/template/template_object_test.rb +0 -95
@@ -25,9 +25,7 @@ module ActionView
25
25
  end
26
26
  end
27
27
 
28
- ActionView::Base.helper_modules.each do |helper_module|
29
- include helper_module
30
- end
28
+ include ActionView::Helpers
31
29
  include ActionController::PolymorphicRoutes
32
30
  include ActionController::RecordIdentifier
33
31
 
@@ -37,6 +35,8 @@ module ActionView
37
35
  if helper_class && !self.class.ancestors.include?(helper_class)
38
36
  self.class.send(:include, helper_class)
39
37
  end
38
+
39
+ self.output_buffer = ''
40
40
  end
41
41
 
42
42
  class TestController < ActionController::Base
@@ -48,10 +48,13 @@ module ActionView
48
48
  end
49
49
  end
50
50
 
51
+ protected
52
+ attr_accessor :output_buffer
53
+
51
54
  private
52
55
  def method_missing(selector, *args)
53
56
  controller = TestController.new
54
- return controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
57
+ return controller.__send__(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
55
58
  super
56
59
  end
57
60
  end
@@ -1,5 +1,5 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib/active_support')
2
+ $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
3
3
  $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
4
4
 
5
5
  require 'yaml'
@@ -22,6 +22,9 @@ ActiveSupport::Deprecation.debug = true
22
22
  ActionController::Base.logger = nil
23
23
  ActionController::Routing::Routes.reload rescue nil
24
24
 
25
+ FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
26
+ ActionView::PathSet::Path.eager_load_templates!
27
+ ActionController::Base.view_paths = FIXTURE_LOAD_PATH
25
28
 
26
29
  # Wrap tests that use Mocha and skip if unavailable.
27
30
  def uses_mocha(test_name)
@@ -30,7 +30,6 @@ end
30
30
  $stderr.flush
31
31
 
32
32
 
33
-
34
33
  # Define the rest of the connector
35
34
  class ActiveRecordTestConnector
36
35
  class << self
@@ -48,46 +47,45 @@ class ActiveRecordTestConnector
48
47
  end
49
48
 
50
49
  private
51
-
52
- def setup_connection
53
- if Object.const_defined?(:ActiveRecord)
54
- defaults = { :database => ':memory:' }
55
- begin
56
- options = defaults.merge :adapter => 'sqlite3', :timeout => 500
57
- ActiveRecord::Base.establish_connection(options)
58
- ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
59
- ActiveRecord::Base.connection
60
- rescue Exception # errors from establishing a connection
61
- $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
62
- options = defaults.merge :adapter => 'sqlite'
63
- ActiveRecord::Base.establish_connection(options)
64
- ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
65
- ActiveRecord::Base.connection
50
+ def setup_connection
51
+ if Object.const_defined?(:ActiveRecord)
52
+ defaults = { :database => ':memory:' }
53
+ begin
54
+ options = defaults.merge :adapter => 'sqlite3', :timeout => 500
55
+ ActiveRecord::Base.establish_connection(options)
56
+ ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
57
+ ActiveRecord::Base.connection
58
+ rescue Exception # errors from establishing a connection
59
+ $stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
60
+ options = defaults.merge :adapter => 'sqlite'
61
+ ActiveRecord::Base.establish_connection(options)
62
+ ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
63
+ ActiveRecord::Base.connection
64
+ end
65
+
66
+ Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
67
+ else
68
+ raise "Can't setup connection since ActiveRecord isn't loaded."
66
69
  end
67
-
68
- Object.send(:const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')) unless Object.const_defined?(:QUOTED_TYPE)
69
- else
70
- raise "Can't setup connection since ActiveRecord isn't loaded."
71
70
  end
72
- end
73
71
 
74
- # Load actionpack sqlite tables
75
- def load_schema
76
- File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
77
- ActiveRecord::Base.connection.execute(sql) unless sql.blank?
72
+ # Load actionpack sqlite tables
73
+ def load_schema
74
+ File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
75
+ ActiveRecord::Base.connection.execute(sql) unless sql.blank?
76
+ end
78
77
  end
79
- end
80
78
 
81
- def require_fixture_models
82
- Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f}
83
- end
79
+ def require_fixture_models
80
+ Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f}
81
+ end
84
82
  end
85
83
  end
86
84
 
87
85
  class ActiveRecordTestCase < ActiveSupport::TestCase
88
86
  # Set our fixture path
89
87
  if ActiveRecordTestConnector.able_to_connect
90
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
88
+ self.fixture_path = [FIXTURE_LOAD_PATH]
91
89
  self.use_transactional_fixtures = false
92
90
  end
93
91
 
@@ -39,12 +39,16 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
39
39
  @developers = Developer.find(:all)
40
40
  render :partial => @developers
41
41
  end
42
+
43
+ def render_with_record_collection_and_spacer_template
44
+ @developer = Developer.find(1)
45
+ render :partial => @developer.projects, :spacer_template => 'test/partial_only'
46
+ end
42
47
  end
43
- RenderPartialWithRecordIdentificationController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
44
48
 
45
49
  class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
46
50
  fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots
47
-
51
+
48
52
  def setup
49
53
  @controller = RenderPartialWithRecordIdentificationController.new
50
54
  @request = ActionController::TestRequest.new
@@ -55,26 +59,36 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
55
59
  def test_rendering_partial_with_has_many_and_belongs_to_association
56
60
  get :render_with_has_many_and_belongs_to_association
57
61
  assert_template 'projects/_project'
62
+ assert_equal 'Active RecordActive Controller', @response.body
58
63
  end
59
-
64
+
60
65
  def test_rendering_partial_with_has_many_association
61
66
  get :render_with_has_many_association
62
67
  assert_template 'replies/_reply'
68
+ assert_equal 'Birdman is better!', @response.body
63
69
  end
64
-
70
+
65
71
  def test_rendering_partial_with_named_scope
66
72
  get :render_with_named_scope
67
73
  assert_template 'replies/_reply'
74
+ assert_equal 'Birdman is better!Nuh uh!', @response.body
68
75
  end
69
-
76
+
70
77
  def test_render_with_record
71
78
  get :render_with_record
72
79
  assert_template 'developers/_developer'
80
+ assert_equal 'David', @response.body
73
81
  end
74
-
82
+
75
83
  def test_render_with_record_collection
76
84
  get :render_with_record_collection
77
85
  assert_template 'developers/_developer'
86
+ assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body
87
+ end
88
+
89
+ def test_render_with_record_collection_and_spacer_template
90
+ get :render_with_record_collection_and_spacer_template
91
+ assert_equal 'Active Recordonly partialActive Controller', @response.body
78
92
  end
79
93
 
80
94
  def test_rendering_partial_with_has_one_association
@@ -116,7 +130,6 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
116
130
  render :partial => @developers
117
131
  end
118
132
  end
119
- RenderPartialWithRecordIdentificationController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
120
133
 
121
134
  class Game < Struct.new(:name, :id)
122
135
  def to_param
@@ -134,7 +147,6 @@ module Fun
134
147
  render :partial => [ Game.new("Pong"), Game.new("Tank") ]
135
148
  end
136
149
  end
137
- NestedController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
138
150
 
139
151
  module Serious
140
152
  class NestedDeeperController < ActionController::Base
@@ -146,7 +158,6 @@ module Fun
146
158
  render :partial => [ Game.new("Chess"), Game.new("Sudoku"), Game.new("Solitaire") ]
147
159
  end
148
160
  end
149
- NestedDeeperController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
150
161
  end
151
162
  end
152
163
 
@@ -161,13 +172,14 @@ class RenderPartialWithRecordIdentificationAndNestedControllersTest < ActiveReco
161
172
  def test_render_with_record_in_nested_controller
162
173
  get :render_with_record_in_nested_controller
163
174
  assert_template 'fun/games/_game'
175
+ assert_equal 'Pong', @response.body
164
176
  end
165
177
 
166
178
  def test_render_with_record_collection_in_nested_controller
167
179
  get :render_with_record_collection_in_nested_controller
168
180
  assert_template 'fun/games/_game'
181
+ assert_equal 'PongTank', @response.body
169
182
  end
170
-
171
183
  end
172
184
 
173
185
  class RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest < ActiveRecordTestCase
@@ -181,11 +193,12 @@ class RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest < Acti
181
193
  def test_render_with_record_in_deeper_nested_controller
182
194
  get :render_with_record_in_deeper_nested_controller
183
195
  assert_template 'fun/serious/games/_game'
196
+ assert_equal 'Chess', @response.body
184
197
  end
185
198
 
186
199
  def test_render_with_record_collection_in_deeper_nested_controller
187
200
  get :render_with_record_collection_in_deeper_nested_controller
188
201
  assert_template 'fun/serious/games/_game'
202
+ assert_equal 'ChessSudokuSolitaire', @response.body
189
203
  end
190
-
191
- end
204
+ end
@@ -157,21 +157,13 @@ module Admin
157
157
  def redirect_to_fellow_controller
158
158
  redirect_to :controller => 'user'
159
159
  end
160
-
160
+
161
161
  def redirect_to_top_level_named_route
162
162
  redirect_to top_level_url(:id => "foo")
163
163
  end
164
164
  end
165
165
  end
166
166
 
167
- # ---------------------------------------------------------------------------
168
-
169
-
170
- # tell the controller where to find its templates but start from parent
171
- # directory of test_request_response to simulate the behaviour of a
172
- # production environment
173
- ActionPackAssertionsController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
174
-
175
167
  # a test case to exercise the new capabilities TestRequest & TestResponse
176
168
  class ActionPackAssertionsControllerTest < Test::Unit::TestCase
177
169
  # let's get this party started
@@ -232,7 +224,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
232
224
  process :redirect_to_named_route
233
225
  assert_redirected_to 'http://test.host/route_one'
234
226
  assert_redirected_to route_one_url
235
- assert_redirected_to :route_one_url
236
227
  end
237
228
  end
238
229
 
@@ -253,9 +244,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
253
244
  assert_raise(Test::Unit::AssertionFailedError) do
254
245
  assert_redirected_to route_two_url
255
246
  end
256
- assert_raise(Test::Unit::AssertionFailedError) do
257
- assert_redirected_to :route_two_url
258
- end
259
247
  end
260
248
  end
261
249
 
@@ -340,11 +328,11 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
340
328
  # check if we were rendered by a file-based template?
341
329
  def test_rendered_action
342
330
  process :nothing
343
- assert !@response.rendered_with_file?
331
+ assert_nil @response.rendered_template
344
332
 
345
333
  process :hello_world
346
- assert @response.rendered_with_file?
347
- assert 'hello_world', @response.rendered_file
334
+ assert @response.rendered_template
335
+ assert 'hello_world', @response.rendered_template.to_s
348
336
  end
349
337
 
350
338
  # check the redirection location
@@ -419,24 +407,6 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
419
407
  assert_equal "Mr. David", @response.body
420
408
  end
421
409
 
422
- def test_follow_redirect
423
- process :redirect_to_action
424
- assert_redirected_to :action => "flash_me"
425
-
426
- assert_deprecated { follow_redirect }
427
- assert_equal 1, @request.parameters["id"].to_i
428
-
429
- assert "Inconceivable!", @response.body
430
- end
431
-
432
- def test_follow_redirect_outside_current_action
433
- process :redirect_to_controller
434
- assert_redirected_to :controller => "elsewhere", :action => "flash_me"
435
-
436
- assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") do
437
- assert_deprecated { follow_redirect }
438
- end
439
- end
440
410
 
441
411
  def test_assert_redirection_fails_with_incorrect_controller
442
412
  process :redirect_to_controller
@@ -450,14 +420,16 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
450
420
  assert_redirected_to :controller => 'action_pack_assertions', :action => "flash_me", :id => 1, :params => { :panda => 'fun' }
451
421
  end
452
422
 
453
- def test_redirected_to_url_leadling_slash
423
+ def test_redirected_to_url_leading_slash
454
424
  process :redirect_to_path
455
425
  assert_redirected_to '/some/path'
456
426
  end
427
+
457
428
  def test_redirected_to_url_no_leadling_slash
458
429
  process :redirect_to_path
459
430
  assert_redirected_to 'some/path'
460
431
  end
432
+
461
433
  def test_redirected_to_url_full_url
462
434
  process :redirect_to_path
463
435
  assert_redirected_to 'http://test.host/some/path'
@@ -477,7 +449,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
477
449
  def test_redirected_to_with_nested_controller
478
450
  @controller = Admin::InnerModuleController.new
479
451
  get :redirect_to_absolute_controller
480
- assert_redirected_to :controller => 'content'
452
+ assert_redirected_to :controller => '/content'
481
453
 
482
454
  get :redirect_to_fellow_controller
483
455
  assert_redirected_to :controller => 'admin/user'
@@ -535,7 +507,6 @@ class ActionPackHeaderTest < Test::Unit::TestCase
535
507
  assert_equal('application/pdf; charset=utf-8', @response.headers['type'])
536
508
  end
537
509
 
538
-
539
510
  def test_render_text_with_custom_content_type
540
511
  get :render_text_with_custom_content_type
541
512
  assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type']
@@ -1,7 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
3
  class Address
4
-
5
4
  def Address.count(conditions = nil, join = nil)
6
5
  nil
7
6
  end
@@ -20,8 +19,6 @@ class AddressesTestController < ActionController::Base
20
19
  def self.controller_path; "addresses"; end
21
20
  end
22
21
 
23
- AddressesTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
24
-
25
22
  class AddressesTest < Test::Unit::TestCase
26
23
  def setup
27
24
  @controller = AddressesTestController.new
@@ -17,6 +17,8 @@ unless defined?(ActionMailer)
17
17
  end
18
18
  end
19
19
 
20
+ ActionMailer::Base.template_root = FIXTURE_LOAD_PATH
21
+
20
22
  class AssertSelectTest < Test::Unit::TestCase
21
23
  class AssertSelectController < ActionController::Base
22
24
  def response_with=(content)
@@ -69,11 +71,10 @@ class AssertSelectTest < Test::Unit::TestCase
69
71
  ActionMailer::Base.deliveries = []
70
72
  end
71
73
 
72
-
73
74
  def teardown
74
75
  ActionMailer::Base.deliveries.clear
75
76
  end
76
-
77
+
77
78
  def assert_failure(message, &block)
78
79
  e = assert_raises(AssertionFailedError, &block)
79
80
  assert_match(message, e.message) if Regexp === message
@@ -91,7 +92,6 @@ class AssertSelectTest < Test::Unit::TestCase
91
92
  assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" }
92
93
  end
93
94
 
94
-
95
95
  def test_equality_true_false
96
96
  render_html %Q{<div id="1"></div><div id="2"></div>}
97
97
  assert_nothing_raised { assert_select "div" }
@@ -102,7 +102,6 @@ class AssertSelectTest < Test::Unit::TestCase
102
102
  assert_nothing_raised { assert_select "p", false }
103
103
  end
104
104
 
105
-
106
105
  def test_equality_string_and_regexp
107
106
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
108
107
  assert_nothing_raised { assert_select "div", "foo" }
@@ -116,7 +115,6 @@ class AssertSelectTest < Test::Unit::TestCase
116
115
  assert_raises(AssertionFailedError) { assert_select "p", :text=>/foobar/ }
117
116
  end
118
117
 
119
-
120
118
  def test_equality_of_html
121
119
  render_html %Q{<p>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</p>}
122
120
  text = "\"This is not a big problem,\" he said."
@@ -135,7 +133,6 @@ class AssertSelectTest < Test::Unit::TestCase
135
133
  assert_raises(AssertionFailedError) { assert_select "pre", :html=>text }
136
134
  end
137
135
 
138
-
139
136
  def test_counts
140
137
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
141
138
  assert_nothing_raised { assert_select "div", 2 }
@@ -166,7 +163,6 @@ class AssertSelectTest < Test::Unit::TestCase
166
163
  end
167
164
  end
168
165
 
169
-
170
166
  def test_substitution_values
171
167
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
172
168
  assert_select "div#?", /\d+/ do |elements|
@@ -181,7 +177,6 @@ class AssertSelectTest < Test::Unit::TestCase
181
177
  end
182
178
  end
183
179
 
184
-
185
180
  def test_nested_assert_select
186
181
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
187
182
  assert_select "div" do |elements|
@@ -200,7 +195,7 @@ class AssertSelectTest < Test::Unit::TestCase
200
195
  assert_select "#3", false
201
196
  end
202
197
  end
203
-
198
+
204
199
  assert_failure(/Expected at least 1 element matching \"#4\", found 0\./) do
205
200
  assert_select "div" do
206
201
  assert_select "#4"
@@ -208,7 +203,6 @@ class AssertSelectTest < Test::Unit::TestCase
208
203
  end
209
204
  end
210
205
 
211
-
212
206
  def test_assert_select_text_match
213
207
  render_html %Q{<div id="1"><span>foo</span></div><div id="2"><span>bar</span></div>}
214
208
  assert_select "div" do
@@ -225,7 +219,6 @@ class AssertSelectTest < Test::Unit::TestCase
225
219
  end
226
220
  end
227
221
 
228
-
229
222
  # With single result.
230
223
  def test_assert_select_from_rjs_with_single_result
231
224
  render_rjs do |page|
@@ -255,19 +248,16 @@ class AssertSelectTest < Test::Unit::TestCase
255
248
  end
256
249
  end
257
250
 
258
-
259
251
  #
260
252
  # Test css_select.
261
253
  #
262
254
 
263
-
264
255
  def test_css_select
265
256
  render_html %Q{<div id="1"></div><div id="2"></div>}
266
257
  assert 2, css_select("div").size
267
258
  assert 0, css_select("p").size
268
259
  end
269
260
 
270
-
271
261
  def test_nested_css_select
272
262
  render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
273
263
  assert_select "div#?", /\d+/ do |elements|
@@ -286,7 +276,6 @@ class AssertSelectTest < Test::Unit::TestCase
286
276
  end
287
277
  end
288
278
 
289
-
290
279
  # With one result.
291
280
  def test_css_select_from_rjs_with_single_result
292
281
  render_rjs do |page|
@@ -309,12 +298,10 @@ class AssertSelectTest < Test::Unit::TestCase
309
298
  assert_equal 1, css_select("#2").size
310
299
  end
311
300
 
312
-
313
301
  #
314
302
  # Test assert_select_rjs.
315
303
  #
316
304
 
317
-
318
305
  # Test that we can pick up all statements in the result.
319
306
  def test_assert_select_rjs_picks_up_all_statements
320
307
  render_rjs do |page|
@@ -381,7 +368,6 @@ class AssertSelectTest < Test::Unit::TestCase
381
368
  assert_raises(AssertionFailedError) { assert_select_rjs "test4" }
382
369
  end
383
370
 
384
-
385
371
  def test_assert_select_rjs_for_replace
386
372
  render_rjs do |page|
387
373
  page.replace "test1", "<div id=\"1\">foo</div>"
@@ -447,6 +433,17 @@ class AssertSelectTest < Test::Unit::TestCase
447
433
  assert_select_rjs :remove, "test1"
448
434
  end
449
435
 
436
+ def test_assert_select_rjs_for_remove_offers_useful_error_when_assertion_fails
437
+ render_rjs do |page|
438
+ page.remove "test_with_typo"
439
+ end
440
+
441
+ assert_select_rjs :remove, "test1"
442
+
443
+ rescue Test::Unit::AssertionFailedError
444
+ assert_equal "No RJS statement that removes 'test1' was rendered.", $!.message
445
+ end
446
+
450
447
  def test_assert_select_rjs_for_remove_ignores_block
451
448
  render_rjs do |page|
452
449
  page.remove "test1"
@@ -468,6 +465,17 @@ class AssertSelectTest < Test::Unit::TestCase
468
465
  assert_select_rjs :show, "test1"
469
466
  end
470
467
 
468
+ def test_assert_select_rjs_for_show_offers_useful_error_when_assertion_fails
469
+ render_rjs do |page|
470
+ page.show "test_with_typo"
471
+ end
472
+
473
+ assert_select_rjs :show, "test1"
474
+
475
+ rescue Test::Unit::AssertionFailedError
476
+ assert_equal "No RJS statement that shows 'test1' was rendered.", $!.message
477
+ end
478
+
471
479
  def test_assert_select_rjs_for_show_ignores_block
472
480
  render_rjs do |page|
473
481
  page.show "test1"
@@ -479,7 +487,7 @@ class AssertSelectTest < Test::Unit::TestCase
479
487
  end
480
488
  end
481
489
  end
482
-
490
+
483
491
  # Simple hide
484
492
  def test_assert_select_rjs_for_hide
485
493
  render_rjs do |page|
@@ -489,6 +497,17 @@ class AssertSelectTest < Test::Unit::TestCase
489
497
  assert_select_rjs :hide, "test1"
490
498
  end
491
499
 
500
+ def test_assert_select_rjs_for_hide_offers_useful_error_when_assertion_fails
501
+ render_rjs do |page|
502
+ page.hide "test_with_typo"
503
+ end
504
+
505
+ assert_select_rjs :hide, "test1"
506
+
507
+ rescue Test::Unit::AssertionFailedError
508
+ assert_equal "No RJS statement that hides 'test1' was rendered.", $!.message
509
+ end
510
+
492
511
  def test_assert_select_rjs_for_hide_ignores_block
493
512
  render_rjs do |page|
494
513
  page.hide "test1"
@@ -500,7 +519,7 @@ class AssertSelectTest < Test::Unit::TestCase
500
519
  end
501
520
  end
502
521
  end
503
-
522
+
504
523
  # Simple toggle
505
524
  def test_assert_select_rjs_for_toggle
506
525
  render_rjs do |page|
@@ -510,6 +529,17 @@ class AssertSelectTest < Test::Unit::TestCase
510
529
  assert_select_rjs :toggle, "test1"
511
530
  end
512
531
 
532
+ def test_assert_select_rjs_for_toggle_offers_useful_error_when_assertion_fails
533
+ render_rjs do |page|
534
+ page.toggle "test_with_typo"
535
+ end
536
+
537
+ assert_select_rjs :toggle, "test1"
538
+
539
+ rescue Test::Unit::AssertionFailedError
540
+ assert_equal "No RJS statement that toggles 'test1' was rendered.", $!.message
541
+ end
542
+
513
543
  def test_assert_select_rjs_for_toggle_ignores_block
514
544
  render_rjs do |page|
515
545
  page.toggle "test1"
@@ -521,7 +551,7 @@ class AssertSelectTest < Test::Unit::TestCase
521
551
  end
522
552
  end
523
553
  end
524
-
554
+
525
555
  # Non-positioned insert.
526
556
  def test_assert_select_rjs_for_nonpositioned_insert
527
557
  render_rjs do |page|
@@ -605,7 +635,6 @@ class AssertSelectTest < Test::Unit::TestCase
605
635
  end
606
636
  end
607
637
 
608
-
609
638
  def test_feed_item_encoded
610
639
  render_xml <<-EOF
611
640
  <rss version="2.0">
@@ -659,7 +688,6 @@ EOF
659
688
  end
660
689
  end
661
690
 
662
-
663
691
  #
664
692
  # Test assert_select_email
665
693
  #
@@ -675,7 +703,6 @@ EOF
675
703
  end
676
704
  end
677
705
 
678
-
679
706
  protected
680
707
  def render_html(html)
681
708
  @controller.response_with = html