actionpack 1.4.0 → 1.5.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 (84) hide show
  1. data/CHANGELOG +66 -0
  2. data/README +94 -64
  3. data/install.rb +1 -20
  4. data/lib/action_controller.rb +15 -7
  5. data/lib/action_controller/assertions/action_pack_assertions.rb +56 -3
  6. data/lib/action_controller/base.rb +137 -64
  7. data/lib/action_controller/caching.rb +11 -11
  8. data/lib/action_controller/cgi_ext/cgi_ext.rb +2 -2
  9. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +4 -4
  10. data/lib/action_controller/cgi_process.rb +9 -1
  11. data/lib/action_controller/components.rb +73 -0
  12. data/lib/action_controller/cookies.rb +1 -1
  13. data/lib/action_controller/dependencies.rb +6 -1
  14. data/lib/action_controller/filters.rb +1 -1
  15. data/lib/action_controller/flash.rb +3 -3
  16. data/lib/action_controller/helpers.rb +17 -21
  17. data/lib/action_controller/layout.rb +2 -2
  18. data/lib/action_controller/request.rb +16 -6
  19. data/lib/action_controller/rescue.rb +15 -3
  20. data/lib/action_controller/routing.rb +304 -0
  21. data/lib/action_controller/scaffolding.rb +10 -12
  22. data/lib/action_controller/session/active_record_store.rb +4 -7
  23. data/lib/action_controller/session/mem_cache_store.rb +2 -2
  24. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +9 -1
  25. data/lib/action_controller/templates/rescues/diagnostics.rhtml +1 -1
  26. data/lib/action_controller/templates/rescues/routing_error.rhtml +8 -0
  27. data/lib/action_controller/test_process.rb +29 -7
  28. data/lib/action_controller/url_rewriter.rb +28 -112
  29. data/lib/action_view.rb +1 -1
  30. data/lib/action_view/base.rb +44 -17
  31. data/lib/action_view/helpers/active_record_helper.rb +1 -1
  32. data/lib/action_view/helpers/asset_tag_helper.rb +59 -0
  33. data/lib/action_view/helpers/date_helper.rb +24 -13
  34. data/lib/action_view/helpers/form_helper.rb +6 -1
  35. data/lib/action_view/helpers/form_options_helper.rb +87 -9
  36. data/lib/action_view/helpers/form_tag_helper.rb +80 -0
  37. data/lib/action_view/helpers/tag_helper.rb +0 -23
  38. data/lib/action_view/helpers/text_helper.rb +26 -1
  39. data/lib/action_view/helpers/url_helper.rb +29 -35
  40. data/lib/action_view/partials.rb +2 -2
  41. data/lib/action_view/vendor/builder/xmlbase.rb +3 -3
  42. data/rakefile +5 -2
  43. data/test/abstract_unit.rb +3 -1
  44. data/test/controller/action_pack_assertions_test.rb +29 -1
  45. data/test/controller/active_record_assertions_test.rb +109 -101
  46. data/test/controller/base_tests.rb +72 -0
  47. data/test/controller/components_test.rb +74 -0
  48. data/test/controller/cookie_test.rb +0 -9
  49. data/test/controller/custom_handler_test.rb +33 -0
  50. data/test/controller/filters_test.rb +36 -0
  51. data/test/controller/helper_test.rb +27 -10
  52. data/test/controller/redirect_test.rb +23 -31
  53. data/test/controller/render_test.rb +81 -66
  54. data/test/controller/request_test.rb +22 -0
  55. data/test/controller/routing_tests.rb +490 -0
  56. data/test/controller/{url_test.rb → url_obsolete.rb} +24 -14
  57. data/test/controller/url_obsolete.rb.rej +747 -0
  58. data/test/fixtures/fun/games/hello_world.rhtml +1 -0
  59. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  60. data/test/template/asset_tag_helper_test.rb +45 -0
  61. data/test/template/form_options_helper_test.rb +161 -1
  62. data/test/template/form_tag_helper_test.rb +22 -0
  63. data/test/template/text_helper_test.rb +7 -0
  64. data/test/template/url_helper_test.rb +5 -2
  65. data/test/template/url_helper_test.rb.rej +105 -0
  66. metadata +32 -27
  67. data/lib/action_controller/support/binding_of_caller.rb +0 -83
  68. data/lib/action_controller/support/breakpoint.rb +0 -518
  69. data/lib/action_controller/support/class_attribute_accessors.rb +0 -57
  70. data/lib/action_controller/support/class_inheritable_attributes.rb +0 -117
  71. data/lib/action_controller/support/clean_logger.rb +0 -10
  72. data/lib/action_controller/support/core_ext.rb +0 -1
  73. data/lib/action_controller/support/core_ext/hash.rb +0 -5
  74. data/lib/action_controller/support/core_ext/hash/keys.rb +0 -35
  75. data/lib/action_controller/support/core_ext/numeric.rb +0 -7
  76. data/lib/action_controller/support/core_ext/numeric/bytes.rb +0 -33
  77. data/lib/action_controller/support/core_ext/numeric/time.rb +0 -59
  78. data/lib/action_controller/support/core_ext/object_and_class.rb +0 -24
  79. data/lib/action_controller/support/core_ext/string.rb +0 -5
  80. data/lib/action_controller/support/core_ext/string/inflections.rb +0 -45
  81. data/lib/action_controller/support/dependencies.rb +0 -63
  82. data/lib/action_controller/support/inflector.rb +0 -84
  83. data/lib/action_controller/support/misc.rb +0 -8
  84. data/lib/action_controller/support/module_attribute_accessors.rb +0 -57
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+ require 'test/unit'
3
+
4
+ # This file currently contains a few controller UTs
5
+ # I couldn't find where the current base tests are, so I created this file.
6
+ # If there aren't any base-specific UTs, then this file should grow as they
7
+ # are written. If there are, or there is a better place for these, then I will
8
+ # move them to the correct location.
9
+ #
10
+ # Nicholas Seckar aka. Ulysses
11
+
12
+ # Provide a static version of the Controllers module instead of the auto-loading version.
13
+ # We don't want these tests to fail when dependencies are to blame.
14
+ module Controllers
15
+ module Submodule
16
+ class ContainedEmptyController < ActionController::Base
17
+ end
18
+ class ContainedNonEmptyController < ActionController::Base
19
+ def public_action
20
+ end
21
+
22
+ hide_action :hidden_action
23
+ def hidden_action
24
+ end
25
+
26
+ def another_hidden_action
27
+ end
28
+ hide_action :another_hidden_action
29
+ end
30
+ class SubclassedController < ContainedNonEmptyController
31
+ hide_action :public_action # Hiding it here should not affect the superclass.
32
+ end
33
+ end
34
+ class EmptyController < ActionController::Base
35
+ include ActionController::Caching
36
+ end
37
+ class NonEmptyController < ActionController::Base
38
+ def public_action
39
+ end
40
+
41
+ hide_action :hidden_action
42
+ def hidden_action
43
+ end
44
+ end
45
+ end
46
+
47
+ class ControllerClassTests < Test::Unit::TestCase
48
+ def test_controller_path
49
+ assert_equal 'empty', Controllers::EmptyController.controller_path
50
+ assert_equal 'submodule/contained_empty', Controllers::Submodule::ContainedEmptyController.controller_path
51
+ end
52
+ def test_controller_name
53
+ assert_equal 'empty', Controllers::EmptyController.controller_name
54
+ assert_equal 'contained_empty', Controllers::Submodule::ContainedEmptyController.controller_name
55
+ end
56
+ end
57
+
58
+ class ControllerInstanceTests < Test::Unit::TestCase
59
+ def setup
60
+ @empty = Controllers::EmptyController.new
61
+ @contained = Controllers::Submodule::ContainedEmptyController.new
62
+ @empty_controllers = [@empty, @contained, Controllers::Submodule::SubclassedController.new]
63
+
64
+ @non_empty_controllers = [Controllers::NonEmptyController.new,
65
+ Controllers::Submodule::ContainedNonEmptyController.new]
66
+
67
+ end
68
+ def test_action_methods
69
+ @empty_controllers.each {|c| assert_equal [], c.send(:action_methods), "#{c.class.controller_path} should be empty!"}
70
+ @non_empty_controllers.each {|c| assert_equal ["public_action"], c.send(:action_methods), "#{c.class.controller_path} should not be empty!"}
71
+ end
72
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class CallerController < ActionController::Base
4
+ def calling_from_controller
5
+ render_component(:controller => "callee", :action => "being_called")
6
+ end
7
+
8
+ def calling_from_controller_with_params
9
+ render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
10
+ end
11
+
12
+ def calling_from_controller_with_different_status_code
13
+ render_component(:controller => "callee", :action => "blowing_up")
14
+ end
15
+
16
+ def calling_from_template
17
+ render_template "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
18
+ end
19
+
20
+ def internal_caller
21
+ render_template "Are you there? <%= render_component(:action => 'internal_callee') %>"
22
+ end
23
+
24
+ def internal_callee
25
+ render_text "Yes, ma'am"
26
+ end
27
+
28
+ def rescue_action(e) raise end
29
+ end
30
+
31
+ class CalleeController < ActionController::Base
32
+ def being_called
33
+ render_text "#{@params["name"] || "Lady"} of the House, speaking"
34
+ end
35
+
36
+ def blowing_up
37
+ render_text "It's game over, man, just game over, man!", "500 Internal Server Error"
38
+ end
39
+
40
+ def rescue_action(e) raise end
41
+ end
42
+
43
+ class ComponentsTest < Test::Unit::TestCase
44
+ def setup
45
+ @controller = CallerController.new
46
+ @request = ActionController::TestRequest.new
47
+ @response = ActionController::TestResponse.new
48
+ end
49
+
50
+ def test_calling_from_controller
51
+ get :calling_from_controller
52
+ assert_equal "Lady of the House, speaking", @response.body
53
+ end
54
+
55
+ def test_calling_from_controller_with_params
56
+ get :calling_from_controller_with_params
57
+ assert_equal "David of the House, speaking", @response.body
58
+ end
59
+
60
+ def test_calling_from_controller_with_different_status_code
61
+ get :calling_from_controller_with_different_status_code
62
+ assert_equal 500, @response.response_code
63
+ end
64
+
65
+ def test_calling_from_template
66
+ get :calling_from_template
67
+ assert_equal "Ring, ring: Lady of the House, speaking", @response.body
68
+ end
69
+
70
+ def test_internal_calling
71
+ get :internal_caller
72
+ assert_equal "Are you there? Yes, ma'am", @response.body
73
+ end
74
+ end
@@ -28,10 +28,6 @@ class CookieTest < Test::Unit::TestCase
28
28
  render_text "hello world"
29
29
  end
30
30
 
31
- def access_frozen_cookies
32
- @cookies["wont"] = "work"
33
- end
34
-
35
31
  def rescue_action(e) raise end
36
32
  end
37
33
 
@@ -67,11 +63,6 @@ class CookieTest < Test::Unit::TestCase
67
63
  assert_equal 2, process_request.headers["cookie"].size
68
64
  end
69
65
 
70
- def test_setting_cookie_on_frozen_instance_variable
71
- @request.action = "access_frozen_cookies"
72
- assert_raises(TypeError) { process_request }
73
- end
74
-
75
66
  private
76
67
  def process_request
77
68
  TestController.process(@request, @response)
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ class CustomHandler
4
+ def initialize( view )
5
+ @view = view
6
+ end
7
+
8
+ def render( template, local_assigns )
9
+ [ template,
10
+ local_assigns,
11
+ @view ]
12
+ end
13
+ end
14
+
15
+ class CustomHandlerTest < Test::Unit::TestCase
16
+ def setup
17
+ ActionView::Base.register_template_handler "foo", CustomHandler
18
+ @view = ActionView::Base.new
19
+ end
20
+
21
+ def test_custom_render
22
+ result = @view.render_template( "foo", "hello <%= one %>", "one" => "two" )
23
+ assert_equal(
24
+ [ "hello <%= one %>", { "one" => "two" }, @view ],
25
+ result )
26
+ end
27
+
28
+ def test_unhandled_extension
29
+ # uses the ERb handler by default if the extension isn't recognized
30
+ result = @view.render_template( "bar", "hello <%= one %>", "one" => "two" )
31
+ assert_equal "hello two", result
32
+ end
33
+ end
@@ -179,6 +179,30 @@ class FilterTest < Test::Unit::TestCase
179
179
  append_around_filter AppendedAroundFilter.new
180
180
  end
181
181
 
182
+ class MixedSpecializationController < ActionController::Base
183
+ class OutOfOrder < StandardError; end
184
+
185
+ before_filter :first
186
+ before_filter :second, :only => :foo
187
+
188
+ def foo
189
+ render_text 'foo'
190
+ end
191
+
192
+ def bar
193
+ render_text 'bar'
194
+ end
195
+
196
+ protected
197
+ def first
198
+ @first = true
199
+ end
200
+
201
+ def second
202
+ raise OutOfOrder unless @first
203
+ end
204
+ end
205
+
182
206
 
183
207
  def test_added_filter_to_inheritance_graph
184
208
  assert_equal [ :fire_flash, :ensure_login ], TestController.before_filters
@@ -285,6 +309,18 @@ class FilterTest < Test::Unit::TestCase
285
309
  assert !response.template.assigns["ran_action"]
286
310
  end
287
311
 
312
+ def test_filters_with_mixed_specialization_run_in_order
313
+ assert_nothing_raised do
314
+ response = test_process(MixedSpecializationController, 'bar')
315
+ assert_equal 'bar', response.body
316
+ end
317
+
318
+ assert_nothing_raised do
319
+ response = test_process(MixedSpecializationController, 'foo')
320
+ assert_equal 'foo', response.body
321
+ end
322
+ end
323
+
288
324
  private
289
325
  def test_process(controller, action = "show")
290
326
  request = ActionController::TestRequest.new
@@ -1,20 +1,30 @@
1
1
  require File.dirname(__FILE__) + '/../abstract_unit'
2
+ $:.unshift(File.dirname(__FILE__) + '/../fixtures/helpers')
2
3
 
3
- class HelperTest < Test::Unit::TestCase
4
- HELPER_PATHS = %w(/../fixtures/helpers)
4
+ class TestController < ActionController::Base
5
+ attr_accessor :delegate_attr
6
+ def delegate_method() end
7
+ def rescue_action(e) raise end
8
+ end
9
+
10
+ module Fun
11
+ class GamesController < ActionController::Base
12
+ def render_hello_world
13
+ render_template "hello: <%= stratego %>"
14
+ end
5
15
 
6
- class TestController < ActionController::Base
7
- attr_accessor :delegate_attr
8
- def delegate_method() end
9
16
  def rescue_action(e) raise end
10
17
  end
18
+ end
11
19
 
12
- module LocalAbcHelper
13
- def a() end
14
- def b() end
15
- def c() end
16
- end
20
+ module LocalAbcHelper
21
+ def a() end
22
+ def b() end
23
+ def c() end
24
+ end
17
25
 
26
+ class HelperTest < Test::Unit::TestCase
27
+ HELPER_PATHS = %w(/../fixtures/helpers)
18
28
 
19
29
  def setup
20
30
  # Increment symbol counter.
@@ -102,6 +112,13 @@ class HelperTest < Test::Unit::TestCase
102
112
  assert template_methods.include?('delegate_attr=')
103
113
  end
104
114
 
115
+ def test_helper_for_nested_controller
116
+ @request = ActionController::TestRequest.new
117
+ @response = ActionController::TestResponse.new
118
+ @request.action = "render_hello_world"
119
+
120
+ assert_equal "hello: Iz guuut!", Fun::GamesController.process(@request, @response).body
121
+ end
105
122
 
106
123
  private
107
124
  def helper_methods; TestHelper.instance_methods end
@@ -1,44 +1,36 @@
1
1
  require File.dirname(__FILE__) + '/../abstract_unit'
2
2
 
3
- class RedirectTest < Test::Unit::TestCase
4
- class RedirectController < ActionController::Base
5
- def simple_redirect
6
- redirect_to :action => "hello_world"
7
- end
8
-
9
- def method_redirect
10
- redirect_to :dashbord_url, 1, "hello"
11
- end
12
-
13
- def rescue_errors(e) raise e end
14
-
15
- protected
16
- def dashbord_url(id, message)
17
- url_for :action => "dashboard", :params => { "id" => id, "message" => message }
18
- end
3
+ class RedirectController < ActionController::Base
4
+ def simple_redirect
5
+ redirect_to :action => "hello_world"
6
+ end
7
+
8
+ def method_redirect
9
+ redirect_to :dashbord_url, 1, "hello"
19
10
  end
11
+
12
+ def rescue_errors(e) raise e end
13
+
14
+ protected
15
+ def dashbord_url(id, message)
16
+ url_for :action => "dashboard", :params => { "id" => id, "message" => message }
17
+ end
18
+ end
20
19
 
20
+ class RedirectTest < Test::Unit::TestCase
21
21
  def setup
22
- @request = ActionController::TestRequest.new
23
- @response = ActionController::TestResponse.new
22
+ @controller = RedirectController.new
23
+ @request = ActionController::TestRequest.new
24
+ @response = ActionController::TestResponse.new
24
25
  end
25
26
 
26
27
  def test_simple_redirect
27
- @request.path = "/redirect/simple_redirect"
28
- @request.action = "simple_redirect"
29
- response = process_request
30
- assert_equal "http://test.host/redirect/hello_world", response.headers["location"]
28
+ get :simple_redirect
29
+ assert_redirect_url "http://test.host/redirect/hello_world"
31
30
  end
32
31
 
33
32
  def test_redirect_with_method_reference_and_parameters
34
- @request.path = "/redirect/method_redirect"
35
- @request.action = "method_redirect"
36
- response = process_request
37
- assert_equal "http://test.host/redirect/dashboard?message=hello&id=1", response.headers["location"]
33
+ get :method_redirect
34
+ assert_redirect_url "http://test.host/redirect/dashboard/1?message=hello"
38
35
  end
39
-
40
- private
41
- def process_request
42
- RedirectController.process(@request, @response)
43
- end
44
36
  end
@@ -2,86 +2,97 @@ require File.dirname(__FILE__) + '/../abstract_unit'
2
2
 
3
3
  Customer = Struct.new("Customer", :name)
4
4
 
5
- class RenderTest < Test::Unit::TestCase
6
- class TestController < ActionController::Base
7
- layout :determine_layout
8
-
5
+ module Fun
6
+ class GamesController < ActionController::Base
9
7
  def hello_world
10
8
  end
9
+ end
10
+ end
11
11
 
12
- def render_hello_world
13
- render "test/hello_world"
14
- end
15
12
 
16
- def render_hello_world_from_variable
17
- @person = "david"
18
- render_text "hello #{@person}"
19
- end
13
+ class TestController < ActionController::Base
14
+ layout :determine_layout
20
15
 
21
- def render_action_hello_world
22
- render_action "hello_world"
23
- end
24
-
25
- def render_text_hello_world
26
- render_text "hello world"
27
- end
28
-
29
- def render_custom_code
30
- render_text "hello world", "404 Moved"
31
- end
32
-
33
- def render_xml_hello
34
- @name = "David"
35
- render "test/hello"
36
- end
16
+ def hello_world
17
+ end
37
18
 
38
- def greeting
39
- # let's just rely on the template
40
- end
19
+ def render_hello_world
20
+ render "test/hello_world"
21
+ end
41
22
 
42
- def layout_test
43
- render_action "hello_world"
44
- end
45
-
46
- def builder_layout_test
47
- render_action "hello"
48
- end
23
+ def render_hello_world_from_variable
24
+ @person = "david"
25
+ render_text "hello #{@person}"
26
+ end
49
27
 
50
- def partials_list
51
- @customers = [ Customer.new("david"), Customer.new("mary") ]
52
- render_action "list"
53
- end
28
+ def render_action_hello_world
29
+ render_action "hello_world"
30
+ end
31
+
32
+ def render_text_hello_world
33
+ render_text "hello world"
34
+ end
54
35
 
55
- def modgreet
56
- end
36
+ def render_custom_code
37
+ render_text "hello world", "404 Moved"
38
+ end
39
+
40
+ def render_xml_hello
41
+ @name = "David"
42
+ render "test/hello"
43
+ end
57
44
 
58
- def rescue_action(e) raise end
59
-
60
- private
61
- def determine_layout
62
- case action_name
63
- when "layout_test": "layouts/standard"
64
- when "builder_layout_test": "layouts/builder"
65
- end
66
- end
45
+ def greeting
46
+ # let's just rely on the template
67
47
  end
68
48
 
69
- TestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
49
+ def layout_test
50
+ render_action "hello_world"
51
+ end
70
52
 
71
- class TestLayoutController < ActionController::Base
72
- layout "layouts/standard"
73
-
74
- def hello_world
75
- end
53
+ def builder_layout_test
54
+ render_action "hello"
55
+ end
56
+
57
+ def partials_list
58
+ @customers = [ Customer.new("david"), Customer.new("mary") ]
59
+ render_action "list"
60
+ end
61
+
62
+ def hello_in_a_string
63
+ @customers = [ Customer.new("david"), Customer.new("mary") ]
64
+ render_text "How's there? #{render_to_string("test/list")}"
65
+ end
66
+
67
+ def rescue_action(e) raise end
76
68
 
77
- def hello_world_outside_layout
69
+ private
70
+ def determine_layout
71
+ case action_name
72
+ when "layout_test": "layouts/standard"
73
+ when "builder_layout_test": "layouts/builder"
74
+ end
78
75
  end
76
+ end
79
77
 
80
- def rescue_action(e)
81
- raise unless ActionController::MissingTemplate === e
82
- end
78
+ TestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
79
+ Fun::GamesController.template_root = File.dirname(__FILE__) + "/../fixtures/"
80
+
81
+ class TestLayoutController < ActionController::Base
82
+ layout "layouts/standard"
83
+
84
+ def hello_world
85
+ end
86
+
87
+ def hello_world_outside_layout
83
88
  end
84
89
 
90
+ def rescue_action(e)
91
+ raise unless ActionController::MissingTemplate === e
92
+ end
93
+ end
94
+
95
+ class RenderTest < Test::Unit::TestCase
85
96
  def setup
86
97
  @request = ActionController::TestRequest.new
87
98
  @response = ActionController::TestResponse.new
@@ -170,10 +181,14 @@ class RenderTest < Test::Unit::TestCase
170
181
  assert_equal "Hello: davidHello: mary", process_request.body
171
182
  end
172
183
 
173
- def test_module_rendering
174
- @request.action = "modgreet"
175
- @request.parameters["module"] = "scope"
176
- assert_equal "<p>Beautiful modules!</p>", process_request.body
184
+ def test_render_to_string
185
+ @request.action = "hello_in_a_string"
186
+ assert_equal "How's there? Hello: davidHello: mary", process_request.body
187
+ end
188
+
189
+ def test_nested_rendering
190
+ @request.action = "hello_world"
191
+ assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
177
192
  end
178
193
 
179
194
  private