ghazel-erubis_rails_helper 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -0
- data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
- data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
- data/lib/erubis_rails_helper.rb +20 -0
- data/test/abstract_unit.rb +51 -0
- data/test/controller/action_pack_assertions_test.rb +516 -0
- data/test/controller/addresses_render_test.rb +37 -0
- data/test/controller/assert_select_test.rb +734 -0
- data/test/controller/base_test.rb +217 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +690 -0
- data/test/controller/capture_test.rb +66 -0
- data/test/controller/content_type_test.rb +168 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +111 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
- data/test/controller/dispatcher_test.rb +103 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +19 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +885 -0
- data/test/controller/flash_test.rb +142 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +224 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +273 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +417 -0
- data/test/controller/layout_test.rb +204 -0
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +536 -0
- data/test/controller/mime_type_test.rb +93 -0
- data/test/controller/polymorphic_routes_test.rb +293 -0
- data/test/controller/rack_test.rb +294 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +282 -0
- data/test/controller/render_test.rb +1752 -0
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +246 -0
- data/test/controller/request_test.rb +407 -0
- data/test/controller/rescue_test.rb +536 -0
- data/test/controller/resources_test.rb +1341 -0
- data/test/controller/routing_test.rb +2557 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +161 -0
- data/test/controller/session/cookie_store_test.rb +239 -0
- data/test/controller/session/mem_cache_store_test.rb +127 -0
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +692 -0
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +359 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +141 -0
- data/test/controller/webservice_test.rb +260 -0
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/template/asset_tag_helper_test.rb +713 -0
- data/test/template/atom_feed_helper_test.rb +286 -0
- data/test/template/benchmark_helper_test.rb +86 -0
- data/test/template/compiled_templates_test.rb +203 -0
- data/test/template/date_helper_i18n_test.rb +120 -0
- data/test/template/date_helper_test.rb +2469 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +1176 -0
- data/test/template/form_options_helper_test.rb +751 -0
- data/test/template/form_tag_helper_test.rb +327 -0
- data/test/template/javascript_helper_test.rb +106 -0
- data/test/template/number_helper_i18n_test.rb +69 -0
- data/test/template/number_helper_test.rb +128 -0
- data/test/template/prototype_helper_test.rb +639 -0
- data/test/template/record_tag_helper_test.rb +58 -0
- data/test/template/render_test.rb +291 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/tag_helper_test.rb +97 -0
- data/test/template/test_test.rb +54 -0
- data/test/template/text_helper_test.rb +520 -0
- data/test/template/translation_helper_test.rb +32 -0
- data/test/template/url_helper_test.rb +614 -0
- data/test/test_erubis_rails_helper.rb +4 -0
- data/test/testing_sandbox.rb +15 -0
- data/test/view/test_case_test.rb +8 -0
- metadata +174 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class CaptureController < ActionController::Base
|
4
|
+
def self.controller_name; "test"; end
|
5
|
+
def self.controller_path; "test"; end
|
6
|
+
|
7
|
+
def content_for
|
8
|
+
render :layout => "talk_from_action"
|
9
|
+
end
|
10
|
+
|
11
|
+
def content_for_with_parameter
|
12
|
+
render :layout => "talk_from_action"
|
13
|
+
end
|
14
|
+
|
15
|
+
def content_for_concatenated
|
16
|
+
render :layout => "talk_from_action"
|
17
|
+
end
|
18
|
+
|
19
|
+
def non_erb_block_content_for
|
20
|
+
render :layout => "talk_from_action"
|
21
|
+
end
|
22
|
+
|
23
|
+
def rescue_action(e) raise end
|
24
|
+
end
|
25
|
+
|
26
|
+
class CaptureTest < ActionController::TestCase
|
27
|
+
tests CaptureController
|
28
|
+
|
29
|
+
def setup
|
30
|
+
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
|
31
|
+
# a more accurate simulation of what happens in "real life".
|
32
|
+
@controller.logger = Logger.new(nil)
|
33
|
+
|
34
|
+
@request.host = "www.nextangle.com"
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_simple_capture
|
38
|
+
get :capturing
|
39
|
+
assert_equal "Dreamy days", @response.body.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_content_for
|
43
|
+
get :content_for
|
44
|
+
assert_equal expected_content_for_output, @response.body
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_concatentate_content_for
|
48
|
+
get :content_for_concatenated
|
49
|
+
assert_equal expected_content_for_output, @response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_set_content_for_with_parameter
|
53
|
+
get :content_for_with_parameter
|
54
|
+
assert_equal expected_content_for_output, @response.body
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_non_erb_block_content_for
|
58
|
+
get :non_erb_block_content_for
|
59
|
+
assert_equal expected_content_for_output, @response.body
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def expected_content_for_output
|
64
|
+
"<title>Putting stuff in the title!</title>\n\nGreat stuff!"
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class ContentTypeController < ActionController::Base
|
4
|
+
def render_content_type_from_body
|
5
|
+
response.content_type = Mime::RSS
|
6
|
+
render :text => "hello world!"
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_defaults
|
10
|
+
render :text => "hello world!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_content_type_from_render
|
14
|
+
render :text => "hello world!", :content_type => Mime::RSS
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_charset_from_body
|
18
|
+
response.charset = "utf-16"
|
19
|
+
render :text => "hello world!"
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_nil_charset_from_body
|
23
|
+
response.charset = nil
|
24
|
+
render :text => "hello world!"
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_default_for_rhtml
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_default_for_rxml
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_default_for_rjs
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_change_for_rxml
|
37
|
+
response.content_type = Mime::HTML
|
38
|
+
render :action => "render_default_for_rxml"
|
39
|
+
end
|
40
|
+
|
41
|
+
def render_default_content_types_for_respond_to
|
42
|
+
respond_to do |format|
|
43
|
+
format.html { render :text => "hello world!" }
|
44
|
+
format.xml { render :action => "render_default_content_types_for_respond_to.rhtml" }
|
45
|
+
format.js { render :text => "hello world!" }
|
46
|
+
format.rss { render :text => "hello world!", :content_type => Mime::XML }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def rescue_action(e) raise end
|
51
|
+
end
|
52
|
+
|
53
|
+
class ContentTypeTest < ActionController::TestCase
|
54
|
+
tests ContentTypeController
|
55
|
+
|
56
|
+
def setup
|
57
|
+
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
|
58
|
+
# a more accurate simulation of what happens in "real life".
|
59
|
+
@controller.logger = Logger.new(nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_render_defaults
|
63
|
+
get :render_defaults
|
64
|
+
assert_equal "utf-8", @response.charset
|
65
|
+
assert_equal Mime::HTML, @response.content_type
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_render_changed_charset_default
|
69
|
+
ContentTypeController.default_charset = "utf-16"
|
70
|
+
get :render_defaults
|
71
|
+
assert_equal "utf-16", @response.charset
|
72
|
+
assert_equal Mime::HTML, @response.content_type
|
73
|
+
ContentTypeController.default_charset = "utf-8"
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_content_type_from_body
|
77
|
+
get :render_content_type_from_body
|
78
|
+
assert_equal "application/rss+xml", @response.content_type
|
79
|
+
assert_equal "utf-8", @response.charset
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_content_type_from_render
|
83
|
+
get :render_content_type_from_render
|
84
|
+
assert_equal "application/rss+xml", @response.content_type
|
85
|
+
assert_equal "utf-8", @response.charset
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_charset_from_body
|
89
|
+
get :render_charset_from_body
|
90
|
+
assert_equal Mime::HTML, @response.content_type
|
91
|
+
assert_equal "utf-16", @response.charset
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_nil_charset_from_body
|
95
|
+
get :render_nil_charset_from_body
|
96
|
+
assert_equal Mime::HTML, @response.content_type
|
97
|
+
assert_equal "utf-8", @response.charset, @response.headers.inspect
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_nil_default_for_rhtml
|
101
|
+
ContentTypeController.default_charset = nil
|
102
|
+
get :render_default_for_rhtml
|
103
|
+
assert_equal Mime::HTML, @response.content_type
|
104
|
+
assert_nil @response.charset, @response.headers.inspect
|
105
|
+
ensure
|
106
|
+
ContentTypeController.default_charset = "utf-8"
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_default_for_rhtml
|
110
|
+
get :render_default_for_rhtml
|
111
|
+
assert_equal Mime::HTML, @response.content_type
|
112
|
+
assert_equal "utf-8", @response.charset
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_default_for_rxml
|
116
|
+
get :render_default_for_rxml
|
117
|
+
assert_equal Mime::XML, @response.content_type
|
118
|
+
assert_equal "utf-8", @response.charset
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_default_for_rjs
|
122
|
+
xhr :post, :render_default_for_rjs
|
123
|
+
assert_equal Mime::JS, @response.content_type
|
124
|
+
assert_equal "utf-8", @response.charset
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_change_for_rxml
|
128
|
+
get :render_change_for_rxml
|
129
|
+
assert_equal Mime::HTML, @response.content_type
|
130
|
+
assert_equal "utf-8", @response.charset
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class AcceptBasedContentTypeTest < ActionController::TestCase
|
135
|
+
|
136
|
+
tests ContentTypeController
|
137
|
+
|
138
|
+
def setup
|
139
|
+
ActionController::Base.use_accept_header = true
|
140
|
+
end
|
141
|
+
|
142
|
+
def teardown
|
143
|
+
ActionController::Base.use_accept_header = false
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def test_render_default_content_types_for_respond_to
|
148
|
+
@request.accept = Mime::HTML.to_s
|
149
|
+
get :render_default_content_types_for_respond_to
|
150
|
+
assert_equal Mime::HTML, @response.content_type
|
151
|
+
|
152
|
+
@request.accept = Mime::JS.to_s
|
153
|
+
get :render_default_content_types_for_respond_to
|
154
|
+
assert_equal Mime::JS, @response.content_type
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_render_default_content_types_for_respond_to_with_template
|
158
|
+
@request.accept = Mime::XML.to_s
|
159
|
+
get :render_default_content_types_for_respond_to
|
160
|
+
assert_equal Mime::XML, @response.content_type
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_render_default_content_types_for_respond_to_with_overwrite
|
164
|
+
@request.accept = Mime::RSS.to_s
|
165
|
+
get :render_default_content_types_for_respond_to
|
166
|
+
assert_equal Mime::XML, @response.content_type
|
167
|
+
end
|
168
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class CookieTest < ActionController::TestCase
|
4
|
+
class TestController < ActionController::Base
|
5
|
+
def authenticate
|
6
|
+
cookies["user_name"] = "david"
|
7
|
+
end
|
8
|
+
|
9
|
+
def authenticate_for_fourteen_days
|
10
|
+
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate_for_fourteen_days_with_symbols
|
14
|
+
cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_multiple_cookies
|
18
|
+
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
|
19
|
+
cookies["login"] = "XJ-122"
|
20
|
+
end
|
21
|
+
|
22
|
+
def access_frozen_cookies
|
23
|
+
cookies["will"] = "work"
|
24
|
+
end
|
25
|
+
|
26
|
+
def logout
|
27
|
+
cookies.delete("user_name")
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_cookie_with_path
|
31
|
+
cookies.delete("user_name", :path => '/beaten')
|
32
|
+
render :text => "hello world"
|
33
|
+
end
|
34
|
+
|
35
|
+
def authenticate_with_http_only
|
36
|
+
cookies["user_name"] = { :value => "david", :httponly => true }
|
37
|
+
end
|
38
|
+
|
39
|
+
def rescue_action(e)
|
40
|
+
raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
tests TestController
|
45
|
+
|
46
|
+
def setup
|
47
|
+
@request.host = "www.nextangle.com"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_setting_cookie
|
51
|
+
get :authenticate
|
52
|
+
assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"]
|
53
|
+
assert_equal({"user_name" => "david"}, @response.cookies)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_setting_cookie_for_fourteen_days
|
57
|
+
get :authenticate_for_fourteen_days
|
58
|
+
assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
|
59
|
+
assert_equal({"user_name" => "david"}, @response.cookies)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_setting_cookie_for_fourteen_days_with_symbols
|
63
|
+
get :authenticate_for_fourteen_days_with_symbols
|
64
|
+
assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
|
65
|
+
assert_equal({"user_name" => "david"}, @response.cookies)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_setting_cookie_with_http_only
|
69
|
+
get :authenticate_with_http_only
|
70
|
+
assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"]
|
71
|
+
assert_equal({"user_name" => "david"}, @response.cookies)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_multiple_cookies
|
75
|
+
get :set_multiple_cookies
|
76
|
+
assert_equal 2, @response.cookies.size
|
77
|
+
assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"][0]
|
78
|
+
assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1]
|
79
|
+
assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_setting_test_cookie
|
83
|
+
assert_nothing_raised { get :access_frozen_cookies }
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_expiring_cookie
|
87
|
+
get :logout
|
88
|
+
assert_equal ["user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
|
89
|
+
assert_equal({"user_name" => nil}, @response.cookies)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_cookiejar_accessor
|
93
|
+
@request.cookies["user_name"] = "david"
|
94
|
+
@controller.request = @request
|
95
|
+
jar = ActionController::CookieJar.new(@controller)
|
96
|
+
assert_equal "david", jar["user_name"]
|
97
|
+
assert_equal nil, jar["something_else"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_cookiejar_accessor_with_array_value
|
101
|
+
@request.cookies["pages"] = %w{1 2 3}
|
102
|
+
@controller.request = @request
|
103
|
+
jar = ActionController::CookieJar.new(@controller)
|
104
|
+
assert_equal %w{1 2 3}, jar["pages"]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_delete_cookie_with_path
|
108
|
+
get :delete_cookie_with_path
|
109
|
+
assert_equal ["user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class DeprecatedBaseMethodsTest < ActionController::TestCase
|
4
|
+
class Target < ActionController::Base
|
5
|
+
def home_url(greeting)
|
6
|
+
"http://example.com/#{greeting}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def raises_name_error
|
10
|
+
this_method_doesnt_exist
|
11
|
+
end
|
12
|
+
|
13
|
+
def rescue_action(e) raise e end
|
14
|
+
end
|
15
|
+
|
16
|
+
tests Target
|
17
|
+
|
18
|
+
def test_log_error_silences_deprecation_warnings
|
19
|
+
get :raises_name_error
|
20
|
+
rescue => e
|
21
|
+
assert_not_deprecated { @controller.send :log_error, e }
|
22
|
+
end
|
23
|
+
|
24
|
+
if defined? Test::Unit::Error
|
25
|
+
def test_assertion_failed_error_silences_deprecation_warnings
|
26
|
+
get :raises_name_error
|
27
|
+
rescue => e
|
28
|
+
error = Test::Unit::Error.new('testing ur doodz', e)
|
29
|
+
assert_not_deprecated { error.message }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class DispatcherTest < Test::Unit::TestCase
|
4
|
+
Dispatcher = ActionController::Dispatcher
|
5
|
+
|
6
|
+
def setup
|
7
|
+
ENV['REQUEST_METHOD'] = 'GET'
|
8
|
+
|
9
|
+
Dispatcher.middleware = ActionController::MiddlewareStack.new do |middleware|
|
10
|
+
middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/middlewares.rb"))
|
11
|
+
middleware.instance_eval(File.read(middlewares))
|
12
|
+
end
|
13
|
+
|
14
|
+
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
|
15
|
+
Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
16
|
+
Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
17
|
+
Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
18
|
+
|
19
|
+
Dispatcher.stubs(:require_dependency)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
ENV.delete 'REQUEST_METHOD'
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_clears_dependencies_after_dispatch_if_in_loading_mode
|
27
|
+
ActiveSupport::Dependencies.expects(:clear).once
|
28
|
+
dispatch(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_reloads_routes_before_dispatch_if_in_loading_mode
|
32
|
+
ActionController::Routing::Routes.expects(:reload).once
|
33
|
+
dispatch(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
|
37
|
+
ActionController::Routing::Routes.expects(:reload).never
|
38
|
+
ActiveSupport::Dependencies.expects(:clear).never
|
39
|
+
|
40
|
+
dispatch
|
41
|
+
end
|
42
|
+
|
43
|
+
# Stub out dispatch error logger
|
44
|
+
class << Dispatcher
|
45
|
+
def log_failsafe_exception(status, exception); end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_failsafe_response
|
49
|
+
Dispatcher.any_instance.expects(:dispatch).raises('b00m')
|
50
|
+
ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
|
51
|
+
|
52
|
+
assert_nothing_raised do
|
53
|
+
assert_equal [
|
54
|
+
500,
|
55
|
+
{"Content-Type" => "text/html"},
|
56
|
+
"<html><body><h1>500 Internal Server Error</h1></body></html>"
|
57
|
+
], dispatch
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_prepare_callbacks
|
62
|
+
a = b = c = nil
|
63
|
+
Dispatcher.to_prepare { |*args| a = b = c = 1 }
|
64
|
+
Dispatcher.to_prepare { |*args| b = c = 2 }
|
65
|
+
Dispatcher.to_prepare { |*args| c = 3 }
|
66
|
+
|
67
|
+
# Ensure to_prepare callbacks are not run when defined
|
68
|
+
assert_nil a || b || c
|
69
|
+
|
70
|
+
# Run callbacks
|
71
|
+
Dispatcher.run_prepare_callbacks
|
72
|
+
|
73
|
+
assert_equal 1, a
|
74
|
+
assert_equal 2, b
|
75
|
+
assert_equal 3, c
|
76
|
+
|
77
|
+
# Make sure they are only run once
|
78
|
+
a = b = c = nil
|
79
|
+
dispatch
|
80
|
+
assert_nil a || b || c
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_to_prepare_with_identifier_replaces
|
84
|
+
a = b = nil
|
85
|
+
Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 }
|
86
|
+
Dispatcher.to_prepare(:unique_id) { |*args| a = 2 }
|
87
|
+
|
88
|
+
Dispatcher.run_prepare_callbacks
|
89
|
+
assert_equal 2, a
|
90
|
+
assert_equal nil, b
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def dispatch(cache_classes = true)
|
95
|
+
ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
|
96
|
+
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
97
|
+
Dispatcher.new.call({})
|
98
|
+
end
|
99
|
+
|
100
|
+
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
101
|
+
assert_equal howmany, klass.subclasses.size, message
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class << Object; alias_method :const_available?, :const_defined?; end
|
2
|
+
|
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
|
11
|
+
end
|
12
|
+
|
13
|
+
# For speed test
|
14
|
+
class SpeedController < ActionController::Base; end
|
15
|
+
class SearchController < SpeedController; end
|
16
|
+
class VideosController < SpeedController; end
|
17
|
+
class VideoFileController < SpeedController; end
|
18
|
+
class VideoSharesController < SpeedController; end
|
19
|
+
class VideoAbusesController < SpeedController; end
|
20
|
+
class VideoUploadsController < SpeedController; end
|
21
|
+
class VideoVisitsController < SpeedController; end
|
22
|
+
class UsersController < SpeedController; end
|
23
|
+
class SettingsController < SpeedController; end
|
24
|
+
class ChannelsController < SpeedController; end
|
25
|
+
class ChannelVideosController < SpeedController; end
|
26
|
+
class SessionsController < SpeedController; end
|
27
|
+
class LostPasswordsController < SpeedController; end
|
28
|
+
class PagesController < SpeedController; end
|
29
|
+
|
30
|
+
ActionController::Routing::Routes.draw do |map|
|
31
|
+
map.route_one 'route_one', :controller => 'elsewhere', :action => 'flash_me'
|
32
|
+
map.connect ':controller/:action/:id'
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Customer < Struct.new(:name, :id)
|
2
|
+
def to_param
|
3
|
+
id.to_s
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class BadCustomer < Customer
|
8
|
+
end
|
9
|
+
|
10
|
+
class GoodCustomer < Customer
|
11
|
+
end
|
12
|
+
|
13
|
+
module Quiz
|
14
|
+
class Question < Struct.new(:name, :id)
|
15
|
+
def to_param
|
16
|
+
id.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class FilterParamController < ActionController::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
class FilterParamTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@controller = FilterParamController.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_filter_parameters
|
12
|
+
assert FilterParamController.respond_to?(:filter_parameter_logging)
|
13
|
+
assert !@controller.respond_to?(:filter_parameters)
|
14
|
+
|
15
|
+
FilterParamController.filter_parameter_logging
|
16
|
+
assert @controller.respond_to?(:filter_parameters)
|
17
|
+
|
18
|
+
test_hashes = [[{},{},[]],
|
19
|
+
[{'foo'=>nil},{'foo'=>nil},[]],
|
20
|
+
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
|
21
|
+
[{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
|
22
|
+
[{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
|
23
|
+
[{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
|
24
|
+
[{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
|
25
|
+
[{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
|
26
|
+
[{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana']]
|
27
|
+
|
28
|
+
test_hashes.each do |before_filter, after_filter, filter_words|
|
29
|
+
FilterParamController.filter_parameter_logging(*filter_words)
|
30
|
+
assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
|
31
|
+
|
32
|
+
filter_words.push('blah')
|
33
|
+
FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
|
34
|
+
value.reverse! if key =~ /bargain/
|
35
|
+
end
|
36
|
+
|
37
|
+
before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
|
38
|
+
after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
|
39
|
+
|
40
|
+
assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_filter_parameters_is_protected
|
45
|
+
FilterParamController.filter_parameter_logging(:foo)
|
46
|
+
assert !FilterParamController.action_methods.include?('filter_parameters')
|
47
|
+
assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
|
48
|
+
end
|
49
|
+
end
|