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,26 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
# class TranslatingController < ActionController::Base
|
4
|
+
# end
|
5
|
+
|
6
|
+
class TranslationControllerTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@controller = ActionController::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_action_controller_base_responds_to_translate
|
12
|
+
assert @controller.respond_to?(:translate)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_action_controller_base_responds_to_t
|
16
|
+
assert @controller.respond_to?(:t)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_action_controller_base_responds_to_localize
|
20
|
+
assert @controller.respond_to?(:localize)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_action_controller_base_responds_to_l
|
24
|
+
assert @controller.respond_to?(:l)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,359 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
ActionController::UrlRewriter
|
4
|
+
|
5
|
+
class UrlRewriterTests < ActionController::TestCase
|
6
|
+
def setup
|
7
|
+
@request = ActionController::TestRequest.new
|
8
|
+
@params = {}
|
9
|
+
@rewriter = ActionController::UrlRewriter.new(@request, @params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_port
|
13
|
+
assert_equal('http://test.host:1271/c/a/i',
|
14
|
+
@rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_protocol_with_and_without_separator
|
19
|
+
assert_equal('https://test.host/c/a/i',
|
20
|
+
@rewriter.rewrite(:protocol => 'https', :controller => 'c', :action => 'a', :id => 'i')
|
21
|
+
)
|
22
|
+
|
23
|
+
assert_equal('https://test.host/c/a/i',
|
24
|
+
@rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i')
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_user_name_and_password
|
29
|
+
assert_equal(
|
30
|
+
'http://david:secret@test.host/c/a/i',
|
31
|
+
@rewriter.rewrite(:user => "david", :password => "secret", :controller => 'c', :action => 'a', :id => 'i')
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_user_name_and_password_with_escape_codes
|
36
|
+
assert_equal(
|
37
|
+
'http://openid.aol.com%2Fnextangler:one+two%3F@test.host/c/a/i',
|
38
|
+
@rewriter.rewrite(:user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i')
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_anchor
|
43
|
+
assert_equal(
|
44
|
+
'http://test.host/c/a/i#anchor',
|
45
|
+
@rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor')
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_overwrite_params
|
50
|
+
@params[:controller] = 'hi'
|
51
|
+
@params[:action] = 'bye'
|
52
|
+
@params[:id] = '2'
|
53
|
+
|
54
|
+
assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'})
|
55
|
+
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'})
|
56
|
+
assert_match %r(/hi/hi/2$), u
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_overwrite_removes_original
|
60
|
+
@params[:controller] = 'search'
|
61
|
+
@params[:action] = 'list'
|
62
|
+
@params[:list_page] = 1
|
63
|
+
|
64
|
+
assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2})
|
65
|
+
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
|
66
|
+
assert_equal 'http://test.host/search/list?list_page=2', u
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_to_str
|
70
|
+
@params[:controller] = 'hi'
|
71
|
+
@params[:action] = 'bye'
|
72
|
+
@request.parameters[:id] = '2'
|
73
|
+
|
74
|
+
assert_equal 'http://, test.host, /, hi, bye, {"id"=>"2"}', @rewriter.to_str
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_trailing_slash
|
78
|
+
options = {:controller => 'foo', :action => 'bar', :id => '3', :only_path => true}
|
79
|
+
assert_equal '/foo/bar/3', @rewriter.rewrite(options)
|
80
|
+
assert_equal '/foo/bar/3?query=string', @rewriter.rewrite(options.merge({:query => 'string'}))
|
81
|
+
options.update({:trailing_slash => true})
|
82
|
+
assert_equal '/foo/bar/3/', @rewriter.rewrite(options)
|
83
|
+
options.update({:query => 'string'})
|
84
|
+
assert_equal '/foo/bar/3/?query=string', @rewriter.rewrite(options)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class UrlWriterTests < ActionController::TestCase
|
89
|
+
class W
|
90
|
+
include ActionController::UrlWriter
|
91
|
+
end
|
92
|
+
|
93
|
+
def teardown
|
94
|
+
W.default_url_options.clear
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_host!
|
98
|
+
W.default_url_options[:host] = 'www.basecamphq.com'
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_exception_is_thrown_without_host
|
102
|
+
assert_raise RuntimeError do
|
103
|
+
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_anchor
|
108
|
+
assert_equal('/c/a#anchor',
|
109
|
+
W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor')
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_default_host
|
114
|
+
add_host!
|
115
|
+
assert_equal('http://www.basecamphq.com/c/a/i',
|
116
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i')
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_host_may_be_overridden
|
121
|
+
add_host!
|
122
|
+
assert_equal('http://37signals.basecamphq.com/c/a/i',
|
123
|
+
W.new.url_for(:host => '37signals.basecamphq.com', :controller => 'c', :action => 'a', :id => 'i')
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_port
|
128
|
+
add_host!
|
129
|
+
assert_equal('http://www.basecamphq.com:3000/c/a/i',
|
130
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :port => 3000)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_protocol
|
135
|
+
add_host!
|
136
|
+
assert_equal('https://www.basecamphq.com/c/a/i',
|
137
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_protocol_with_and_without_separator
|
142
|
+
add_host!
|
143
|
+
assert_equal('https://www.basecamphq.com/c/a/i',
|
144
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
145
|
+
)
|
146
|
+
assert_equal('https://www.basecamphq.com/c/a/i',
|
147
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://')
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_trailing_slash
|
152
|
+
add_host!
|
153
|
+
options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'}
|
154
|
+
assert_equal('http://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_trailing_slash_with_protocol
|
158
|
+
add_host!
|
159
|
+
options = { :trailing_slash => true,:protocol => 'https', :controller => 'foo', :action => 'bar', :id => '33'}
|
160
|
+
assert_equal('https://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
|
161
|
+
assert_equal 'https://www.basecamphq.com/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string'}))
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_trailing_slash_with_only_path
|
165
|
+
options = {:controller => 'foo', :trailing_slash => true}
|
166
|
+
assert_equal '/foo/', W.new.url_for(options.merge({:only_path => true}))
|
167
|
+
options.update({:action => 'bar', :id => '33'})
|
168
|
+
assert_equal '/foo/bar/33/', W.new.url_for(options.merge({:only_path => true}))
|
169
|
+
assert_equal '/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string',:only_path => true}))
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_trailing_slash_with_anchor
|
173
|
+
options = {:trailing_slash => true, :controller => 'foo', :action => 'bar', :id => '33', :only_path => true, :anchor=> 'chapter7'}
|
174
|
+
assert_equal '/foo/bar/33/#chapter7', W.new.url_for(options)
|
175
|
+
assert_equal '/foo/bar/33/?query=string#chapter7', W.new.url_for(options.merge({:query => 'string'}))
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_trailing_slash_with_params
|
179
|
+
url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => 'cont', :action => 'act', :p1 => 'cafe', :p2 => 'link')
|
180
|
+
params = extract_params(url)
|
181
|
+
assert_equal params[0], { :p1 => 'cafe' }.to_query
|
182
|
+
assert_equal params[1], { :p2 => 'link' }.to_query
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_relative_url_root_is_respected
|
186
|
+
orig_relative_url_root = ActionController::Base.relative_url_root
|
187
|
+
ActionController::Base.relative_url_root = '/subdir'
|
188
|
+
|
189
|
+
add_host!
|
190
|
+
assert_equal('https://www.basecamphq.com/subdir/c/a/i',
|
191
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
192
|
+
)
|
193
|
+
ensure
|
194
|
+
ActionController::Base.relative_url_root = orig_relative_url_root
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_named_routes
|
198
|
+
ActionController::Routing::Routes.draw do |map|
|
199
|
+
map.no_args '/this/is/verbose', :controller => 'home', :action => 'index'
|
200
|
+
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
201
|
+
map.connect ':controller/:action/:id'
|
202
|
+
end
|
203
|
+
|
204
|
+
# We need to create a new class in order to install the new named route.
|
205
|
+
kls = Class.new { include ActionController::UrlWriter }
|
206
|
+
controller = kls.new
|
207
|
+
assert controller.respond_to?(:home_url)
|
208
|
+
assert_equal 'http://www.basecamphq.com/home/sweet/home/again',
|
209
|
+
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
210
|
+
|
211
|
+
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
|
212
|
+
assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
|
213
|
+
assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
|
214
|
+
ensure
|
215
|
+
ActionController::Routing::Routes.load!
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_relative_url_root_is_respected_for_named_routes
|
219
|
+
orig_relative_url_root = ActionController::Base.relative_url_root
|
220
|
+
ActionController::Base.relative_url_root = '/subdir'
|
221
|
+
|
222
|
+
ActionController::Routing::Routes.draw do |map|
|
223
|
+
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
224
|
+
end
|
225
|
+
|
226
|
+
kls = Class.new { include ActionController::UrlWriter }
|
227
|
+
controller = kls.new
|
228
|
+
|
229
|
+
assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
|
230
|
+
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
231
|
+
ensure
|
232
|
+
ActionController::Routing::Routes.load!
|
233
|
+
ActionController::Base.relative_url_root = orig_relative_url_root
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_only_path
|
237
|
+
ActionController::Routing::Routes.draw do |map|
|
238
|
+
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
239
|
+
map.connect ':controller/:action/:id'
|
240
|
+
end
|
241
|
+
|
242
|
+
# We need to create a new class in order to install the new named route.
|
243
|
+
kls = Class.new { include ActionController::UrlWriter }
|
244
|
+
controller = kls.new
|
245
|
+
assert controller.respond_to?(:home_url)
|
246
|
+
assert_equal '/brave/new/world',
|
247
|
+
controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true)
|
248
|
+
|
249
|
+
assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
|
250
|
+
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
|
251
|
+
ensure
|
252
|
+
ActionController::Routing::Routes.load!
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_one_parameter
|
256
|
+
assert_equal('/c/a?param=val',
|
257
|
+
W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :param => 'val')
|
258
|
+
)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_two_parameters
|
262
|
+
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :p1 => 'X1', :p2 => 'Y2')
|
263
|
+
params = extract_params(url)
|
264
|
+
assert_equal params[0], { :p1 => 'X1' }.to_query
|
265
|
+
assert_equal params[1], { :p2 => 'Y2' }.to_query
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_hash_parameter
|
269
|
+
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:name => 'Bob', :category => 'prof'})
|
270
|
+
params = extract_params(url)
|
271
|
+
assert_equal params[0], { 'query[category]' => 'prof' }.to_query
|
272
|
+
assert_equal params[1], { 'query[name]' => 'Bob' }.to_query
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_array_parameter
|
276
|
+
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => ['Bob', 'prof'])
|
277
|
+
params = extract_params(url)
|
278
|
+
assert_equal params[0], { 'query[]' => 'Bob' }.to_query
|
279
|
+
assert_equal params[1], { 'query[]' => 'prof' }.to_query
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_hash_recursive_parameters
|
283
|
+
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:person => {:name => 'Bob', :position => 'prof'}, :hobby => 'piercing'})
|
284
|
+
params = extract_params(url)
|
285
|
+
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
|
286
|
+
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
|
287
|
+
assert_equal params[2], { 'query[person][position]' => 'prof' }.to_query
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_hash_recursive_and_array_parameters
|
291
|
+
url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
|
292
|
+
assert_match %r(^/c/a/101), url
|
293
|
+
params = extract_params(url)
|
294
|
+
assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
|
295
|
+
assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
|
296
|
+
assert_equal params[2], { 'query[person][position][]' => 'prof' }.to_query
|
297
|
+
assert_equal params[3], { 'query[person][position][]' => 'art director' }.to_query
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_path_generation_for_symbol_parameter_keys
|
301
|
+
assert_generates("/image", :controller=> :image)
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_named_routes_with_nil_keys
|
305
|
+
ActionController::Routing::Routes.clear!
|
306
|
+
ActionController::Routing::Routes.draw do |map|
|
307
|
+
map.main '', :controller => 'posts'
|
308
|
+
map.resources :posts
|
309
|
+
map.connect ':controller/:action/:id'
|
310
|
+
end
|
311
|
+
# We need to create a new class in order to install the new named route.
|
312
|
+
kls = Class.new { include ActionController::UrlWriter }
|
313
|
+
kls.default_url_options[:host] = 'www.basecamphq.com'
|
314
|
+
|
315
|
+
controller = kls.new
|
316
|
+
params = {:action => :index, :controller => :posts, :format => :xml}
|
317
|
+
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
|
318
|
+
params[:format] = nil
|
319
|
+
assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
|
320
|
+
ensure
|
321
|
+
ActionController::Routing::Routes.load!
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_formatted_url_methods_are_deprecated
|
325
|
+
ActionController::Routing::Routes.draw do |map|
|
326
|
+
map.resources :posts
|
327
|
+
end
|
328
|
+
# We need to create a new class in order to install the new named route.
|
329
|
+
kls = Class.new { include ActionController::UrlWriter }
|
330
|
+
controller = kls.new
|
331
|
+
params = {:id => 1, :format => :xml}
|
332
|
+
assert_deprecated do
|
333
|
+
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, params))
|
334
|
+
end
|
335
|
+
assert_deprecated do
|
336
|
+
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml))
|
337
|
+
end
|
338
|
+
ensure
|
339
|
+
ActionController::Routing::Routes.load!
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_multiple_includes_maintain_distinct_options
|
343
|
+
first_class = Class.new { include ActionController::UrlWriter }
|
344
|
+
second_class = Class.new { include ActionController::UrlWriter }
|
345
|
+
|
346
|
+
first_host, second_host = 'firsthost.com', 'secondhost.com'
|
347
|
+
|
348
|
+
first_class.default_url_options[:host] = first_host
|
349
|
+
second_class.default_url_options[:host] = second_host
|
350
|
+
|
351
|
+
assert_equal first_class.default_url_options[:host], first_host
|
352
|
+
assert_equal second_class.default_url_options[:host], second_host
|
353
|
+
end
|
354
|
+
|
355
|
+
private
|
356
|
+
def extract_params(url)
|
357
|
+
url.split('?', 2).last.split('&')
|
358
|
+
end
|
359
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class VerificationTest < ActionController::TestCase
|
4
|
+
class TestController < ActionController::Base
|
5
|
+
verify :only => :guarded_one, :params => "one",
|
6
|
+
:add_flash => { :error => 'unguarded' },
|
7
|
+
:redirect_to => { :action => "unguarded" }
|
8
|
+
|
9
|
+
verify :only => :guarded_two, :params => %w( one two ),
|
10
|
+
:redirect_to => { :action => "unguarded" }
|
11
|
+
|
12
|
+
verify :only => :guarded_with_flash, :params => "one",
|
13
|
+
:add_flash => { :notice => "prereqs failed" },
|
14
|
+
:redirect_to => { :action => "unguarded" }
|
15
|
+
|
16
|
+
verify :only => :guarded_in_session, :session => "one",
|
17
|
+
:redirect_to => { :action => "unguarded" }
|
18
|
+
|
19
|
+
verify :only => [:multi_one, :multi_two], :session => %w( one two ),
|
20
|
+
:redirect_to => { :action => "unguarded" }
|
21
|
+
|
22
|
+
verify :only => :guarded_by_method, :method => :post,
|
23
|
+
:redirect_to => { :action => "unguarded" }
|
24
|
+
|
25
|
+
verify :only => :guarded_by_xhr, :xhr => true,
|
26
|
+
:redirect_to => { :action => "unguarded" }
|
27
|
+
|
28
|
+
verify :only => :guarded_by_not_xhr, :xhr => false,
|
29
|
+
:redirect_to => { :action => "unguarded" }
|
30
|
+
|
31
|
+
before_filter :unconditional_redirect, :only => :two_redirects
|
32
|
+
verify :only => :two_redirects, :method => :post,
|
33
|
+
:redirect_to => { :action => "unguarded" }
|
34
|
+
|
35
|
+
verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
|
36
|
+
|
37
|
+
verify :only => :guarded_one_for_named_route_test, :params => "one",
|
38
|
+
:redirect_to => :foo_url
|
39
|
+
|
40
|
+
verify :only => :no_default_action, :params => "santa"
|
41
|
+
|
42
|
+
verify :only => :guarded_with_back, :method => :post,
|
43
|
+
:redirect_to => :back
|
44
|
+
|
45
|
+
def guarded_one
|
46
|
+
render :text => "#{params[:one]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def guarded_one_for_named_route_test
|
50
|
+
render :text => "#{params[:one]}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def guarded_with_flash
|
54
|
+
render :text => "#{params[:one]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def guarded_two
|
58
|
+
render :text => "#{params[:one]}:#{params[:two]}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def guarded_in_session
|
62
|
+
render :text => "#{session["one"]}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def multi_one
|
66
|
+
render :text => "#{session["one"]}:#{session["two"]}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def multi_two
|
70
|
+
render :text => "#{session["two"]}:#{session["one"]}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def guarded_by_method
|
74
|
+
render :text => "#{request.method}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def guarded_by_xhr
|
78
|
+
render :text => "#{request.xhr?}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def guarded_by_not_xhr
|
82
|
+
render :text => "#{request.xhr?}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def unguarded
|
86
|
+
render :text => "#{params[:one]}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def two_redirects
|
90
|
+
render :nothing => true
|
91
|
+
end
|
92
|
+
|
93
|
+
def must_be_post
|
94
|
+
render :text => "Was a post!"
|
95
|
+
end
|
96
|
+
|
97
|
+
def guarded_with_back
|
98
|
+
render :text => "#{params[:one]}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def no_default_action
|
102
|
+
# Will never run
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
def rescue_action(e) raise end
|
107
|
+
|
108
|
+
def unconditional_redirect
|
109
|
+
redirect_to :action => "unguarded"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def setup
|
114
|
+
@controller = TestController.new
|
115
|
+
@request = ActionController::TestRequest.new
|
116
|
+
@response = ActionController::TestResponse.new
|
117
|
+
ActionController::Routing::Routes.add_named_route :foo, '/foo', :controller => 'test', :action => 'foo'
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_using_symbol_back_with_no_referrer
|
121
|
+
assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_using_symbol_back_redirects_to_referrer
|
125
|
+
@request.env["HTTP_REFERER"] = "/foo"
|
126
|
+
get :guarded_with_back
|
127
|
+
assert_redirected_to '/foo'
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_no_deprecation_warning_for_named_route
|
131
|
+
assert_not_deprecated do
|
132
|
+
get :guarded_one_for_named_route_test, :two => "not one"
|
133
|
+
assert_redirected_to '/foo'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_guarded_one_with_prereqs
|
138
|
+
get :guarded_one, :one => "here"
|
139
|
+
assert_equal "here", @response.body
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_guarded_one_without_prereqs
|
143
|
+
get :guarded_one
|
144
|
+
assert_redirected_to :action => "unguarded"
|
145
|
+
assert_equal 'unguarded', flash[:error]
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_guarded_with_flash_with_prereqs
|
149
|
+
get :guarded_with_flash, :one => "here"
|
150
|
+
assert_equal "here", @response.body
|
151
|
+
assert flash.empty?
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_guarded_with_flash_without_prereqs
|
155
|
+
get :guarded_with_flash
|
156
|
+
assert_redirected_to :action => "unguarded"
|
157
|
+
assert_equal "prereqs failed", flash[:notice]
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_guarded_two_with_prereqs
|
161
|
+
get :guarded_two, :one => "here", :two => "there"
|
162
|
+
assert_equal "here:there", @response.body
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_guarded_two_without_prereqs_one
|
166
|
+
get :guarded_two, :two => "there"
|
167
|
+
assert_redirected_to :action => "unguarded"
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_guarded_two_without_prereqs_two
|
171
|
+
get :guarded_two, :one => "here"
|
172
|
+
assert_redirected_to :action => "unguarded"
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_guarded_two_without_prereqs_both
|
176
|
+
get :guarded_two
|
177
|
+
assert_redirected_to :action => "unguarded"
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_unguarded_with_params
|
181
|
+
get :unguarded, :one => "here"
|
182
|
+
assert_equal "here", @response.body
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_unguarded_without_params
|
186
|
+
get :unguarded
|
187
|
+
assert_equal "", @response.body
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_guarded_in_session_with_prereqs
|
191
|
+
get :guarded_in_session, {}, "one" => "here"
|
192
|
+
assert_equal "here", @response.body
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_guarded_in_session_without_prereqs
|
196
|
+
get :guarded_in_session
|
197
|
+
assert_redirected_to :action => "unguarded"
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_multi_one_with_prereqs
|
201
|
+
get :multi_one, {}, "one" => "here", "two" => "there"
|
202
|
+
assert_equal "here:there", @response.body
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_multi_one_without_prereqs
|
206
|
+
get :multi_one
|
207
|
+
assert_redirected_to :action => "unguarded"
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_multi_two_with_prereqs
|
211
|
+
get :multi_two, {}, "one" => "here", "two" => "there"
|
212
|
+
assert_equal "there:here", @response.body
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_multi_two_without_prereqs
|
216
|
+
get :multi_two
|
217
|
+
assert_redirected_to :action => "unguarded"
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_guarded_by_method_with_prereqs
|
221
|
+
post :guarded_by_method
|
222
|
+
assert_equal "post", @response.body
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_guarded_by_method_without_prereqs
|
226
|
+
get :guarded_by_method
|
227
|
+
assert_redirected_to :action => "unguarded"
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_guarded_by_xhr_with_prereqs
|
231
|
+
xhr :post, :guarded_by_xhr
|
232
|
+
assert_equal "true", @response.body
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_guarded_by_xhr_without_prereqs
|
236
|
+
get :guarded_by_xhr
|
237
|
+
assert_redirected_to :action => "unguarded"
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_guarded_by_not_xhr_with_prereqs
|
241
|
+
get :guarded_by_not_xhr
|
242
|
+
assert_equal "false", @response.body
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_guarded_by_not_xhr_without_prereqs
|
246
|
+
xhr :post, :guarded_by_not_xhr
|
247
|
+
assert_redirected_to :action => "unguarded"
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_guarded_post_and_calls_render_succeeds
|
251
|
+
post :must_be_post
|
252
|
+
assert_equal "Was a post!", @response.body
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_default_failure_should_be_a_bad_request
|
256
|
+
post :no_default_action
|
257
|
+
assert_response :bad_request
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_guarded_post_and_calls_render_fails_and_sets_allow_header
|
261
|
+
get :must_be_post
|
262
|
+
assert_response 405
|
263
|
+
assert_equal "Must be post", @response.body
|
264
|
+
assert_equal "POST", @response.headers["Allow"]
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_second_redirect
|
268
|
+
assert_nothing_raised { get :two_redirects }
|
269
|
+
end
|
270
|
+
end
|