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
@@ -2,7 +2,7 @@ require 'abstract_unit'
2
2
 
3
3
  class Post
4
4
  def id
5
- 45
5
+ 45
6
6
  end
7
7
  def body
8
8
  "What a wonderful world!"
@@ -15,40 +15,44 @@ class RecordTagHelperTest < ActionView::TestCase
15
15
  def setup
16
16
  @post = Post.new
17
17
  end
18
-
18
+
19
19
  def test_content_tag_for
20
- _erbout = ''
21
20
  expected = %(<li class="post bar" id="post_45"></li>)
22
21
  actual = content_tag_for(:li, @post, :class => 'bar') { }
23
22
  assert_dom_equal expected, actual
24
23
  end
25
-
24
+
26
25
  def test_content_tag_for_prefix
27
- _erbout = ''
28
26
  expected = %(<ul class="post" id="archived_post_45"></ul>)
29
27
  actual = content_tag_for(:ul, @post, :archived) { }
30
- assert_dom_equal expected, actual
28
+ assert_dom_equal expected, actual
31
29
  end
32
-
30
+
33
31
  def test_content_tag_for_with_extra_html_tags
34
- _erbout = ''
35
32
  expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>)
36
33
  actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { }
37
- assert_dom_equal expected, actual
34
+ assert_dom_equal expected, actual
35
+ end
36
+
37
+ def test_block_not_in_erb_multiple_calls
38
+ expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
39
+ actual = div_for(@post, :class => "bar") { @post.body }
40
+ assert_dom_equal expected, actual
41
+ actual = div_for(@post, :class => "bar") { @post.body }
42
+ assert_dom_equal expected, actual
38
43
  end
39
-
40
- def test_block_works_with_content_tag_for
41
- _erbout = ''
44
+
45
+ def test_block_works_with_content_tag_for_in_erb
46
+ __in_erb_template = ''
42
47
  expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
43
- actual = content_tag_for(:tr, @post) { _erbout.concat @post.body }
44
- assert_dom_equal expected, actual
48
+ actual = content_tag_for(:tr, @post) { concat @post.body }
49
+ assert_dom_equal expected, actual
45
50
  end
46
-
47
- def test_div_for
48
- _erbout = ''
51
+
52
+ def test_div_for_in_erb
53
+ __in_erb_template = ''
49
54
  expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
50
- actual = div_for(@post, :class => "bar") { _erbout.concat @post.body }
55
+ actual = div_for(@post, :class => "bar") { concat @post.body }
51
56
  assert_dom_equal expected, actual
52
- end
53
-
57
+ end
54
58
  end
@@ -0,0 +1,193 @@
1
+ require 'abstract_unit'
2
+ require 'controller/fake_models'
3
+
4
+ class ViewRenderTest < Test::Unit::TestCase
5
+ def setup
6
+ @assigns = { :secret => 'in the sauce' }
7
+ @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns)
8
+ end
9
+
10
+ def test_render_file
11
+ assert_deprecated do
12
+ assert_equal "Hello world!", @view.render("test/hello_world.erb")
13
+ end
14
+ end
15
+
16
+ def test_render_file_not_using_full_path
17
+ assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb")
18
+ end
19
+
20
+ def test_render_file_without_specific_extension
21
+ assert_deprecated do
22
+ assert_equal "Hello world!", @view.render("test/hello_world")
23
+ end
24
+ end
25
+
26
+ def test_render_file_at_top_level
27
+ assert_deprecated do
28
+ assert_equal 'Elastica', @view.render('/shared')
29
+ end
30
+ end
31
+
32
+ def test_render_file_with_full_path
33
+ template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb')
34
+ assert_equal "Hello world!", @view.render(:file => template_path)
35
+ end
36
+
37
+ def test_render_file_with_instance_variables
38
+ assert_deprecated do
39
+ assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb")
40
+ end
41
+ end
42
+
43
+ def test_render_file_with_locals
44
+ locals = { :secret => 'in the sauce' }
45
+ assert_deprecated do
46
+ assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals)
47
+ end
48
+ end
49
+
50
+ def test_render_file_not_using_full_path_with_dot_in_path
51
+ assert_deprecated do
52
+ assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar")
53
+ end
54
+ end
55
+
56
+ def test_render_has_access_current_template
57
+ assert_deprecated do
58
+ assert_equal "test/template.erb", @view.render("test/template.erb")
59
+ end
60
+ end
61
+
62
+ def test_render_update
63
+ # TODO: You should not have to stub out template because template is self!
64
+ @view.instance_variable_set(:@template, @view)
65
+ assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') }
66
+ end
67
+
68
+ def test_render_partial
69
+ assert_equal "only partial", @view.render(:partial => "test/partial_only")
70
+ end
71
+
72
+ def test_render_partial_with_format
73
+ assert_equal 'partial html', @view.render(:partial => 'test/partial')
74
+ end
75
+
76
+ def test_render_partial_at_top_level
77
+ # file fixtures/_top_level_partial_only.erb (not fixtures/test)
78
+ assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only')
79
+ end
80
+
81
+ def test_render_partial_with_format_at_top_level
82
+ # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension)
83
+ assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial')
84
+ end
85
+
86
+ def test_render_partial_with_locals
87
+ assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 })
88
+ end
89
+
90
+ def test_render_partial_with_errors
91
+ @view.render(:partial => "test/raise")
92
+ flunk "Render did not raise TemplateError"
93
+ rescue ActionView::TemplateError => e
94
+ assert_match "undefined local variable or method `doesnt_exist'", e.message
95
+ assert_equal "", e.sub_template_message
96
+ assert_equal "1", e.line_number
97
+ assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
98
+ end
99
+
100
+ def test_render_sub_template_with_errors
101
+ @view.render(:file => "test/sub_template_raise")
102
+ flunk "Render did not raise TemplateError"
103
+ rescue ActionView::TemplateError => e
104
+ assert_match "undefined local variable or method `doesnt_exist'", e.message
105
+ assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message
106
+ assert_equal "1", e.line_number
107
+ assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
108
+ end
109
+
110
+ def test_render_partial_collection
111
+ assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
112
+ end
113
+
114
+ def test_render_partial_collection_as
115
+ assert_equal "david david davidmary mary mary",
116
+ @view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer)
117
+ end
118
+
119
+ def test_render_partial_collection_without_as
120
+ assert_equal "local_inspector,local_inspector_counter,object",
121
+ @view.render(:partial => "test/local_inspector", :collection => [ Customer.new("mary") ])
122
+ end
123
+
124
+ def test_render_partial_with_empty_collection_should_return_nil
125
+ assert_nil @view.render(:partial => "test/customer", :collection => [])
126
+ end
127
+
128
+ def test_render_partial_with_nil_collection_should_return_nil
129
+ assert_nil @view.render(:partial => "test/customer", :collection => nil)
130
+ end
131
+
132
+ def test_render_partial_with_nil_values_in_collection
133
+ assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ])
134
+ end
135
+
136
+ def test_render_partial_with_empty_array_should_return_nil
137
+ assert_nil @view.render(:partial => [])
138
+ end
139
+
140
+ # TODO: The reason for this test is unclear, improve documentation
141
+ def test_render_partial_and_fallback_to_layout
142
+ assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
143
+ end
144
+
145
+ # TODO: The reason for this test is unclear, improve documentation
146
+ def test_render_js_partial_and_fallback_to_erb_layout
147
+ @view.template_format = :js
148
+ assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
149
+ end
150
+
151
+ # TODO: The reason for this test is unclear, improve documentation
152
+ def test_render_missing_xml_partial_and_raise_missing_template
153
+ @view.template_format = :xml
154
+ assert_raise(ActionView::MissingTemplate) { @view.render(:partial => "test/layout_for_partial") }
155
+ end
156
+
157
+ def test_render_inline
158
+ assert_equal "Hello, World!", @view.render(:inline => "Hello, World!")
159
+ end
160
+
161
+ def test_render_inline_with_locals
162
+ assert_equal "Hello, Josh!", @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" })
163
+ end
164
+
165
+ def test_render_fallbacks_to_erb_for_unknown_types
166
+ assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo)
167
+ end
168
+
169
+ CustomHandler = lambda do |template|
170
+ "@output_buffer = ''\n" +
171
+ "@output_buffer << 'source: #{template.source.inspect}'\n"
172
+ end
173
+
174
+ def test_render_inline_with_compilable_custom_type
175
+ ActionView::Template.register_template_handler :foo, CustomHandler
176
+ assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
177
+ end
178
+
179
+ def test_render_inline_with_locals_and_compilable_custom_type
180
+ ActionView::Template.register_template_handler :foo, CustomHandler
181
+ assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
182
+ end
183
+
184
+ def test_render_with_layout
185
+ assert_equal %(<title></title>\nHello world!\n),
186
+ @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
187
+ end
188
+
189
+ def test_render_with_nested_layout
190
+ assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n),
191
+ @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")
192
+ end
193
+ end
@@ -11,9 +11,9 @@ class SanitizeHelperTest < ActionView::TestCase
11
11
  assert_equal "Dont touch me", strip_links("Dont touch me")
12
12
  assert_equal "<a<a", strip_links("<a<a")
13
13
  assert_equal "on my mind\nall day long", strip_links("<a href='almost'>on my mind</a>\n<A href='almost'>all day long</A>")
14
- assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>")
15
- assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic")
16
- assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>")
14
+ assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>")
15
+ assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic")
16
+ assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>")
17
17
  assert_equal "My mind\nall <b>day</b> long", strip_links("<a href='almost'>My mind</a>\n<A href='almost'>all <b>day</b> long</A>")
18
18
  assert_equal "all <b>day</b> long", strip_links("<<a>a href='hello'>all <b>day</b> long<</A>/a>")
19
19
  end
@@ -19,6 +19,10 @@ class TagHelperTest < ActionView::TestCase
19
19
  assert_equal "<p />", tag("p", :ignored => nil)
20
20
  end
21
21
 
22
+ def test_tag_options_accepts_false_option
23
+ assert_equal "<p value=\"false\" />", tag("p", :value => false)
24
+ end
25
+
22
26
  def test_tag_options_accepts_blank_option
23
27
  assert_equal "<p included=\"\" />", tag("p", :included => '')
24
28
  end
@@ -33,24 +37,40 @@ class TagHelperTest < ActionView::TestCase
33
37
  assert_equal content_tag("a", "Create", "href" => "create"),
34
38
  content_tag("a", "Create", :href => "create")
35
39
  end
36
-
37
- def test_content_tag_with_block
38
- _erbout = ''
39
- content_tag(:div) { _erbout.concat "Hello world!" }
40
- assert_dom_equal "<div>Hello world!</div>", _erbout
40
+
41
+ def test_content_tag_with_block_in_erb
42
+ __in_erb_template = ''
43
+ content_tag(:div) { concat "Hello world!" }
44
+ assert_dom_equal "<div>Hello world!</div>", output_buffer
41
45
  end
42
-
43
- def test_content_tag_with_block_and_options
44
- _erbout = ''
45
- content_tag(:div, :class => "green") { _erbout.concat "Hello world!" }
46
- assert_dom_equal %(<div class="green">Hello world!</div>), _erbout
46
+
47
+ def test_content_tag_with_block_and_options_in_erb
48
+ __in_erb_template = ''
49
+ content_tag(:div, :class => "green") { concat "Hello world!" }
50
+ assert_dom_equal %(<div class="green">Hello world!</div>), output_buffer
47
51
  end
48
-
49
- def test_content_tag_with_block_and_options_outside_of_action_view
52
+
53
+ def test_content_tag_with_block_and_options_out_of_erb
54
+ assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, :class => "green") { "Hello world!" }
55
+ end
56
+
57
+ def test_content_tag_with_block_and_options_outside_out_of_erb
50
58
  assert_equal content_tag("a", "Create", :href => "create"),
51
- content_tag("a", "href" => "create") { "Create" }
59
+ content_tag("a", "href" => "create") { "Create" }
52
60
  end
53
-
61
+
62
+ def test_content_tag_nested_in_content_tag_out_of_erb
63
+ assert_equal content_tag("p", content_tag("b", "Hello")),
64
+ content_tag("p") { content_tag("b", "Hello") },
65
+ output_buffer
66
+ end
67
+
68
+ def test_content_tag_nested_in_content_tag_in_erb
69
+ __in_erb_template = true
70
+ content_tag("p") { concat content_tag("b", "Hello") }
71
+ assert_equal '<p><b>Hello</b></p>', output_buffer
72
+ end
73
+
54
74
  def test_cdata_section
55
75
  assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
56
76
  end
@@ -11,6 +11,12 @@ class TextHelperTest < ActionView::TestCase
11
11
  @_cycles = nil if (defined? @_cycles)
12
12
  end
13
13
 
14
+ def test_concat
15
+ self.output_buffer = 'foo'
16
+ assert_equal 'foobar', concat('bar')
17
+ assert_equal 'foobar', output_buffer
18
+ end
19
+
14
20
  def test_simple_format
15
21
  assert_equal "<p></p>", simple_format(nil)
16
22
 
@@ -29,8 +35,8 @@ class TextHelperTest < ActionView::TestCase
29
35
  end
30
36
 
31
37
  def test_truncate
32
- assert_equal "Hello World!", truncate("Hello World!", 12)
33
- assert_equal "Hello Wor...", truncate("Hello World!!", 12)
38
+ assert_equal "Hello World!", truncate("Hello World!", :length => 12)
39
+ assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12)
34
40
  end
35
41
 
36
42
  def test_truncate_should_use_default_length_of_30
@@ -38,23 +44,29 @@ class TextHelperTest < ActionView::TestCase
38
44
  assert_equal str[0...27] + "...", truncate(str)
39
45
  end
40
46
 
47
+ def test_truncate_with_options_hash
48
+ assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]")
49
+ assert_equal "Hello W...", truncate("Hello World!", :length => 10)
50
+ assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10)
51
+ end
52
+
41
53
  if RUBY_VERSION < '1.9.0'
42
54
  def test_truncate_multibyte
43
55
  with_kcode 'none' do
44
- assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
56
+ assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10)
45
57
  end
46
58
  with_kcode 'u' do
47
59
  assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
48
- truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", 10)
60
+ truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", :length => 10)
49
61
  end
50
62
  end
51
63
  else
52
64
  def test_truncate_multibyte
53
65
  assert_equal "\354\225\210\353\205\225\355...",
54
- truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
66
+ truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10)
55
67
 
56
68
  assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
57
- truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), 10)
69
+ truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10)
58
70
  end
59
71
  end
60
72
 
@@ -82,7 +94,7 @@ class TextHelperTest < ActionView::TestCase
82
94
  assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
83
95
  end
84
96
 
85
- def test_highlighter_with_regexp
97
+ def test_highlight_with_regexp
86
98
  assert_equal(
87
99
  "This is a <strong class=\"highlight\">beautiful!</strong> morning",
88
100
  highlight("This is a beautiful! morning", "beautiful!")
@@ -99,10 +111,17 @@ class TextHelperTest < ActionView::TestCase
99
111
  )
100
112
  end
101
113
 
102
- def test_highlighting_multiple_phrases_in_one_pass
114
+ def test_highlight_with_multiple_phrases_in_one_pass
103
115
  assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>')
104
116
  end
105
117
 
118
+ def test_highlight_with_options_hash
119
+ assert_equal(
120
+ "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
121
+ highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>')
122
+ )
123
+ end
124
+
106
125
  def test_excerpt
107
126
  assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
108
127
  assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
@@ -132,6 +151,16 @@ class TextHelperTest < ActionView::TestCase
132
151
  assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5))
133
152
  end
134
153
 
154
+ def test_excerpt_with_options_hash
155
+ assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
156
+ assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5))
157
+ assert_equal(
158
+ "This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]",
159
+ excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very",
160
+ :omission => "[...]")
161
+ )
162
+ end
163
+
135
164
  if RUBY_VERSION < '1.9'
136
165
  def test_excerpt_with_utf8
137
166
  with_kcode('u') do
@@ -156,6 +185,10 @@ class TextHelperTest < ActionView::TestCase
156
185
  assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15))
157
186
  end
158
187
 
188
+ def test_word_wrap_with_options_hash
189
+ assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
190
+ end
191
+
159
192
  def test_pluralization
160
193
  assert_equal("1 count", pluralize(1, "count"))
161
194
  assert_equal("2 counts", pluralize(2, "count"))
@@ -188,6 +221,7 @@ class TextHelperTest < ActionView::TestCase
188
221
  http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
189
222
  http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
190
223
  http://en.wikipedia.org/wiki/Texas_hold'em
224
+ https://www.google.com/doku.php?id=gps:resource:scs:start
191
225
  )
192
226
 
193
227
  urls.each do |url|
@@ -279,7 +313,13 @@ class TextHelperTest < ActionView::TestCase
279
313
  url = "http://api.rubyonrails.com/Foo.html"
280
314
  email = "fantabulous@shiznadel.ic"
281
315
 
282
- assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, 10) }
316
+ assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, :length => 10) }
317
+ end
318
+
319
+ def test_auto_link_with_options_hash
320
+ assert_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com">me@email.com</a>.',
321
+ auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
322
+ :link => :all, :html => { :class => "menu", :target => "_blank" })
283
323
  end
284
324
 
285
325
  def test_cycle_class
@@ -330,6 +370,40 @@ class TextHelperTest < ActionView::TestCase
330
370
  assert_equal("red", cycle("red", "blue", :name => "colors"))
331
371
  end
332
372
 
373
+ def test_current_cycle_with_default_name
374
+ cycle("even","odd")
375
+ assert_equal "even", current_cycle
376
+ cycle("even","odd")
377
+ assert_equal "odd", current_cycle
378
+ cycle("even","odd")
379
+ assert_equal "even", current_cycle
380
+ end
381
+
382
+ def test_current_cycle_with_named_cycles
383
+ cycle("red", "blue", :name => "colors")
384
+ assert_equal "red", current_cycle("colors")
385
+ cycle("red", "blue", :name => "colors")
386
+ assert_equal "blue", current_cycle("colors")
387
+ cycle("red", "blue", :name => "colors")
388
+ assert_equal "red", current_cycle("colors")
389
+ end
390
+
391
+ def test_current_cycle_safe_call
392
+ assert_nothing_raised { current_cycle }
393
+ assert_nothing_raised { current_cycle("colors") }
394
+ end
395
+
396
+ def test_current_cycle_with_more_than_two_names
397
+ cycle(1,2,3)
398
+ assert_equal "1", current_cycle
399
+ cycle(1,2,3)
400
+ assert_equal "2", current_cycle
401
+ cycle(1,2,3)
402
+ assert_equal "3", current_cycle
403
+ cycle(1,2,3)
404
+ assert_equal "1", current_cycle
405
+ end
406
+
333
407
  def test_default_named_cycle
334
408
  assert_equal("1", cycle(1, 2, 3))
335
409
  assert_equal("2", cycle(1, 2, 3, :name => "default"))