actionpack 1.8.1 → 1.9.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 (101) hide show
  1. data/CHANGELOG +309 -16
  2. data/README +1 -1
  3. data/lib/action_controller.rb +5 -0
  4. data/lib/action_controller/assertions.rb +57 -12
  5. data/lib/action_controller/auto_complete.rb +47 -0
  6. data/lib/action_controller/base.rb +288 -258
  7. data/lib/action_controller/benchmarking.rb +8 -3
  8. data/lib/action_controller/caching.rb +88 -42
  9. data/lib/action_controller/cgi_ext/cgi_ext.rb +1 -1
  10. data/lib/action_controller/cgi_ext/cgi_methods.rb +41 -11
  11. data/lib/action_controller/cgi_ext/multipart_progress.rb +169 -0
  12. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +30 -12
  13. data/lib/action_controller/cgi_process.rb +39 -11
  14. data/lib/action_controller/code_generation.rb +235 -0
  15. data/lib/action_controller/cookies.rb +14 -8
  16. data/lib/action_controller/deprecated_renders_and_redirects.rb +76 -0
  17. data/lib/action_controller/filters.rb +8 -7
  18. data/lib/action_controller/helpers.rb +41 -6
  19. data/lib/action_controller/layout.rb +45 -16
  20. data/lib/action_controller/request.rb +86 -23
  21. data/lib/action_controller/rescue.rb +1 -0
  22. data/lib/action_controller/response.rb +1 -1
  23. data/lib/action_controller/routing.rb +536 -272
  24. data/lib/action_controller/scaffolding.rb +30 -25
  25. data/lib/action_controller/session/active_record_store.rb +251 -50
  26. data/lib/action_controller/streaming.rb +133 -0
  27. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -7
  28. data/lib/action_controller/templates/scaffolds/edit.rhtml +2 -2
  29. data/lib/action_controller/templates/scaffolds/layout.rhtml +22 -18
  30. data/lib/action_controller/templates/scaffolds/list.rhtml +3 -3
  31. data/lib/action_controller/templates/scaffolds/new.rhtml +2 -2
  32. data/lib/action_controller/templates/scaffolds/show.rhtml +1 -1
  33. data/lib/action_controller/test_process.rb +68 -47
  34. data/lib/action_controller/upload_progress.rb +421 -0
  35. data/lib/action_controller/url_rewriter.rb +8 -11
  36. data/lib/action_controller/vendor/html-scanner/html/document.rb +6 -5
  37. data/lib/action_controller/vendor/html-scanner/html/node.rb +70 -14
  38. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +17 -10
  39. data/lib/action_controller/vendor/html-scanner/html/version.rb +3 -3
  40. data/lib/action_controller/vendor/xml_simple.rb +1019 -0
  41. data/lib/action_controller/verification.rb +36 -30
  42. data/lib/action_view/base.rb +21 -14
  43. data/lib/action_view/helpers/active_record_helper.rb +15 -13
  44. data/lib/action_view/helpers/asset_tag_helper.rb +26 -9
  45. data/lib/action_view/helpers/benchmark_helper.rb +24 -0
  46. data/lib/action_view/helpers/capture_helper.rb +7 -5
  47. data/lib/action_view/helpers/date_helper.rb +63 -46
  48. data/lib/action_view/helpers/form_helper.rb +7 -1
  49. data/lib/action_view/helpers/form_options_helper.rb +19 -11
  50. data/lib/action_view/helpers/form_tag_helper.rb +5 -1
  51. data/lib/action_view/helpers/javascript_helper.rb +403 -35
  52. data/lib/action_view/helpers/javascripts/controls.js +261 -0
  53. data/lib/action_view/helpers/javascripts/dragdrop.js +476 -0
  54. data/lib/action_view/helpers/javascripts/effects.js +570 -0
  55. data/lib/action_view/helpers/javascripts/prototype.js +633 -371
  56. data/lib/action_view/helpers/number_helper.rb +11 -13
  57. data/lib/action_view/helpers/tag_helper.rb +1 -2
  58. data/lib/action_view/helpers/text_helper.rb +69 -6
  59. data/lib/action_view/helpers/upload_progress_helper.rb +433 -0
  60. data/lib/action_view/helpers/url_helper.rb +98 -3
  61. data/lib/action_view/partials.rb +14 -8
  62. data/lib/action_view/vendor/builder/xmlmarkup.rb +11 -0
  63. data/rakefile +13 -5
  64. data/test/abstract_unit.rb +1 -1
  65. data/test/controller/action_pack_assertions_test.rb +52 -9
  66. data/test/controller/active_record_assertions_test.rb +119 -120
  67. data/test/controller/active_record_store_test.rb +111 -0
  68. data/test/controller/addresses_render_test.rb +45 -0
  69. data/test/controller/caching_filestore.rb +92 -0
  70. data/test/controller/capture_test.rb +39 -0
  71. data/test/controller/cgi_test.rb +40 -3
  72. data/test/controller/helper_test.rb +65 -13
  73. data/test/controller/multipart_progress_testx.rb +365 -0
  74. data/test/controller/new_render_test.rb +263 -0
  75. data/test/controller/redirect_test.rb +64 -0
  76. data/test/controller/render_test.rb +20 -21
  77. data/test/controller/request_test.rb +83 -3
  78. data/test/controller/routing_test.rb +702 -0
  79. data/test/controller/send_file_test.rb +2 -0
  80. data/test/controller/test_test.rb +44 -8
  81. data/test/controller/upload_progress_testx.rb +89 -0
  82. data/test/controller/verification_test.rb +94 -29
  83. data/test/fixtures/addresses/list.rhtml +1 -0
  84. data/test/fixtures/test/capturing.rhtml +4 -0
  85. data/test/fixtures/test/list.rhtml +1 -1
  86. data/test/fixtures/test/update_element_with_capture.rhtml +9 -0
  87. data/test/template/active_record_helper_test.rb +30 -15
  88. data/test/template/asset_tag_helper_test.rb +12 -5
  89. data/test/template/benchmark_helper_test.rb +72 -0
  90. data/test/template/date_helper_test.rb +69 -0
  91. data/test/template/form_helper_test.rb +18 -10
  92. data/test/template/form_options_helper_test.rb +40 -5
  93. data/test/template/javascript_helper.rb +149 -2
  94. data/test/template/number_helper_test.rb +2 -0
  95. data/test/template/tag_helper_test.rb +4 -0
  96. data/test/template/text_helper_test.rb +36 -0
  97. data/test/template/upload_progress_helper_testx.rb +272 -0
  98. data/test/template/url_helper_test.rb +30 -0
  99. metadata +30 -6
  100. data/test/controller/layout_test.rb +0 -49
  101. data/test/controller/routing_tests.rb +0 -543
@@ -10,6 +10,7 @@ end
10
10
 
11
11
  class SendFileController < ActionController::Base
12
12
  include TestFileUtils
13
+ layout "layouts/standard" # to make sure layouts don't interfere
13
14
 
14
15
  attr_writer :options
15
16
  def options() @options ||= {} end
@@ -20,6 +21,7 @@ class SendFileController < ActionController::Base
20
21
  def rescue_action(e) raise end
21
22
  end
22
23
 
24
+ SendFileController.template_root = File.dirname(__FILE__) + "/../fixtures/"
23
25
 
24
26
  class SendFileTest < Test::Unit::TestCase
25
27
  include TestFileUtils
@@ -5,13 +5,17 @@ class TestTest < Test::Unit::TestCase
5
5
  def set_flash
6
6
  flash["test"] = ">#{flash["test"]}<"
7
7
  end
8
-
8
+
9
+ def test_params
10
+ render :text => params.inspect
11
+ end
12
+
9
13
  def test_uri
10
- render_text @request.request_uri
14
+ render :text => request.request_uri
11
15
  end
12
16
 
13
17
  def test_html_output
14
- render_text <<HTML
18
+ render :text => <<HTML
15
19
  <html>
16
20
  <body>
17
21
  <div id="foo">
@@ -29,6 +33,10 @@ class TestTest < Test::Unit::TestCase
29
33
  </html>
30
34
  HTML
31
35
  end
36
+
37
+ def test_only_one_param
38
+ render :text => (@params[:left] && @params[:right]) ? "EEP, Both here!" : "OK"
39
+ end
32
40
  end
33
41
 
34
42
  def setup
@@ -45,8 +53,8 @@ HTML
45
53
  def test_process_without_flash
46
54
  process :set_flash
47
55
  assert_flash_equal "><", "test"
48
- end
49
-
56
+ end
57
+
50
58
  def test_process_with_flash
51
59
  process :set_flash, nil, nil, { "test" => "value" }
52
60
  assert_flash_equal ">value<", "test"
@@ -54,18 +62,25 @@ HTML
54
62
 
55
63
  def test_process_with_request_uri_with_no_params
56
64
  process :test_uri
57
- assert_equal @response.body, "/test_test/test/test_uri"
65
+ assert_equal "/test_test/test/test_uri", @response.body
58
66
  end
59
67
 
60
68
  def test_process_with_request_uri_with_params
61
69
  process :test_uri, :id => 7
62
- assert_equal @response.body, "/test_test/test/test_uri/7"
70
+ assert_equal "/test_test/test/test_uri/7", @response.body
63
71
  end
64
72
 
65
73
  def test_process_with_request_uri_with_params_with_explicit_uri
66
74
  @request.set_REQUEST_URI "/explicit/uri"
67
75
  process :test_uri, :id => 7
68
- assert_equal @response.body, "/explicit/uri"
76
+ assert_equal "/explicit/uri", @response.body
77
+ end
78
+
79
+ def test_multiple_calls
80
+ process :test_only_one_param, :left => true
81
+ assert_equal "OK", @response.body
82
+ process :test_only_one_param, :right => true
83
+ assert_equal "OK", @response.body
69
84
  end
70
85
 
71
86
  def test_assert_tag
@@ -84,4 +99,25 @@ HTML
84
99
  :children => { :greater_than => 2,
85
100
  :only => { :tag => "li" } } }
86
101
  end
102
+
103
+ def test_assert_routing
104
+ assert_generates 'controller/action/5', :controller => 'controller', :action => 'action', :id => '5'
105
+ end
106
+
107
+ def test_params_passing
108
+ get :test_params, :page => {:name => "Page name", :month => '4', :year => '2004', :day => '6'}
109
+ parsed_params = eval(@response.body)
110
+ assert_equal(
111
+ {'controller' => 'test_test/test', 'action' => 'test_params',
112
+ 'page' => {'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6'}},
113
+ parsed_params
114
+ )
115
+ end
116
+
117
+ def test_path_params_are_strings
118
+ get :test_params, :id => 20, :foo => Object.new
119
+ @request.path_parameters.each do |key, value|
120
+ assert_kind_of String, value
121
+ end
122
+ end
87
123
  end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+ require 'test/unit'
3
+ require 'cgi'
4
+ require 'stringio'
5
+
6
+ class UploadProgressTest < Test::Unit::TestCase
7
+ def test_remaining
8
+ progress = new_progress(20000)
9
+ assert_equal(0, progress.received_bytes)
10
+ assert_equal(20000, progress.remaining_bytes)
11
+ progress.update!(10000, 1.0)
12
+ assert_equal(10000, progress.remaining_bytes)
13
+ assert_equal(1.0, progress.remaining_seconds)
14
+ assert_equal(50, progress.completed_percent)
15
+ assert_equal(true, progress.started?)
16
+ assert_equal(false, progress.finished?)
17
+ assert_equal(false, progress.stalled?)
18
+ progress.update!(10000, 2.0)
19
+ assert_equal(true, progress.finished?)
20
+ assert_equal(0.0, progress.remaining_seconds)
21
+ end
22
+
23
+ def test_stalled
24
+ progress = new_progress(10000)
25
+ assert_equal(false, progress.stalled?)
26
+ progress.update!(100, 1.0)
27
+ assert_equal(false, progress.stalled?)
28
+ progress.update!(100, 20.0)
29
+ assert_equal(true, progress.stalled?)
30
+ assert_in_delta(0.0, progress.bitrate, 0.001)
31
+ progress.update!(100, 21.0)
32
+ assert_equal(false, progress.stalled?)
33
+ end
34
+
35
+ def test_elapsed
36
+ progress = new_progress(10000)
37
+ (1..5).each do |t|
38
+ progress.update!(1000, Float(t))
39
+ end
40
+ assert_in_delta(5.0, progress.elapsed_seconds, 0.001)
41
+ assert_equal(10000, progress.total_bytes)
42
+ assert_equal(5000, progress.received_bytes)
43
+ assert_equal(5000, progress.remaining_bytes)
44
+ end
45
+
46
+ def test_overflow
47
+ progress = new_progress(10000)
48
+ progress.update!(20000, 1.0)
49
+ assert_equal(10000, progress.received_bytes)
50
+ end
51
+
52
+ def test_zero
53
+ progress = new_progress(0)
54
+ assert_equal(0, progress.total_bytes)
55
+ assert_equal(0, progress.remaining_bytes)
56
+ assert_equal(false, progress.started?)
57
+ assert_equal(true, progress.finished?)
58
+ assert_equal(0, progress.bitrate)
59
+ assert_equal(0, progress.completed_percent)
60
+ assert_equal(0, progress.remaining_seconds)
61
+ end
62
+
63
+ def test_finished
64
+ progress = new_progress(10000)
65
+ (1..9).each do |t|
66
+ progress.update!(1000, Float(t))
67
+ assert_equal(false, progress.finished?)
68
+ assert_equal(1000.0, progress.bitrate)
69
+ assert_equal(false, progress.stalled?)
70
+ end
71
+ assert_equal(false, progress.finished?)
72
+ progress.update!(1000, 10.0)
73
+ assert_equal(true, progress.finished?)
74
+ end
75
+
76
+ def test_rapid_samples
77
+ progress = new_progress(10000)
78
+ (1..1000).each do |t|
79
+ progress.update!(10, t/100.0)
80
+ end
81
+ assert_in_delta(1000.0, progress.bitrate, 0.001)
82
+ assert_equal(true, progress.finished?)
83
+ end
84
+
85
+ private
86
+ def new_progress(total)
87
+ ActionController::UploadProgress::Progress.new(total)
88
+ end
89
+ end
@@ -20,40 +20,73 @@ class VerificationTest < Test::Unit::TestCase
20
20
 
21
21
  verify :only => :guarded_by_method, :method => :post,
22
22
  :redirect_to => { :action => "unguarded" }
23
+
24
+ verify :only => :guarded_by_xhr, :xhr => true,
25
+ :redirect_to => { :action => "unguarded" }
26
+
27
+ verify :only => :guarded_by_not_xhr, :xhr => false,
28
+ :redirect_to => { :action => "unguarded" }
29
+
30
+ before_filter :unconditional_redirect, :only => :two_redirects
31
+ verify :only => :two_redirects, :method => :post,
32
+ :redirect_to => { :action => "unguarded" }
33
+
34
+ verify :only => :must_be_post, :method => :post, :render => { :status => 500, :text => "Must be post"}
23
35
 
24
36
  def guarded_one
25
- render_text "#{@params["one"]}"
37
+ render :text => "#{@params["one"]}"
26
38
  end
27
39
 
28
40
  def guarded_with_flash
29
- render_text "#{@params["one"]}"
41
+ render :text => "#{@params["one"]}"
30
42
  end
31
43
 
32
44
  def guarded_two
33
- render_text "#{@params["one"]}:#{@params["two"]}"
45
+ render :text => "#{@params["one"]}:#{@params["two"]}"
34
46
  end
35
47
 
36
48
  def guarded_in_session
37
- render_text "#{@session["one"]}"
49
+ render :text => "#{@session["one"]}"
38
50
  end
39
51
 
40
52
  def multi_one
41
- render_text "#{@session["one"]}:#{@session["two"]}"
53
+ render :text => "#{@session["one"]}:#{@session["two"]}"
42
54
  end
43
55
 
44
56
  def multi_two
45
- render_text "#{@session["two"]}:#{@session["one"]}"
57
+ render :text => "#{@session["two"]}:#{@session["one"]}"
46
58
  end
47
59
 
48
60
  def guarded_by_method
49
- render_text "#{@request.method}"
61
+ render :text => "#{@request.method}"
62
+ end
63
+
64
+ def guarded_by_xhr
65
+ render :text => "#{@request.xhr?}"
66
+ end
67
+
68
+ def guarded_by_not_xhr
69
+ render :text => "#{@request.xhr?}"
50
70
  end
51
71
 
52
72
  def unguarded
53
- render_text "#{@params["one"]}"
73
+ render :text => "#{@params["one"]}"
74
+ end
75
+
76
+ def two_redirects
77
+ render :nothing => true
78
+ end
79
+
80
+ def must_be_post
81
+ render :text => "Was a post!"
54
82
  end
83
+
84
+ protected
85
+ def rescue_action(e) raise end
55
86
 
56
- def rescue_action(e) raise end
87
+ def unconditional_redirect
88
+ redirect_to :action => "unguarded"
89
+ end
57
90
  end
58
91
 
59
92
  def setup
@@ -63,96 +96,128 @@ class VerificationTest < Test::Unit::TestCase
63
96
  end
64
97
 
65
98
  def test_guarded_one_with_prereqs
66
- process "guarded_one", "one" => "here"
99
+ get :guarded_one, :one => "here"
67
100
  assert_equal "here", @response.body
68
101
  end
69
102
 
70
103
  def test_guarded_one_without_prereqs
71
- process "guarded_one"
104
+ get :guarded_one
72
105
  assert_redirected_to :action => "unguarded"
73
106
  end
74
107
 
75
108
  def test_guarded_with_flash_with_prereqs
76
- process "guarded_with_flash", "one" => "here"
109
+ get :guarded_with_flash, :one => "here"
77
110
  assert_equal "here", @response.body
78
111
  assert_flash_empty
79
112
  end
80
113
 
81
114
  def test_guarded_with_flash_without_prereqs
82
- process "guarded_with_flash"
115
+ get :guarded_with_flash
83
116
  assert_redirected_to :action => "unguarded"
84
117
  assert_flash_equal "prereqs failed", "notice"
85
118
  end
86
119
 
87
120
  def test_guarded_two_with_prereqs
88
- process "guarded_two", "one" => "here", "two" => "there"
121
+ get :guarded_two, :one => "here", :two => "there"
89
122
  assert_equal "here:there", @response.body
90
123
  end
91
124
 
92
125
  def test_guarded_two_without_prereqs_one
93
- process "guarded_two", "two" => "there"
126
+ get :guarded_two, :two => "there"
94
127
  assert_redirected_to :action => "unguarded"
95
128
  end
96
129
 
97
130
  def test_guarded_two_without_prereqs_two
98
- process "guarded_two", "one" => "here"
131
+ get :guarded_two, :one => "here"
99
132
  assert_redirected_to :action => "unguarded"
100
133
  end
101
134
 
102
135
  def test_guarded_two_without_prereqs_both
103
- process "guarded_two"
136
+ get :guarded_two
104
137
  assert_redirected_to :action => "unguarded"
105
138
  end
106
139
 
107
140
  def test_unguarded_with_params
108
- process "unguarded", "one" => "here"
141
+ get :unguarded, :one => "here"
109
142
  assert_equal "here", @response.body
110
143
  end
111
144
 
112
145
  def test_unguarded_without_params
113
- process "unguarded"
146
+ get :unguarded
114
147
  assert_equal "", @response.body
115
148
  end
116
149
 
117
150
  def test_guarded_in_session_with_prereqs
118
- process "guarded_in_session", {}, "one" => "here"
151
+ get :guarded_in_session, {}, "one" => "here"
119
152
  assert_equal "here", @response.body
120
153
  end
121
154
 
122
155
  def test_guarded_in_session_without_prereqs
123
- process "guarded_in_session"
156
+ get :guarded_in_session
124
157
  assert_redirected_to :action => "unguarded"
125
158
  end
126
159
 
127
160
  def test_multi_one_with_prereqs
128
- process "multi_one", {}, "one" => "here", "two" => "there"
161
+ get :multi_one, {}, "one" => "here", "two" => "there"
129
162
  assert_equal "here:there", @response.body
130
163
  end
131
164
 
132
165
  def test_multi_one_without_prereqs
133
- process "multi_one"
166
+ get :multi_one
134
167
  assert_redirected_to :action => "unguarded"
135
168
  end
136
169
 
137
170
  def test_multi_two_with_prereqs
138
- process "multi_two", {}, "one" => "here", "two" => "there"
171
+ get :multi_two, {}, "one" => "here", "two" => "there"
139
172
  assert_equal "there:here", @response.body
140
173
  end
141
174
 
142
175
  def test_multi_two_without_prereqs
143
- process "multi_two"
176
+ get :multi_two
144
177
  assert_redirected_to :action => "unguarded"
145
178
  end
146
179
 
147
180
  def test_guarded_by_method_with_prereqs
148
- @request.env["REQUEST_METHOD"] = "POST"
149
- process "guarded_by_method"
181
+ post :guarded_by_method
150
182
  assert_equal "post", @response.body
151
183
  end
152
184
 
153
185
  def test_guarded_by_method_without_prereqs
154
- @request.env["REQUEST_METHOD"] = "GET"
155
- process "guarded_by_method"
186
+ get :guarded_by_method
156
187
  assert_redirected_to :action => "unguarded"
157
188
  end
189
+
190
+ def test_guarded_by_xhr_with_prereqs
191
+ xhr :post, :guarded_by_xhr
192
+ assert_equal "true", @response.body
193
+ end
194
+
195
+ def test_guarded_by_xhr_without_prereqs
196
+ get :guarded_by_xhr
197
+ assert_redirected_to :action => "unguarded"
198
+ end
199
+
200
+ def test_guarded_by_not_xhr_with_prereqs
201
+ get :guarded_by_not_xhr
202
+ assert_equal "false", @response.body
203
+ end
204
+
205
+ def test_guarded_by_not_xhr_without_prereqs
206
+ xhr :post, :guarded_by_not_xhr
207
+ assert_redirected_to :action => "unguarded"
208
+ end
209
+
210
+ def test_guarded_post_and_calls_render
211
+ post :must_be_post
212
+ assert_equal "Was a post!", @response.body
213
+
214
+ get :must_be_post
215
+ assert_response 500
216
+ assert_equal "Must be post", @response.body
217
+ end
218
+
219
+
220
+ def test_second_redirect
221
+ assert_nothing_raised { get :two_redirects }
222
+ end
158
223
  end
@@ -0,0 +1 @@
1
+ We only need to get this far!
@@ -0,0 +1,4 @@
1
+ <% days = capture do %>
2
+ Dreamy days
3
+ <% end %>
4
+ <%= days %>
@@ -1 +1 @@
1
- <%= render_collection_of_partials "customer", @customers %>
1
+ <%= @test_unchanged = 'goodbye' %><%= render_collection_of_partials "customer", @customers %><%= @test_unchanged %>
@@ -0,0 +1,9 @@
1
+ <% replacement_function = update_element_function("products", :action => :update) do %>
2
+ <p>Product 1</p>
3
+ <p>Product 2</p>
4
+ <% end %>
5
+ <%= javascript_tag(replacement_function) %>
6
+
7
+ <% update_element_function("status", :action => :update, :binding => binding) do %>
8
+ <b>You bought something!</b>
9
+ <% end %>