actionpack 2.3.4 → 2.3.5

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 (74) hide show
  1. data/CHANGELOG +12 -0
  2. data/Rakefile +1 -1
  3. data/lib/action_controller.rb +3 -1
  4. data/lib/action_controller/assertions/dom_assertions.rb +19 -3
  5. data/lib/action_controller/assertions/selector_assertions.rb +16 -10
  6. data/lib/action_controller/base.rb +1 -1
  7. data/lib/action_controller/caching.rb +1 -0
  8. data/lib/action_controller/cookies.rb +2 -1
  9. data/lib/action_controller/http_authentication.rb +3 -2
  10. data/lib/action_controller/integration.rb +15 -3
  11. data/lib/action_controller/layout.rb +6 -1
  12. data/lib/action_controller/middlewares.rb +2 -0
  13. data/lib/action_controller/polymorphic_routes.rb +6 -21
  14. data/lib/action_controller/rack_lint_patch.rb +36 -0
  15. data/lib/action_controller/request_forgery_protection.rb +6 -2
  16. data/lib/action_controller/response.rb +2 -1
  17. data/lib/action_controller/string_coercion.rb +29 -0
  18. data/lib/action_controller/test_case.rb +6 -1
  19. data/lib/action_controller/test_process.rb +1 -1
  20. data/lib/action_controller/translation.rb +2 -2
  21. data/lib/action_controller/uploaded_file.rb +2 -2
  22. data/lib/action_controller/vendor/html-scanner/html/node.rb +1 -1
  23. data/lib/action_pack/version.rb +1 -1
  24. data/lib/action_view.rb +3 -3
  25. data/lib/action_view/base.rb +6 -1
  26. data/lib/action_view/erb/util.rb +6 -0
  27. data/lib/action_view/helpers.rb +2 -0
  28. data/lib/action_view/helpers/active_record_helper.rb +3 -3
  29. data/lib/action_view/helpers/asset_tag_helper.rb +2 -2
  30. data/lib/action_view/helpers/capture_helper.rb +2 -2
  31. data/lib/action_view/helpers/date_helper.rb +27 -15
  32. data/lib/action_view/helpers/form_helper.rb +32 -11
  33. data/lib/action_view/helpers/form_options_helper.rb +1 -1
  34. data/lib/action_view/helpers/form_tag_helper.rb +3 -3
  35. data/lib/action_view/helpers/number_helper.rb +6 -1
  36. data/lib/action_view/helpers/prototype_helper.rb +1 -1
  37. data/lib/action_view/helpers/raw_output_helper.rb +9 -0
  38. data/lib/action_view/helpers/sanitize_helper.rb +10 -2
  39. data/lib/action_view/helpers/tag_helper.rb +4 -4
  40. data/lib/action_view/helpers/translation_helper.rb +1 -1
  41. data/lib/action_view/helpers/url_helper.rb +3 -3
  42. data/lib/action_view/locale/en.yml +3 -0
  43. data/lib/action_view/partials.rb +1 -1
  44. data/lib/action_view/safe_buffer.rb +28 -0
  45. data/lib/action_view/template.rb +8 -2
  46. data/lib/action_view/test_case.rb +102 -27
  47. data/lib/actionpack.rb +1 -0
  48. data/test/controller/cookie_test.rb +7 -0
  49. data/test/controller/dom_assertions_test.rb +53 -0
  50. data/test/controller/filter_params_test.rb +1 -0
  51. data/test/controller/html-scanner/sanitizer_test.rb +1 -0
  52. data/test/controller/http_digest_authentication_test.rb +22 -0
  53. data/test/controller/integration_test.rb +38 -0
  54. data/test/controller/layout_test.rb +11 -0
  55. data/test/controller/polymorphic_routes_test.rb +4 -0
  56. data/test/controller/request_forgery_protection_test.rb +19 -1
  57. data/test/controller/routing_test.rb +23 -15
  58. data/test/controller/session/test_session_test.rb +2 -2
  59. data/test/fixtures/layout_tests/abs_path_layout.rhtml +1 -0
  60. data/test/fixtures/test/_from_helper.erb +1 -0
  61. data/test/template/active_record_helper_test.rb +1 -1
  62. data/test/template/asset_tag_helper_test.rb +12 -0
  63. data/test/template/benchmark_helper_test.rb +6 -6
  64. data/test/template/compiled_templates_test.rb +2 -1
  65. data/test/template/date_helper_i18n_test.rb +10 -9
  66. data/test/template/date_helper_test.rb +29 -13
  67. data/test/template/form_helper_test.rb +90 -10
  68. data/test/template/number_helper_test.rb +4 -0
  69. data/test/template/raw_output_helper_test.rb +21 -0
  70. data/test/template/sanitize_helper_test.rb +10 -1
  71. data/test/template/tag_helper_test.rb +1 -0
  72. data/test/view/safe_buffer_test.rb +36 -0
  73. data/test/view/test_case_test.rb +173 -5
  74. metadata +13 -4
@@ -118,6 +118,10 @@ class NumberHelperTest < ActionView::TestCase
118
118
  assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2)
119
119
  assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4)
120
120
  assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4)
121
+ assert_equal '1 TB', number_to_human_size(1234567890123, :precision => 0)
122
+ assert_equal '500 MB', number_to_human_size(524288000, :precision=>0)
123
+ assert_equal '40 KB', number_to_human_size(41010, :precision => 0)
124
+ assert_equal '40 KB', number_to_human_size(41100, :precision => 0)
121
125
  end
122
126
 
123
127
  def test_number_to_human_size_with_custom_delimiter_and_separator
@@ -0,0 +1,21 @@
1
+ require 'abstract_unit'
2
+ require 'testing_sandbox'
3
+
4
+ class RawOutputHelperTest < ActionView::TestCase
5
+ tests ActionView::Helpers::RawOutputHelper
6
+ include TestingSandbox
7
+
8
+ def setup
9
+ @string = "hello"
10
+ end
11
+
12
+ test "raw returns the safe string" do
13
+ result = raw(@string)
14
+ assert_equal @string, result
15
+ assert result.html_safe?
16
+ end
17
+
18
+ test "raw handles nil values correctly" do
19
+ assert_equal "", raw(nil)
20
+ end
21
+ end
@@ -39,7 +39,16 @@ class SanitizeHelperTest < ActionView::TestCase
39
39
  %{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags(
40
40
  %{<title>This is <b>a <a href="" target="_blank">test</a></b>.</title>\n\n<!-- it has a comment -->\n\n<p>It no <b>longer <strong>contains <em>any <strike>HTML</strike></em>.</strong></b></p>\n}))
41
41
  assert_equal "This has a here.", strip_tags("This has a <!-- comment --> here.")
42
- [nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) }
42
+ [nil, '', ' '].each do |blank|
43
+ stripped = strip_tags(blank)
44
+ assert_equal blank, stripped
45
+ assert stripped.html_safe? unless blank.nil?
46
+ end
47
+ assert strip_tags("<script>").html_safe?
48
+ end
49
+
50
+ def test_sanitize_is_marked_safe
51
+ assert sanitize("<html><script></script></html>").html_safe?
43
52
  end
44
53
 
45
54
  def assert_sanitized(text, expected = nil)
@@ -34,6 +34,7 @@ class TagHelperTest < ActionView::TestCase
34
34
 
35
35
  def test_content_tag
36
36
  assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
37
+ assert content_tag("a", "Create", "href" => "create").html_safe?
37
38
  assert_equal content_tag("a", "Create", "href" => "create"),
38
39
  content_tag("a", "Create", :href => "create")
39
40
  end
@@ -0,0 +1,36 @@
1
+ require 'abstract_unit'
2
+
3
+ class SafeBufferTest < ActionView::TestCase
4
+ def setup
5
+ @buffer = ActionView::SafeBuffer.new
6
+ end
7
+
8
+ test "Should look like a string" do
9
+ assert @buffer.is_a?(String)
10
+ assert_equal "", @buffer
11
+ end
12
+
13
+ test "Should escape a raw string which is passed to them" do
14
+ @buffer << "<script>"
15
+ assert_equal "&lt;script&gt;", @buffer
16
+ end
17
+
18
+ test "Should NOT escape a safe value passed to it" do
19
+ @buffer << "<script>".html_safe!
20
+ assert_equal "<script>", @buffer
21
+ end
22
+
23
+ test "Should not mess with an innocuous string" do
24
+ @buffer << "Hello"
25
+ assert_equal "Hello", @buffer
26
+ end
27
+
28
+ test "Should be considered safe" do
29
+ assert @buffer.html_safe?
30
+ end
31
+
32
+ test "Should return a safe buffer when calling to_s" do
33
+ new_buffer = @buffer.to_s
34
+ assert_equal ActionView::SafeBuffer, new_buffer.class
35
+ end
36
+ end
@@ -1,8 +1,176 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class TestCaseTest < ActionView::TestCase
4
- def test_should_have_current_url
5
- controller = TestController.new
6
- assert_nothing_raised(NoMethodError){ controller.url_for({:controller => "foo", :action => "index"}) }
3
+ module ActionView
4
+ class TestCase
5
+ module ATestHelper
6
+ end
7
+
8
+ module AnotherTestHelper
9
+ def from_another_helper
10
+ 'Howdy!'
11
+ end
12
+ end
13
+
14
+ module ASharedTestHelper
15
+ def from_shared_helper
16
+ 'Holla!'
17
+ end
18
+ end
19
+ helper ASharedTestHelper
20
+
21
+ module SharedTests
22
+ def self.included(test_case)
23
+ test_case.class_eval do
24
+ test "helpers defined on ActionView::TestCase are available" do
25
+ assert test_case.ancestors.include?(ASharedTestHelper)
26
+ assert_equal 'Holla!', from_shared_helper
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ class GeneralViewTest < ActionView::TestCase
33
+ include SharedTests
34
+ test_case = self
35
+
36
+ test "works without testing a helper module" do
37
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
38
+ end
39
+
40
+ test "can render a layout with block" do
41
+ assert_equal "Before (ChrisCruft)\n!\nAfter",
42
+ render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
43
+ end
44
+
45
+ helper AnotherTestHelper
46
+ test "additional helper classes can be specified as in a controller" do
47
+ assert test_case.ancestors.include?(AnotherTestHelper)
48
+ assert_equal 'Howdy!', from_another_helper
49
+ end
50
+ end
51
+
52
+ class ClassMethodsTest < ActionView::TestCase
53
+ include SharedTests
54
+ test_case = self
55
+
56
+ tests ATestHelper
57
+ test "tests the specified helper module" do
58
+ assert_equal ATestHelper, test_case.helper_class
59
+ assert test_case.ancestors.include?(ATestHelper)
60
+ end
61
+
62
+ helper AnotherTestHelper
63
+ test "additional helper classes can be specified as in a controller" do
64
+ assert test_case.ancestors.include?(AnotherTestHelper)
65
+ assert_equal 'Howdy!', from_another_helper
66
+
67
+ test_case.helper_class.module_eval do
68
+ def render_from_helper
69
+ from_another_helper
70
+ end
71
+ end
72
+ assert_equal 'Howdy!', render(:partial => 'test/from_helper')
73
+ end
74
+ end
75
+
76
+ class ATestHelperTest < ActionView::TestCase
77
+ include SharedTests
78
+ test_case = self
79
+
80
+ test "inflects the name of the helper module to test from the test case class" do
81
+ assert_equal ATestHelper, test_case.helper_class
82
+ assert test_case.ancestors.include?(ATestHelper)
83
+ end
84
+
85
+ test "a configured test controller is available" do
86
+ assert_kind_of ActionController::Base, controller
87
+ assert_equal '', controller.controller_path
88
+ end
89
+
90
+ test "helper class that is being tested is always included in view instance" do
91
+ self.class.helper_class.module_eval do
92
+ def render_from_helper
93
+ render :partial => 'customer', :collection => @customers
94
+ end
95
+ end
96
+
97
+ TestController.stubs(:controller_path).returns('test')
98
+
99
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
100
+ assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
101
+ end
102
+
103
+ test "no additional helpers should shared across test cases" do
104
+ assert !test_case.ancestors.include?(AnotherTestHelper)
105
+ assert_raise(NoMethodError) { send :from_another_helper }
106
+ end
107
+
108
+ test "is able to use routes" do
109
+ controller.request.assign_parameters('foo', 'index')
110
+ assert_equal '/foo', url_for
111
+ assert_equal '/bar', url_for(:controller => 'bar')
112
+ end
113
+
114
+ test "is able to use named routes" do
115
+ with_routing do |set|
116
+ set.draw { |map| map.resources :contents }
117
+ assert_equal 'http://test.host/contents/new', new_content_url
118
+ assert_equal 'http://test.host/contents/1', content_url(:id => 1)
119
+ end
120
+ end
121
+
122
+ test "named routes can be used from helper included in view" do
123
+ with_routing do |set|
124
+ set.draw { |map| map.resources :contents }
125
+ master_helper_module.module_eval do
126
+ def render_from_helper
127
+ new_content_url
128
+ end
129
+ end
130
+
131
+ assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper')
132
+ end
133
+ end
134
+
135
+ test "is able to render partials with local variables" do
136
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
137
+ assert_equal 'Eloy', render(:partial => 'developers/developer',
138
+ :locals => { :developer => stub(:name => 'Eloy') })
139
+ end
140
+
141
+ test "is able to render partials from templates and also use instance variables" do
142
+ TestController.stubs(:controller_path).returns('test')
143
+
144
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
145
+ assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
146
+ end
147
+
148
+ test "is able to make methods available to the view" do
149
+ master_helper_module.module_eval do
150
+ def render_from_helper; from_test_case end
151
+ end
152
+ assert_equal 'Word!', render(:partial => 'test/from_helper')
153
+ end
154
+
155
+ def from_test_case; 'Word!'; end
156
+ helper_method :from_test_case
157
+ end
158
+
159
+ class AssertionsTest < ActionView::TestCase
160
+ def render_from_helper
161
+ form_tag('/foo') do
162
+ concat render(:text => '<ul><li>foo</li></ul>')
163
+ end
164
+ end
165
+ helper_method :render_from_helper
166
+
167
+ test "uses the output_buffer for assert_select" do
168
+ render(:partial => 'test/from_helper')
169
+
170
+ assert_select 'form' do
171
+ assert_select 'li', :text => 'foo'
172
+ end
173
+ end
174
+ end
7
175
  end
8
- end
176
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ autorequire: action_controller
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-04 00:00:00 +12:00
12
+ date: 2009-11-27 00:00:00 +13:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.3.4
23
+ version: 2.3.5
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
@@ -84,6 +84,7 @@ files:
84
84
  - lib/action_controller/params_parser.rb
85
85
  - lib/action_controller/performance_test.rb
86
86
  - lib/action_controller/polymorphic_routes.rb
87
+ - lib/action_controller/rack_lint_patch.rb
87
88
  - lib/action_controller/record_identifier.rb
88
89
  - lib/action_controller/reloader.rb
89
90
  - lib/action_controller/request.rb
@@ -105,6 +106,7 @@ files:
105
106
  - lib/action_controller/session_management.rb
106
107
  - lib/action_controller/status_codes.rb
107
108
  - lib/action_controller/streaming.rb
109
+ - lib/action_controller/string_coercion.rb
108
110
  - lib/action_controller/templates/rescues/_request_and_response.erb
109
111
  - lib/action_controller/templates/rescues/_trace.erb
110
112
  - lib/action_controller/templates/rescues/diagnostics.erb
@@ -145,6 +147,7 @@ files:
145
147
  - lib/action_view/helpers/javascript_helper.rb
146
148
  - lib/action_view/helpers/number_helper.rb
147
149
  - lib/action_view/helpers/prototype_helper.rb
150
+ - lib/action_view/helpers/raw_output_helper.rb
148
151
  - lib/action_view/helpers/record_identification_helper.rb
149
152
  - lib/action_view/helpers/record_tag_helper.rb
150
153
  - lib/action_view/helpers/sanitize_helper.rb
@@ -161,6 +164,7 @@ files:
161
164
  - lib/action_view/reloadable_template.rb
162
165
  - lib/action_view/renderable.rb
163
166
  - lib/action_view/renderable_partial.rb
167
+ - lib/action_view/safe_buffer.rb
164
168
  - lib/action_view/template.rb
165
169
  - lib/action_view/template_error.rb
166
170
  - lib/action_view/template_handler.rb
@@ -190,6 +194,7 @@ files:
190
194
  - test/controller/cookie_test.rb
191
195
  - test/controller/deprecation/deprecated_base_methods_test.rb
192
196
  - test/controller/dispatcher_test.rb
197
+ - test/controller/dom_assertions_test.rb
193
198
  - test/controller/failsafe_test.rb
194
199
  - test/controller/fake_controllers.rb
195
200
  - test/controller/fake_models.rb
@@ -274,6 +279,7 @@ files:
274
279
  - test/fixtures/helpers/abc_helper.rb
275
280
  - test/fixtures/helpers/fun/games_helper.rb
276
281
  - test/fixtures/helpers/fun/pdf_helper.rb
282
+ - test/fixtures/layout_tests/abs_path_layout.rhtml
277
283
  - test/fixtures/layout_tests/alt/hello.rhtml
278
284
  - test/fixtures/layout_tests/alt/layouts/alt.rhtml
279
285
  - test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml
@@ -362,6 +368,7 @@ files:
362
368
  - test/fixtures/test/_customer_greeting.erb
363
369
  - test/fixtures/test/_customer_with_var.erb
364
370
  - test/fixtures/test/_form.erb
371
+ - test/fixtures/test/_from_helper.erb
365
372
  - test/fixtures/test/_hash_greeting.erb
366
373
  - test/fixtures/test/_hash_object.erb
367
374
  - test/fixtures/test/_hello.builder
@@ -448,6 +455,7 @@ files:
448
455
  - test/template/number_helper_i18n_test.rb
449
456
  - test/template/number_helper_test.rb
450
457
  - test/template/prototype_helper_test.rb
458
+ - test/template/raw_output_helper_test.rb
451
459
  - test/template/record_tag_helper_test.rb
452
460
  - test/template/render_test.rb
453
461
  - test/template/sanitize_helper_test.rb
@@ -459,6 +467,7 @@ files:
459
467
  - test/template/translation_helper_test.rb
460
468
  - test/template/url_helper_test.rb
461
469
  - test/testing_sandbox.rb
470
+ - test/view/safe_buffer_test.rb
462
471
  - test/view/test_case_test.rb
463
472
  has_rdoc: true
464
473
  homepage: http://www.rubyonrails.org
@@ -484,7 +493,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
493
  requirements:
485
494
  - none
486
495
  rubyforge_project: actionpack
487
- rubygems_version: 1.3.2
496
+ rubygems_version: 1.3.5
488
497
  signing_key:
489
498
  specification_version: 3
490
499
  summary: Web-flow and rendering framework putting the VC in MVC.