actionpack 1.11.2 → 1.12.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.
- data/CHANGELOG +392 -5
- data/lib/action_controller.rb +8 -4
- data/lib/action_controller/assertions.rb +9 -10
- data/lib/action_controller/base.rb +177 -88
- data/lib/action_controller/benchmarking.rb +5 -5
- data/lib/action_controller/caching.rb +44 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
- data/lib/action_controller/cgi_process.rb +36 -24
- data/lib/action_controller/components.rb +152 -52
- data/lib/action_controller/dependencies.rb +1 -1
- data/lib/action_controller/deprecated_redirects.rb +2 -2
- data/lib/action_controller/deprecated_request_methods.rb +34 -0
- data/lib/action_controller/filters.rb +59 -19
- data/lib/action_controller/flash.rb +53 -47
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/integration.rb +524 -0
- data/lib/action_controller/layout.rb +58 -23
- data/lib/action_controller/mime_responds.rb +163 -0
- data/lib/action_controller/mime_type.rb +142 -0
- data/lib/action_controller/pagination.rb +13 -7
- data/lib/action_controller/request.rb +59 -56
- data/lib/action_controller/rescue.rb +1 -1
- data/lib/action_controller/routing.rb +29 -10
- data/lib/action_controller/scaffolding.rb +8 -0
- data/lib/action_controller/session/active_record_store.rb +21 -10
- data/lib/action_controller/session/mem_cache_store.rb +18 -12
- data/lib/action_controller/session_management.rb +30 -11
- data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
- data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +189 -118
- data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
- data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
- data/lib/action_controller/vendor/xml_node.rb +97 -0
- data/lib/action_controller/verification.rb +2 -0
- data/lib/action_pack/version.rb +3 -3
- data/lib/action_view.rb +0 -2
- data/lib/action_view/base.rb +109 -36
- data/lib/action_view/compiled_templates.rb +1 -1
- data/lib/action_view/helpers/active_record_helper.rb +4 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
- data/lib/action_view/helpers/capture_helper.rb +49 -12
- data/lib/action_view/helpers/date_helper.rb +14 -4
- data/lib/action_view/helpers/form_helper.rb +136 -20
- data/lib/action_view/helpers/form_options_helper.rb +29 -7
- data/lib/action_view/helpers/form_tag_helper.rb +22 -20
- data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
- data/lib/action_view/helpers/javascript_helper.rb +50 -446
- data/lib/action_view/helpers/javascripts/controls.js +95 -30
- data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
- data/lib/action_view/helpers/javascripts/effects.js +310 -211
- data/lib/action_view/helpers/javascripts/prototype.js +228 -28
- data/lib/action_view/helpers/number_helper.rb +9 -9
- data/lib/action_view/helpers/pagination_helper.rb +1 -1
- data/lib/action_view/helpers/prototype_helper.rb +900 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
- data/lib/action_view/helpers/text_helper.rb +7 -6
- data/lib/action_view/helpers/url_helper.rb +23 -14
- data/lib/action_view/partials.rb +12 -4
- data/rakefile +13 -5
- data/test/abstract_unit.rb +4 -3
- data/test/active_record_unit.rb +88 -0
- data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
- data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
- data/test/activerecord/pagination_test.rb +161 -0
- data/test/controller/action_pack_assertions_test.rb +18 -15
- data/test/controller/base_test.rb +31 -42
- data/test/controller/benchmark_test.rb +8 -11
- data/test/controller/capture_test.rb +33 -1
- data/test/controller/cgi_test.rb +33 -0
- data/test/controller/custom_handler_test.rb +8 -0
- data/test/controller/fake_controllers.rb +9 -17
- data/test/controller/filters_test.rb +32 -3
- data/test/controller/flash_test.rb +26 -41
- data/test/controller/fragment_store_setting_test.rb +1 -1
- data/test/controller/layout_test.rb +73 -0
- data/test/controller/mime_responds_test.rb +257 -0
- data/test/controller/mime_type_test.rb +24 -0
- data/test/controller/new_render_test.rb +157 -1
- data/test/controller/redirect_test.rb +23 -0
- data/test/controller/render_test.rb +54 -56
- data/test/controller/request_test.rb +25 -0
- data/test/controller/routing_test.rb +74 -66
- data/test/controller/test_test.rb +66 -1
- data/test/controller/verification_test.rb +3 -1
- data/test/controller/webservice_test.rb +255 -0
- data/test/fixtures/companies.yml +24 -0
- data/test/fixtures/company.rb +9 -0
- data/test/fixtures/db_definitions/sqlite.sql +42 -0
- data/test/fixtures/developer.rb +7 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +13 -0
- data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
- data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
- data/test/fixtures/multipart/mona_lisa.jpg +0 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/replies.yml +13 -0
- data/test/fixtures/reply.rb +5 -0
- data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
- data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
- data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults.rxml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
- data/test/fixtures/test/block_content_for.rhtml +2 -0
- data/test/fixtures/test/delete_with_js.rjs +2 -0
- data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
- data/test/fixtures/test/enum_rjs_test.rjs +6 -0
- data/test/fixtures/test/erb_content_for.rhtml +2 -0
- data/test/fixtures/test/hello_world.rxml +3 -0
- data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
- data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/template/active_record_helper_test.rb +4 -0
- data/test/template/asset_tag_helper_test.rb +7 -2
- data/test/template/date_helper_test.rb +39 -2
- data/test/template/form_helper_test.rb +238 -5
- data/test/template/form_options_helper_test.rb +78 -0
- data/test/template/form_tag_helper_test.rb +11 -0
- data/test/template/java_script_macros_helper_test.rb +51 -6
- data/test/template/javascript_helper_test.rb +7 -153
- data/test/template/number_helper_test.rb +14 -13
- data/test/template/prototype_helper_test.rb +423 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/text_helper_test.rb +12 -9
- data/test/template/url_helper_test.rb +31 -15
- metadata +291 -246
- data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
- data/lib/action_controller/upload_progress.rb +0 -473
- data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
- data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
- data/lib/action_view/vendor/builder.rb +0 -13
- data/lib/action_view/vendor/builder/blankslate.rb +0 -53
- data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
- data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
- data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
- data/test/controller/multipart_progress_testx.rb +0 -365
- data/test/controller/upload_progress_testx.rb +0 -89
- data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -1,17 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
|
-
# Provide
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
render :nothing => true
|
10
|
-
end
|
4
|
+
# Provide some static controllers.
|
5
|
+
class BenchmarkedController < ActionController::Base
|
6
|
+
def public_action
|
7
|
+
render :nothing => true
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
10
|
+
def rescue_action(e)
|
11
|
+
raise e
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
@@ -22,7 +19,7 @@ class BenchmarkTest < Test::Unit::TestCase
|
|
22
19
|
end
|
23
20
|
|
24
21
|
def setup
|
25
|
-
@controller =
|
22
|
+
@controller = BenchmarkedController.new
|
26
23
|
# benchmark doesn't do anything unless a logger is set
|
27
24
|
@controller.logger = MockLogger.new
|
28
25
|
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
@@ -7,6 +7,18 @@ class CaptureController < ActionController::Base
|
|
7
7
|
def content_for
|
8
8
|
render :layout => "talk_from_action"
|
9
9
|
end
|
10
|
+
|
11
|
+
def erb_content_for
|
12
|
+
render :layout => "talk_from_action"
|
13
|
+
end
|
14
|
+
|
15
|
+
def block_content_for
|
16
|
+
render :layout => "talk_from_action"
|
17
|
+
end
|
18
|
+
|
19
|
+
def non_erb_block_content_for
|
20
|
+
render :layout => "talk_from_action"
|
21
|
+
end
|
10
22
|
|
11
23
|
def rescue_action(e) raise end
|
12
24
|
end
|
@@ -34,7 +46,22 @@ class CaptureTest < Test::Unit::TestCase
|
|
34
46
|
|
35
47
|
def test_content_for
|
36
48
|
get :content_for
|
37
|
-
assert_equal
|
49
|
+
assert_equal expected_content_for_output, @response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_erb_content_for
|
53
|
+
get :content_for
|
54
|
+
assert_equal expected_content_for_output, @response.body
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_block_content_for
|
58
|
+
get :block_content_for
|
59
|
+
assert_equal expected_content_for_output, @response.body
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_non_erb_block_content_for
|
63
|
+
get :non_erb_block_content_for
|
64
|
+
assert_equal expected_content_for_output, @response.body
|
38
65
|
end
|
39
66
|
|
40
67
|
def test_update_element_with_capture
|
@@ -45,4 +72,9 @@ class CaptureTest < Test::Unit::TestCase
|
|
45
72
|
@response.body.strip
|
46
73
|
)
|
47
74
|
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def expected_content_for_output
|
78
|
+
"<title>Putting stuff in the title!</title>\n\nGreat stuff!"
|
79
|
+
end
|
48
80
|
end
|
data/test/controller/cgi_test.rb
CHANGED
@@ -313,6 +313,8 @@ end
|
|
313
313
|
class CGIRequestTest < Test::Unit::TestCase
|
314
314
|
def setup
|
315
315
|
@request_hash = {"HTTP_MAX_FORWARDS"=>"10", "SERVER_NAME"=>"glu.ttono.us:8007", "FCGI_ROLE"=>"RESPONDER", "HTTP_X_FORWARDED_HOST"=>"glu.ttono.us", "HTTP_ACCEPT_ENCODING"=>"gzip, deflate", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.5.1 (KHTML, like Gecko) Safari/312.3.1", "PATH_INFO"=>"", "HTTP_ACCEPT_LANGUAGE"=>"en", "HTTP_HOST"=>"glu.ttono.us:8007", "SERVER_PROTOCOL"=>"HTTP/1.1", "REDIRECT_URI"=>"/dispatch.fcgi", "SCRIPT_NAME"=>"/dispatch.fcgi", "SERVER_ADDR"=>"207.7.108.53", "REMOTE_ADDR"=>"207.7.108.53", "SERVER_SOFTWARE"=>"lighttpd/1.4.5", "HTTP_COOKIE"=>"_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes", "HTTP_X_FORWARDED_SERVER"=>"glu.ttono.us", "REQUEST_URI"=>"/admin", "DOCUMENT_ROOT"=>"/home/kevinc/sites/typo/public", "SERVER_PORT"=>"8007", "QUERY_STRING"=>"", "REMOTE_PORT"=>"63137", "GATEWAY_INTERFACE"=>"CGI/1.1", "HTTP_X_FORWARDED_FOR"=>"65.88.180.234", "HTTP_ACCEPT"=>"*/*", "SCRIPT_FILENAME"=>"/home/kevinc/sites/typo/public/dispatch.fcgi", "REDIRECT_STATUS"=>"200", "REQUEST_METHOD"=>"GET"}
|
316
|
+
# cookie as returned by some Nokia phone browsers (no space after semicolon separator)
|
317
|
+
@alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace84796670c052c6ceb2451fb0f2;is_admin=yes"}
|
316
318
|
@fake_cgi = Struct.new(:env_table).new(@request_hash)
|
317
319
|
@request = ActionController::CgiRequest.new(@fake_cgi)
|
318
320
|
end
|
@@ -325,6 +327,37 @@ class CGIRequestTest < Test::Unit::TestCase
|
|
325
327
|
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
326
328
|
@request_hash['HTTP_HOST'] = "rubyonrails.org:8080"
|
327
329
|
assert_equal "rubyonrails.org:8080", @request.host_with_port
|
330
|
+
|
331
|
+
@request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
|
332
|
+
assert_equal "www.secondhost.org", @request.host
|
328
333
|
end
|
329
334
|
|
335
|
+
def test_http_host_with_default_port_overrides_server_port
|
336
|
+
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
337
|
+
@request_hash['HTTP_HOST'] = "rubyonrails.org"
|
338
|
+
assert_equal "rubyonrails.org", @request.host_with_port
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_host_with_port_defaults_to_server_name_if_no_host_headers
|
342
|
+
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
343
|
+
@request_hash.delete "HTTP_HOST"
|
344
|
+
assert_equal "glu.ttono.us:8007", @request.host_with_port
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_host_with_port_falls_back_to_server_addr_if_necessary
|
348
|
+
@request_hash.delete "HTTP_X_FORWARDED_HOST"
|
349
|
+
@request_hash.delete "HTTP_HOST"
|
350
|
+
@request_hash.delete "SERVER_NAME"
|
351
|
+
assert_equal "207.7.108.53:8007", @request.host_with_port
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_cookie_syntax_resilience
|
355
|
+
cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]);
|
356
|
+
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"]
|
357
|
+
assert_equal ["yes"], cookies["is_admin"]
|
358
|
+
|
359
|
+
alt_cookies = CGI::Cookie::parse(@alt_cookie_fmt_request_hash["HTTP_COOKIE"]);
|
360
|
+
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], alt_cookies["_session_id"]
|
361
|
+
assert_equal ["yes"], alt_cookies["is_admin"]
|
362
|
+
end
|
330
363
|
end
|
@@ -15,6 +15,7 @@ end
|
|
15
15
|
class CustomHandlerTest < Test::Unit::TestCase
|
16
16
|
def setup
|
17
17
|
ActionView::Base.register_template_handler "foo", CustomHandler
|
18
|
+
ActionView::Base.register_template_handler :foo2, CustomHandler
|
18
19
|
@view = ActionView::Base.new
|
19
20
|
end
|
20
21
|
|
@@ -25,6 +26,13 @@ class CustomHandlerTest < Test::Unit::TestCase
|
|
25
26
|
result )
|
26
27
|
end
|
27
28
|
|
29
|
+
def test_custom_render2
|
30
|
+
result = @view.render_template( "foo2", "hello <%= one %>", nil, :one => "two" )
|
31
|
+
assert_equal(
|
32
|
+
[ "hello <%= one %>", { :one => "two" }, @view ],
|
33
|
+
result )
|
34
|
+
end
|
35
|
+
|
28
36
|
def test_unhandled_extension
|
29
37
|
# uses the ERb handler by default if the extension isn't recognized
|
30
38
|
result = @view.render_template( "bar", "hello <%= one %>", nil, :one => "two" )
|
@@ -1,21 +1,13 @@
|
|
1
|
-
|
2
|
-
def self.const_available?(*args)
|
3
|
-
const_defined?(*args)
|
4
|
-
end
|
1
|
+
class << Object; alias_method :const_available?, :const_defined?; end
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
class UserController < ActionController::Base
|
15
|
-
end
|
16
|
-
class NewsFeedController < ActionController::Base
|
17
|
-
end
|
18
|
-
end
|
3
|
+
class ContentController < Class.new(ActionController::Base)
|
4
|
+
end
|
5
|
+
class NotAController
|
6
|
+
end
|
7
|
+
module Admin
|
8
|
+
class << self; alias_method :const_available?, :const_defined?; end
|
9
|
+
class UserController < Class.new(ActionController::Base); end
|
10
|
+
class NewsFeedController < Class.new(ActionController::Base); end
|
19
11
|
end
|
20
12
|
|
21
13
|
ActionController::Routing::Routes.draw do |map|
|
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../abstract_unit'
|
|
3
3
|
class FilterTest < Test::Unit::TestCase
|
4
4
|
class TestController < ActionController::Base
|
5
5
|
before_filter :ensure_login
|
6
|
+
after_filter :clean_up
|
6
7
|
|
7
8
|
def show
|
8
9
|
render :inline => "ran action"
|
@@ -13,6 +14,11 @@ class FilterTest < Test::Unit::TestCase
|
|
13
14
|
@ran_filter ||= []
|
14
15
|
@ran_filter << "ensure_login"
|
15
16
|
end
|
17
|
+
|
18
|
+
def clean_up
|
19
|
+
@ran_after_filter ||= []
|
20
|
+
@ran_after_filter << "clean_up"
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
class RenderingController < ActionController::Base
|
@@ -99,7 +105,7 @@ class FilterTest < Test::Unit::TestCase
|
|
99
105
|
|
100
106
|
class PrependingController < TestController
|
101
107
|
prepend_before_filter :wonderful_life
|
102
|
-
skip_before_filter :fire_flash
|
108
|
+
# skip_before_filter :fire_flash
|
103
109
|
|
104
110
|
private
|
105
111
|
def wonderful_life
|
@@ -108,6 +114,20 @@ class FilterTest < Test::Unit::TestCase
|
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
117
|
+
class ConditionalSkippingController < TestController
|
118
|
+
skip_before_filter :ensure_login, :only => [ :login ]
|
119
|
+
skip_after_filter :clean_up, :only => [ :login ]
|
120
|
+
|
121
|
+
def login
|
122
|
+
render :inline => "ran action"
|
123
|
+
end
|
124
|
+
|
125
|
+
def change_password
|
126
|
+
render :inline => "ran action"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
111
131
|
class ProcController < PrependingController
|
112
132
|
before_filter(proc { |c| c.assigns["ran_proc_filter"] = true })
|
113
133
|
end
|
@@ -169,6 +189,7 @@ class FilterTest < Test::Unit::TestCase
|
|
169
189
|
|
170
190
|
class MixedFilterController < PrependingController
|
171
191
|
cattr_accessor :execution_log
|
192
|
+
|
172
193
|
def initialize
|
173
194
|
@@execution_log = ""
|
174
195
|
end
|
@@ -218,11 +239,11 @@ class FilterTest < Test::Unit::TestCase
|
|
218
239
|
end
|
219
240
|
|
220
241
|
def test_added_filter_to_inheritance_graph
|
221
|
-
assert_equal [ :
|
242
|
+
assert_equal [ :ensure_login ], TestController.before_filters
|
222
243
|
end
|
223
244
|
|
224
245
|
def test_base_class_in_isolation
|
225
|
-
assert_equal [
|
246
|
+
assert_equal [ ], ActionController::Base.before_filters
|
226
247
|
end
|
227
248
|
|
228
249
|
def test_prepending_filter
|
@@ -343,6 +364,14 @@ class FilterTest < Test::Unit::TestCase
|
|
343
364
|
end
|
344
365
|
end
|
345
366
|
|
367
|
+
def test_conditional_skipping_of_filters
|
368
|
+
assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"]
|
369
|
+
assert_equal %w( ensure_login ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"]
|
370
|
+
|
371
|
+
assert_nil test_process(ConditionalSkippingController, "login").template.controller.instance_variable_get("@ran_after_filter")
|
372
|
+
assert_equal %w( clean_up ), test_process(ConditionalSkippingController, "change_password").template.controller.instance_variable_get("@ran_after_filter")
|
373
|
+
end
|
374
|
+
|
346
375
|
private
|
347
376
|
def test_process(controller, action = "show")
|
348
377
|
request = ActionController::TestRequest.new
|
@@ -41,60 +41,45 @@ class FlashTest < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def setup
|
44
|
-
|
44
|
+
@request = ActionController::TestRequest.new
|
45
|
+
@response = ActionController::TestResponse.new
|
46
|
+
@controller = TestController.new
|
45
47
|
end
|
46
48
|
|
47
49
|
def test_flash
|
48
|
-
|
49
|
-
response = process_request
|
50
|
+
get :set_flash
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
assert_equal "hello",
|
54
|
-
assert_equal "hello", first_response.template.assigns["flashy"]
|
52
|
+
get :use_flash
|
53
|
+
assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
|
54
|
+
assert_equal "hello", @response.template.assigns["flashy"]
|
55
55
|
|
56
|
-
|
57
|
-
assert_nil
|
56
|
+
get :use_flash
|
57
|
+
assert_nil @response.template.assigns["flash_copy"]["that"], "On second flash"
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_keep_flash
|
61
|
-
|
62
|
-
response = process_request
|
61
|
+
get :set_flash
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
assert_equal "hello",
|
67
|
-
assert_equal "hello", first_response.template.assigns["flashy"]
|
63
|
+
get :use_flash_and_keep_it
|
64
|
+
assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
|
65
|
+
assert_equal "hello", @response.template.assigns["flashy"]
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
assert_equal "hello", second_response.template.assigns["flash_copy"]["that"], "On second flash"
|
67
|
+
get :use_flash
|
68
|
+
assert_equal "hello", @response.template.assigns["flash_copy"]["that"], "On second flash"
|
72
69
|
|
73
|
-
|
74
|
-
assert_nil
|
70
|
+
get :use_flash
|
71
|
+
assert_nil @response.template.assigns["flash_copy"]["that"], "On third flash"
|
75
72
|
end
|
76
73
|
|
77
74
|
def test_flash_now
|
78
|
-
|
79
|
-
|
80
|
-
assert_equal "
|
81
|
-
assert_equal "
|
82
|
-
assert_equal "hello", response.template.assigns["flashy"]
|
75
|
+
get :set_flash_now
|
76
|
+
assert_equal "hello", @response.template.assigns["flash_copy"]["that"]
|
77
|
+
assert_equal "bar" , @response.template.assigns["flash_copy"]["foo"]
|
78
|
+
assert_equal "hello", @response.template.assigns["flashy"]
|
83
79
|
|
84
|
-
|
85
|
-
|
86
|
-
assert_nil
|
87
|
-
assert_nil
|
88
|
-
assert_nil first_response.template.assigns["flashy"]
|
80
|
+
get :attempt_to_use_flash_now
|
81
|
+
assert_nil @response.template.assigns["flash_copy"]["that"]
|
82
|
+
assert_nil @response.template.assigns["flash_copy"]["foo"]
|
83
|
+
assert_nil @response.template.assigns["flashy"]
|
89
84
|
end
|
90
|
-
|
91
|
-
private
|
92
|
-
def initialize_request_and_response
|
93
|
-
@request = ActionController::TestRequest.new
|
94
|
-
@response = ActionController::TestResponse.new
|
95
|
-
end
|
96
|
-
|
97
|
-
def process_request
|
98
|
-
TestController.process(@request, @response)
|
99
|
-
end
|
100
|
-
end
|
85
|
+
end
|
@@ -31,7 +31,7 @@ class FragmentCacheStoreSettingTest < Test::Unit::TestCase
|
|
31
31
|
ActionController::Caching::Fragments::MemCacheStore,
|
32
32
|
ActionController::Base.fragment_cache_store
|
33
33
|
)
|
34
|
-
assert_equal
|
34
|
+
assert_equal %w(localhost), ActionController::Base.fragment_cache_store.addresses
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_object_assigned_fragment_cache_store
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
# The template_root must be set on Base and not LayoutTest so that LayoutTest's inherited method has access to
|
4
|
+
# the template_root when looking for a layout
|
5
|
+
ActionController::Base.template_root = File.dirname(__FILE__) + '/../fixtures/layout_tests/'
|
6
|
+
|
7
|
+
class LayoutTest < ActionController::Base
|
8
|
+
def self.controller_path; 'views' end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Restore template root to be unset
|
12
|
+
ActionController::Base.template_root = nil
|
13
|
+
|
14
|
+
class ProductController < LayoutTest
|
15
|
+
end
|
16
|
+
|
17
|
+
class ItemController < LayoutTest
|
18
|
+
end
|
19
|
+
|
20
|
+
class ThirdPartyTemplateLibraryController < LayoutTest
|
21
|
+
end
|
22
|
+
|
23
|
+
module ControllerNameSpace
|
24
|
+
end
|
25
|
+
|
26
|
+
class ControllerNameSpace::NestedController < LayoutTest
|
27
|
+
end
|
28
|
+
|
29
|
+
class MabView
|
30
|
+
def initialize(view)
|
31
|
+
end
|
32
|
+
|
33
|
+
def render(text, locals = {})
|
34
|
+
text
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ActionView::Base::register_template_handler :mab, MabView
|
39
|
+
|
40
|
+
class LayoutAutoDiscoveryTest < Test::Unit::TestCase
|
41
|
+
def setup
|
42
|
+
@request = ActionController::TestRequest.new
|
43
|
+
@response = ActionController::TestResponse.new
|
44
|
+
|
45
|
+
@request.host = "www.nextangle.com"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_application_layout_is_default_when_no_controller_match
|
49
|
+
@controller = ProductController.new
|
50
|
+
get :hello
|
51
|
+
assert_equal 'layout_test.rhtml hello.rhtml', @response.body
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_controller_name_layout_name_match
|
55
|
+
@controller = ItemController.new
|
56
|
+
get :hello
|
57
|
+
assert_equal 'item.rhtml hello.rhtml', @response.body
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_third_party_template_library_auto_discovers_layout
|
61
|
+
@controller = ThirdPartyTemplateLibraryController.new
|
62
|
+
get :hello
|
63
|
+
assert_equal 'layouts/third_party_template_library', @controller.active_layout
|
64
|
+
assert_equal 'Mab', @response.body
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_namespaced_controllers_auto_detect_layouts
|
68
|
+
@controller = ControllerNameSpace::NestedController.new
|
69
|
+
get :hello
|
70
|
+
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
|
71
|
+
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
class RespondToController < ActionController::Base
|
4
|
+
layout :set_layout
|
5
|
+
|
6
|
+
def html_xml_or_rss
|
7
|
+
respond_to do |type|
|
8
|
+
type.html { render :text => "HTML" }
|
9
|
+
type.xml { render :text => "XML" }
|
10
|
+
type.rss { render :text => "RSS" }
|
11
|
+
type.all { render :text => "Nothing" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def js_or_html
|
16
|
+
respond_to do |type|
|
17
|
+
type.html { render :text => "HTML" }
|
18
|
+
type.js { render :text => "JS" }
|
19
|
+
type.all { render :text => "Nothing" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def html_or_xml
|
24
|
+
respond_to do |type|
|
25
|
+
type.html { render :text => "HTML" }
|
26
|
+
type.xml { render :text => "XML" }
|
27
|
+
type.all { render :text => "Nothing" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def just_xml
|
32
|
+
respond_to do |type|
|
33
|
+
type.xml { render :text => "XML" }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def using_defaults
|
38
|
+
respond_to do |type|
|
39
|
+
type.html
|
40
|
+
type.js
|
41
|
+
type.xml
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def using_defaults_with_type_list
|
46
|
+
respond_to(:html, :js, :xml)
|
47
|
+
end
|
48
|
+
|
49
|
+
def made_for_content_type
|
50
|
+
respond_to do |type|
|
51
|
+
type.rss { render :text => "RSS" }
|
52
|
+
type.atom { render :text => "ATOM" }
|
53
|
+
type.all { render :text => "Nothing" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def custom_type_handling
|
58
|
+
respond_to do |type|
|
59
|
+
type.html { render :text => "HTML" }
|
60
|
+
type.custom("application/crazy-xml") { render :text => "Crazy XML" }
|
61
|
+
type.all { render :text => "Nothing" }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle_any
|
66
|
+
respond_to do |type|
|
67
|
+
type.html { render :text => "HTML" }
|
68
|
+
type.any(:js, :xml) { render :text => "Either JS or XML" }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def all_types_with_layout
|
73
|
+
respond_to do |type|
|
74
|
+
type.html
|
75
|
+
type.js
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def rescue_action(e)
|
80
|
+
raise
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
def set_layout
|
85
|
+
if action_name == "all_types_with_layout"
|
86
|
+
"standard"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
RespondToController.template_root = File.dirname(__FILE__) + "/../fixtures/"
|
92
|
+
|
93
|
+
class MimeControllerTest < Test::Unit::TestCase
|
94
|
+
def setup
|
95
|
+
@request = ActionController::TestRequest.new
|
96
|
+
@response = ActionController::TestResponse.new
|
97
|
+
|
98
|
+
@controller = RespondToController.new
|
99
|
+
@request.host = "www.example.com"
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_html
|
103
|
+
@request.env["HTTP_ACCEPT"] = "text/html"
|
104
|
+
get :js_or_html
|
105
|
+
assert_equal 'HTML', @response.body
|
106
|
+
|
107
|
+
get :html_or_xml
|
108
|
+
assert_equal 'HTML', @response.body
|
109
|
+
|
110
|
+
get :just_xml
|
111
|
+
assert_response 406
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_all
|
115
|
+
@request.env["HTTP_ACCEPT"] = "*/*"
|
116
|
+
get :js_or_html
|
117
|
+
assert_equal 'HTML', @response.body # js is not part of all
|
118
|
+
|
119
|
+
get :html_or_xml
|
120
|
+
assert_equal 'HTML', @response.body
|
121
|
+
|
122
|
+
get :just_xml
|
123
|
+
assert_equal 'XML', @response.body
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_xml
|
127
|
+
@request.env["HTTP_ACCEPT"] = "application/xml"
|
128
|
+
get :html_xml_or_rss
|
129
|
+
assert_equal 'XML', @response.body
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_js_or_html
|
133
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript, text/html"
|
134
|
+
get :js_or_html
|
135
|
+
assert_equal 'JS', @response.body
|
136
|
+
|
137
|
+
get :html_or_xml
|
138
|
+
assert_equal 'HTML', @response.body
|
139
|
+
|
140
|
+
get :just_xml
|
141
|
+
assert_response 406
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_js_or_anything
|
145
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript, */*"
|
146
|
+
get :js_or_html
|
147
|
+
assert_equal 'JS', @response.body
|
148
|
+
|
149
|
+
get :html_or_xml
|
150
|
+
assert_equal 'HTML', @response.body
|
151
|
+
|
152
|
+
get :just_xml
|
153
|
+
assert_equal 'XML', @response.body
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_using_defaults
|
157
|
+
@request.env["HTTP_ACCEPT"] = "*/*"
|
158
|
+
get :using_defaults
|
159
|
+
assert_equal 'Hello world!', @response.body
|
160
|
+
|
161
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
162
|
+
get :using_defaults
|
163
|
+
assert_equal '$("body").visualEffect("highlight");', @response.body
|
164
|
+
|
165
|
+
@request.env["HTTP_ACCEPT"] = "application/xml"
|
166
|
+
get :using_defaults
|
167
|
+
assert_equal "<p>Hello world!</p>\n", @response.body
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_using_defaults_with_type_list
|
171
|
+
@request.env["HTTP_ACCEPT"] = "*/*"
|
172
|
+
get :using_defaults_with_type_list
|
173
|
+
assert_equal 'Hello world!', @response.body
|
174
|
+
|
175
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
176
|
+
get :using_defaults_with_type_list
|
177
|
+
assert_equal '$("body").visualEffect("highlight");', @response.body
|
178
|
+
|
179
|
+
@request.env["HTTP_ACCEPT"] = "application/xml"
|
180
|
+
get :using_defaults_with_type_list
|
181
|
+
assert_equal "<p>Hello world!</p>\n", @response.body
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_with_content_type
|
185
|
+
@request.env["CONTENT_TYPE"] = "application/atom+xml"
|
186
|
+
get :made_for_content_type
|
187
|
+
assert_equal "ATOM", @response.body
|
188
|
+
|
189
|
+
@request.env["CONTENT_TYPE"] = "application/rss+xml"
|
190
|
+
get :made_for_content_type
|
191
|
+
assert_equal "RSS", @response.body
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_synonyms
|
195
|
+
@request.env["HTTP_ACCEPT"] = "application/javascript"
|
196
|
+
get :js_or_html
|
197
|
+
assert_equal 'JS', @response.body
|
198
|
+
|
199
|
+
@request.env["HTTP_ACCEPT"] = "application/x-xml"
|
200
|
+
get :html_xml_or_rss
|
201
|
+
assert_equal "XML", @response.body
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_custom_types
|
205
|
+
@request.env["HTTP_ACCEPT"] = "application/crazy-xml"
|
206
|
+
get :custom_type_handling
|
207
|
+
assert_equal 'Crazy XML', @response.body
|
208
|
+
|
209
|
+
@request.env["HTTP_ACCEPT"] = "text/html"
|
210
|
+
get :custom_type_handling
|
211
|
+
assert_equal 'HTML', @response.body
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_xhtml_alias
|
215
|
+
@request.env["HTTP_ACCEPT"] = "application/xhtml+xml,application/xml"
|
216
|
+
get :html_or_xml
|
217
|
+
assert_equal 'HTML', @response.body
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_firefox_simulation
|
221
|
+
@request.env["HTTP_ACCEPT"] = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
|
222
|
+
get :html_or_xml
|
223
|
+
assert_equal 'HTML', @response.body
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_handle_any
|
227
|
+
@request.env["HTTP_ACCEPT"] = "*/*"
|
228
|
+
get :handle_any
|
229
|
+
assert_equal 'HTML', @response.body
|
230
|
+
|
231
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
232
|
+
get :handle_any
|
233
|
+
assert_equal 'Either JS or XML', @response.body
|
234
|
+
|
235
|
+
@request.env["HTTP_ACCEPT"] = "text/xml"
|
236
|
+
get :handle_any
|
237
|
+
assert_equal 'Either JS or XML', @response.body
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_all_types_with_layout
|
241
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
242
|
+
get :all_types_with_layout
|
243
|
+
assert_equal 'RJS for all_types_with_layout', @response.body
|
244
|
+
|
245
|
+
@request.env["HTTP_ACCEPT"] = "text/html"
|
246
|
+
get :all_types_with_layout
|
247
|
+
assert_equal '<html>HTML for all_types_with_layout</html>', @response.body
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_xhr
|
251
|
+
xhr :get, :js_or_html
|
252
|
+
assert_equal 'JS', @response.body
|
253
|
+
|
254
|
+
xhr :get, :using_defaults
|
255
|
+
assert_equal '$("body").visualEffect("highlight");', @response.body
|
256
|
+
end
|
257
|
+
end
|