actionpack 2.0.2 → 2.0.4
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 +45 -0
- data/Rakefile +5 -3
- data/lib/action_controller.rb +0 -0
- data/lib/action_controller/assertions/response_assertions.rb +6 -2
- data/lib/action_controller/assertions/routing_assertions.rb +5 -2
- data/lib/action_controller/base.rb +4 -3
- data/lib/action_controller/cgi_ext/cookie.rb +1 -1
- data/lib/action_controller/filters.rb +5 -3
- data/lib/action_controller/http_authentication.rb +2 -4
- data/lib/action_controller/integration.rb +3 -2
- data/lib/action_controller/layout.rb +14 -15
- data/lib/action_controller/mime_type.rb +4 -1
- data/lib/action_controller/polymorphic_routes.rb +90 -15
- data/lib/action_controller/record_identifier.rb +4 -4
- data/lib/action_controller/request.rb +29 -14
- data/lib/action_controller/request_forgery_protection.rb +41 -34
- data/lib/action_controller/request_profiler.rb +16 -6
- data/lib/action_controller/response.rb +0 -0
- data/lib/action_controller/routing.rb +3 -3
- data/lib/action_controller/session/active_record_store.rb +7 -8
- data/lib/action_controller/session/cookie_store.rb +2 -3
- data/lib/action_controller/templates/rescues/_trace.erb +5 -5
- data/lib/action_controller/test_case.rb +24 -4
- data/lib/action_controller/test_process.rb +3 -3
- data/lib/action_controller/url_rewriter.rb +29 -28
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +2 -2
- data/lib/action_controller/verification.rb +73 -57
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view/base.rb +24 -6
- data/lib/action_view/helpers/active_record_helper.rb +1 -1
- data/lib/action_view/helpers/asset_tag_helper.rb +12 -6
- data/lib/action_view/helpers/atom_feed_helper.rb +21 -17
- data/lib/action_view/helpers/date_helper.rb +6 -6
- data/lib/action_view/helpers/form_helper.rb +3 -2
- data/lib/action_view/helpers/form_options_helper.rb +12 -1
- data/lib/action_view/helpers/form_tag_helper.rb +18 -0
- data/lib/action_view/helpers/number_helper.rb +1 -1
- data/lib/action_view/helpers/prototype_helper.rb +1 -1
- data/lib/action_view/helpers/text_helper.rb +1 -1
- data/lib/action_view/helpers/url_helper.rb +5 -9
- data/lib/action_view/template_error.rb +11 -4
- data/test/activerecord/active_record_store_test.rb +1 -1
- data/test/activerecord/fixtures_test.rb +24 -0
- data/test/controller/action_pack_assertions_test.rb +37 -2
- data/test/controller/base_test.rb +4 -1
- data/test/controller/cgi_test.rb +4 -3
- data/test/controller/filters_test.rb +4 -7
- data/test/controller/html-scanner/sanitizer_test.rb +7 -1
- data/test/controller/integration_test.rb +0 -1
- data/test/controller/mime_type_test.rb +5 -0
- data/test/controller/new_render_test.rb +25 -2
- data/test/controller/polymorphic_routes_test.rb +106 -75
- data/test/controller/redirect_test.rb +11 -0
- data/test/controller/render_test.rb +19 -0
- data/test/controller/request_forgery_protection_test.rb +9 -0
- data/test/controller/request_test.rb +33 -5
- data/test/controller/routing_test.rb +4 -4
- data/test/controller/session/cookie_store_test.rb +0 -0
- data/test/controller/test_test.rb +43 -1
- data/test/controller/url_rewriter_test.rb +34 -4
- data/test/fixtures/layouts/block_with_layout.erb +3 -0
- data/test/fixtures/layouts/partial_with_layout.erb +3 -0
- data/test/template/asset_tag_helper_test.rb +17 -13
- data/test/template/atom_feed_helper_test.rb +52 -2
- data/test/template/compiled_templates_test.rb +5 -1
- data/test/template/date_helper_test.rb +1 -1
- data/test/template/deprecate_ivars_test.rb +51 -0
- data/test/template/form_options_helper_test.rb +29 -0
- data/test/template/form_tag_helper_test.rb +18 -0
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/text_helper_test.rb +32 -14
- data/test/template/url_helper_test.rb +1 -1
- data/test/testing_sandbox.rb +8 -4
- metadata +9 -4
@@ -77,6 +77,10 @@ class RedirectController < ActionController::Base
|
|
77
77
|
redirect_to Workshop.new(5, true)
|
78
78
|
end
|
79
79
|
|
80
|
+
def redirect_to_nil
|
81
|
+
redirect_to nil
|
82
|
+
end
|
83
|
+
|
80
84
|
def rescue_errors(e) raise e end
|
81
85
|
|
82
86
|
def rescue_action(e) raise end
|
@@ -215,6 +219,13 @@ class RedirectTest < Test::Unit::TestCase
|
|
215
219
|
get :redirect_to_new_record
|
216
220
|
assert_equal "http://test.host/workshops", redirect_to_url
|
217
221
|
end
|
222
|
+
|
223
|
+
def test_redirect_to_nil
|
224
|
+
assert_raises(ActionController::ActionControllerError) do
|
225
|
+
get :redirect_to_nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
218
229
|
end
|
219
230
|
|
220
231
|
module ModuleTest
|
@@ -57,6 +57,14 @@ class TestController < ActionController::Base
|
|
57
57
|
render :text => "hello world", :status => 404
|
58
58
|
end
|
59
59
|
|
60
|
+
def render_text_with_nil
|
61
|
+
render :text => nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_text_with_false
|
65
|
+
render :text => false
|
66
|
+
end
|
67
|
+
|
60
68
|
def render_nothing_with_appendix
|
61
69
|
render :text => "appended"
|
62
70
|
end
|
@@ -263,6 +271,17 @@ class RenderTest < Test::Unit::TestCase
|
|
263
271
|
assert_equal 'hello world', @response.body
|
264
272
|
end
|
265
273
|
|
274
|
+
def test_render_text_with_nil
|
275
|
+
get :render_text_with_nil
|
276
|
+
assert_response 200
|
277
|
+
assert_equal '', @response.body
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_render_text_with_false
|
281
|
+
get :render_text_with_false
|
282
|
+
assert_equal 'false', @response.body
|
283
|
+
end
|
284
|
+
|
266
285
|
def test_render_nothing_with_appendix
|
267
286
|
get :render_nothing_with_appendix
|
268
287
|
assert_response 200
|
@@ -22,6 +22,10 @@ module RequestForgeryProtectionActions
|
|
22
22
|
render :inline => "<%= button_to('New', '/') {} %>"
|
23
23
|
end
|
24
24
|
|
25
|
+
def remote_form
|
26
|
+
render :inline => "<% form_remote_tag(:url => '/') {} %>"
|
27
|
+
end
|
28
|
+
|
25
29
|
def unsafe
|
26
30
|
render :text => 'pwn'
|
27
31
|
end
|
@@ -75,6 +79,11 @@ module RequestForgeryProtectionTests
|
|
75
79
|
assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
|
76
80
|
end
|
77
81
|
|
82
|
+
def test_should_render_remote_form_with_only_one_token_parameter
|
83
|
+
get :remote_form
|
84
|
+
assert_equal 1, @response.body.scan(@token).size
|
85
|
+
end
|
86
|
+
|
78
87
|
def test_should_allow_get
|
79
88
|
get :index
|
80
89
|
assert_response :success
|
@@ -13,9 +13,17 @@ class RequestTest < Test::Unit::TestCase
|
|
13
13
|
assert_equal '1.2.3.4', @request.remote_ip
|
14
14
|
|
15
15
|
@request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
|
16
|
+
assert_equal '1.2.3.4', @request.remote_ip
|
17
|
+
|
18
|
+
@request.remote_addr = '192.168.0.1'
|
16
19
|
assert_equal '2.3.4.5', @request.remote_ip
|
17
20
|
@request.env.delete 'HTTP_CLIENT_IP'
|
18
21
|
|
22
|
+
@request.remote_addr = '1.2.3.4'
|
23
|
+
@request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
|
24
|
+
assert_equal '1.2.3.4', @request.remote_ip
|
25
|
+
|
26
|
+
@request.remote_addr = '127.0.0.1'
|
19
27
|
@request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
|
20
28
|
assert_equal '3.4.5.6', @request.remote_ip
|
21
29
|
|
@@ -35,10 +43,23 @@ class RequestTest < Test::Unit::TestCase
|
|
35
43
|
assert_equal '3.4.5.6', @request.remote_ip
|
36
44
|
|
37
45
|
@request.env['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,3.4.5.6'
|
38
|
-
assert_equal '
|
46
|
+
assert_equal '3.4.5.6', @request.remote_ip
|
39
47
|
|
40
48
|
@request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
|
41
|
-
assert_equal '
|
49
|
+
assert_equal 'unknown', @request.remote_ip
|
50
|
+
|
51
|
+
@request.env['HTTP_X_FORWARDED_FOR'] = '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
|
52
|
+
assert_equal '3.4.5.6', @request.remote_ip
|
53
|
+
|
54
|
+
@request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
|
55
|
+
e = assert_raises(ActionController::ActionControllerError) {
|
56
|
+
@request.remote_ip
|
57
|
+
}
|
58
|
+
assert_match /IP spoofing attack/, e.message
|
59
|
+
assert_match /HTTP_X_FORWARDED_FOR="9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4"/, e.message
|
60
|
+
assert_match /HTTP_CLIENT_IP="8.8.8.8"/, e.message
|
61
|
+
|
62
|
+
@request.env.delete 'HTTP_CLIENT_IP'
|
42
63
|
@request.env.delete 'HTTP_X_FORWARDED_FOR'
|
43
64
|
end
|
44
65
|
|
@@ -371,6 +392,13 @@ class RequestTest < Test::Unit::TestCase
|
|
371
392
|
assert_equal Mime::HTML, @request.content_type
|
372
393
|
end
|
373
394
|
|
395
|
+
def test_format_assignment_should_set_format
|
396
|
+
@request.instance_eval { self.format = :txt }
|
397
|
+
assert !@request.format.xml?
|
398
|
+
@request.instance_eval { self.format = :xml }
|
399
|
+
assert @request.format.xml?
|
400
|
+
end
|
401
|
+
|
374
402
|
def test_content_no_type
|
375
403
|
assert_equal nil, @request.content_type
|
376
404
|
end
|
@@ -789,7 +817,7 @@ end
|
|
789
817
|
|
790
818
|
class XmlParamsParsingTest < Test::Unit::TestCase
|
791
819
|
def test_single_file
|
792
|
-
person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar></person>")
|
820
|
+
person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>")
|
793
821
|
|
794
822
|
assert_equal "image/jpg", person['person']['avatar'].content_type
|
795
823
|
assert_equal "me.jpg", person['person']['avatar'].original_filename
|
@@ -801,8 +829,8 @@ class XmlParamsParsingTest < Test::Unit::TestCase
|
|
801
829
|
<person>
|
802
830
|
<name>David</name>
|
803
831
|
<avatars>
|
804
|
-
<avatar type='file' name='me.jpg' content_type='image/jpg'>#{Base64.encode64('ABC')}</avatar>
|
805
|
-
<avatar type='file' name='you.gif' content_type='image/gif'>#{Base64.encode64('DEF')}</avatar>
|
832
|
+
<avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar>
|
833
|
+
<avatar type='file' name='you.gif' content_type='image/gif'>#{ActiveSupport::Base64.encode64('DEF')}</avatar>
|
806
834
|
</avatars>
|
807
835
|
</person>
|
808
836
|
end_body
|
@@ -2119,15 +2119,15 @@ class RoutingTest < Test::Unit::TestCase
|
|
2119
2119
|
end
|
2120
2120
|
|
2121
2121
|
def test_normalize_unix_paths
|
2122
|
-
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models)
|
2122
|
+
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config)
|
2123
2123
|
paths = ActionController::Routing.normalize_paths(load_paths)
|
2124
|
-
assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models lib .), paths
|
2124
|
+
assert_equal %w(vendor/rails/railties/builtin/rails_info vendor/rails/actionpack/lib app/controllers app/helpers app/models config .bar lib .), paths
|
2125
2125
|
end
|
2126
2126
|
|
2127
2127
|
def test_normalize_windows_paths
|
2128
|
-
load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models)
|
2128
|
+
load_paths = %w(. config\\..\\app\\controllers config\\..\\app\\\\helpers script\\..\\config\\..\\vendor\\rails\\actionpack\\lib vendor\\rails\\railties\\builtin\\rails_info app\\models lib script\\..\\config\\..\\foo\\bar\\..\\..\\app\\models .foo\\..\\.bar foo.bar\\..\\config)
|
2129
2129
|
paths = ActionController::Routing.normalize_paths(load_paths)
|
2130
|
-
assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models lib .), paths
|
2130
|
+
assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models config .bar lib .), paths
|
2131
2131
|
end
|
2132
2132
|
|
2133
2133
|
def test_routing_helper_module
|
File without changes
|
@@ -4,11 +4,21 @@ require "action_controller/test_case"
|
|
4
4
|
|
5
5
|
class TestTest < Test::Unit::TestCase
|
6
6
|
class TestController < ActionController::Base
|
7
|
+
def no_op
|
8
|
+
render :text => 'dummy'
|
9
|
+
end
|
10
|
+
|
7
11
|
def set_flash
|
8
12
|
flash["test"] = ">#{flash["test"]}<"
|
9
13
|
render :text => 'ignore me'
|
10
14
|
end
|
11
15
|
|
16
|
+
def set_session
|
17
|
+
session['string'] = 'A wonder'
|
18
|
+
session[:symbol] = 'it works'
|
19
|
+
render :text => 'Success'
|
20
|
+
end
|
21
|
+
|
12
22
|
def render_raw_post
|
13
23
|
raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank?
|
14
24
|
render :text => request.raw_post
|
@@ -136,6 +146,22 @@ XML
|
|
136
146
|
assert_equal '>value<', flash['test']
|
137
147
|
end
|
138
148
|
|
149
|
+
def test_process_with_session
|
150
|
+
process :set_session
|
151
|
+
assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
|
152
|
+
assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
|
153
|
+
assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
|
154
|
+
assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_process_with_session_arg
|
158
|
+
process :no_op, nil, { 'string' => 'value1', :symbol => 'value2' }
|
159
|
+
assert_equal 'value1', session['string']
|
160
|
+
assert_equal 'value1', session[:string]
|
161
|
+
assert_equal 'value2', session['symbol']
|
162
|
+
assert_equal 'value2', session[:symbol]
|
163
|
+
end
|
164
|
+
|
139
165
|
def test_process_with_request_uri_with_no_params
|
140
166
|
process :test_uri
|
141
167
|
assert_equal "/test_test/test/test_uri", @response.body
|
@@ -375,6 +401,13 @@ XML
|
|
375
401
|
assert_routing 'content', :controller => 'content', :action => 'index'
|
376
402
|
end
|
377
403
|
|
404
|
+
def test_assert_routing_with_method
|
405
|
+
with_routing do |set|
|
406
|
+
set.draw { |map| map.resources(:content) }
|
407
|
+
assert_routing({ :method => 'post', :path => 'content' }, { :controller => 'content', :action => 'create' })
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
378
411
|
def test_assert_routing_in_module
|
379
412
|
assert_routing 'admin/user', :controller => 'admin/user', :action => 'index'
|
380
413
|
end
|
@@ -614,10 +647,19 @@ class InferringClassNameTest < Test::Unit::TestCase
|
|
614
647
|
end
|
615
648
|
end
|
616
649
|
|
650
|
+
class ContentControllerTest < ActionController::TestCase
|
651
|
+
def setup
|
652
|
+
# Should not override ActionController setup methods
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_should_still_setup_controller
|
656
|
+
assert_kind_of(ContentController, @controller)
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
617
660
|
class CrazyNameTest < ActionController::TestCase
|
618
661
|
tests ContentController
|
619
662
|
def test_controller_class_can_be_set_manually_not_just_inferred
|
620
663
|
assert_equal ContentController, self.class.controller_class
|
621
664
|
end
|
622
665
|
end
|
623
|
-
|
@@ -149,27 +149,57 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
149
149
|
)
|
150
150
|
end
|
151
151
|
|
152
|
-
def
|
152
|
+
def test_relative_url_root_is_respected
|
153
|
+
orig_relative_url_root = ActionController::AbstractRequest.relative_url_root
|
154
|
+
ActionController::AbstractRequest.relative_url_root = '/subdir'
|
155
|
+
|
156
|
+
add_host!
|
157
|
+
assert_equal('https://www.basecamphq.com/subdir/c/a/i',
|
158
|
+
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
159
|
+
)
|
160
|
+
ensure
|
161
|
+
ActionController::AbstractRequest.relative_url_root = orig_relative_url_root
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_named_routes
|
153
165
|
ActionController::Routing::Routes.draw do |map|
|
154
166
|
map.no_args '/this/is/verbose', :controller => 'home', :action => 'index'
|
155
167
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
156
168
|
map.connect ':controller/:action/:id'
|
157
169
|
end
|
158
|
-
|
170
|
+
|
159
171
|
# We need to create a new class in order to install the new named route.
|
160
172
|
kls = Class.new { include ActionController::UrlWriter }
|
161
173
|
controller = kls.new
|
162
174
|
assert controller.respond_to?(:home_url)
|
163
175
|
assert_equal 'http://www.basecamphq.com/home/sweet/home/again',
|
164
176
|
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
165
|
-
|
177
|
+
|
166
178
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
|
167
179
|
assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
|
168
180
|
assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
|
169
181
|
ensure
|
170
182
|
ActionController::Routing::Routes.load!
|
171
183
|
end
|
172
|
-
|
184
|
+
|
185
|
+
def test_relative_url_root_is_respected_for_named_routes
|
186
|
+
orig_relative_url_root = ActionController::AbstractRequest.relative_url_root
|
187
|
+
ActionController::AbstractRequest.relative_url_root = '/subdir'
|
188
|
+
|
189
|
+
ActionController::Routing::Routes.draw do |map|
|
190
|
+
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
191
|
+
end
|
192
|
+
|
193
|
+
kls = Class.new { include ActionController::UrlWriter }
|
194
|
+
controller = kls.new
|
195
|
+
|
196
|
+
assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
|
197
|
+
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
198
|
+
ensure
|
199
|
+
ActionController::Routing::Routes.load!
|
200
|
+
ActionController::AbstractRequest.relative_url_root = orig_relative_url_root
|
201
|
+
end
|
202
|
+
|
173
203
|
def test_only_path
|
174
204
|
ActionController::Routing::Routes.draw do |map|
|
175
205
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
@@ -46,7 +46,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
46
46
|
def teardown
|
47
47
|
ActionController::Base.perform_caching = false
|
48
48
|
ActionController::Base.asset_host = nil
|
49
|
-
ENV
|
49
|
+
ENV.delete('RAILS_ASSET_ID')
|
50
50
|
end
|
51
51
|
|
52
52
|
AutoDiscoveryToTag = {
|
@@ -225,7 +225,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
225
225
|
|
226
226
|
def test_caching_javascript_include_tag_when_caching_on
|
227
227
|
ENV["RAILS_ASSET_ID"] = ""
|
228
|
-
ActionController::Base.asset_host = 'http://
|
228
|
+
ActionController::Base.asset_host = 'http://a0.example.com'
|
229
229
|
ActionController::Base.perform_caching = true
|
230
230
|
|
231
231
|
assert_dom_equal(
|
@@ -236,15 +236,15 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
236
236
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
|
237
237
|
|
238
238
|
assert_dom_equal(
|
239
|
-
%(<script src="http://
|
239
|
+
%(<script src="http://a0.example.com/javascripts/money.js" type="text/javascript"></script>),
|
240
240
|
javascript_include_tag(:all, :cache => "money")
|
241
241
|
)
|
242
242
|
|
243
243
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
|
244
244
|
|
245
245
|
ensure
|
246
|
-
|
247
|
-
|
246
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
|
247
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
|
248
248
|
end
|
249
249
|
|
250
250
|
def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host
|
@@ -261,7 +261,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
261
261
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
|
262
262
|
|
263
263
|
ensure
|
264
|
-
|
264
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
|
265
265
|
end
|
266
266
|
|
267
267
|
def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
|
@@ -276,7 +276,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
276
276
|
|
277
277
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
|
278
278
|
ensure
|
279
|
-
|
279
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
|
280
280
|
end
|
281
281
|
|
282
282
|
def test_caching_javascript_include_tag_when_caching_off
|
@@ -300,25 +300,25 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
300
300
|
|
301
301
|
def test_caching_stylesheet_link_tag_when_caching_on
|
302
302
|
ENV["RAILS_ASSET_ID"] = ""
|
303
|
-
ActionController::Base.asset_host = 'http://
|
303
|
+
ActionController::Base.asset_host = 'http://a0.example.com'
|
304
304
|
ActionController::Base.perform_caching = true
|
305
305
|
|
306
306
|
assert_dom_equal(
|
307
|
-
%(<link href="http://
|
307
|
+
%(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
|
308
308
|
stylesheet_link_tag(:all, :cache => true)
|
309
309
|
)
|
310
310
|
|
311
311
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
|
312
312
|
|
313
313
|
assert_dom_equal(
|
314
|
-
%(<link href="http://
|
314
|
+
%(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
|
315
315
|
stylesheet_link_tag(:all, :cache => "money")
|
316
316
|
)
|
317
317
|
|
318
318
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
|
319
319
|
ensure
|
320
|
-
|
321
|
-
|
320
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
|
321
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
|
322
322
|
end
|
323
323
|
|
324
324
|
def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
|
@@ -335,7 +335,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
335
335
|
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
|
336
336
|
|
337
337
|
ensure
|
338
|
-
|
338
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
|
339
339
|
end
|
340
340
|
|
341
341
|
def test_caching_stylesheet_include_tag_when_caching_off
|
@@ -392,6 +392,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
392
392
|
assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
393
393
|
assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
394
394
|
assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
395
|
+
assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
|
396
|
+
assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
|
395
397
|
end
|
396
398
|
|
397
399
|
def test_should_ignore_relative_root_path_on_complete_url
|
@@ -404,6 +406,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
404
406
|
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
|
405
407
|
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
|
406
408
|
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
|
409
|
+
assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
|
410
|
+
assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse2.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
|
407
411
|
ensure
|
408
412
|
ActionController::Base.asset_host = ""
|
409
413
|
end
|
@@ -5,7 +5,7 @@ Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
|
|
5
5
|
class ScrollsController < ActionController::Base
|
6
6
|
FEEDS = {}
|
7
7
|
FEEDS["defaults"] = <<-EOT
|
8
|
-
atom_feed do |feed|
|
8
|
+
atom_feed(:schema_date => '2008') do |feed|
|
9
9
|
feed.title("My great blog!")
|
10
10
|
feed.updated((@scrolls.first.created_at))
|
11
11
|
|
@@ -38,7 +38,23 @@ class ScrollsController < ActionController::Base
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
EOT
|
41
|
+
FEEDS["xml_block"] = <<-EOT
|
42
|
+
atom_feed do |feed|
|
43
|
+
feed.title("My great blog!")
|
44
|
+
feed.updated((@scrolls.first.created_at))
|
41
45
|
|
46
|
+
feed.author do |author|
|
47
|
+
author.name("DHH")
|
48
|
+
end
|
49
|
+
|
50
|
+
for scroll in @scrolls
|
51
|
+
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
|
52
|
+
entry.title(scroll.title)
|
53
|
+
entry.content(scroll.body, :type => 'html')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
EOT
|
42
58
|
def index
|
43
59
|
@scrolls = [
|
44
60
|
Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
|
@@ -47,6 +63,12 @@ class ScrollsController < ActionController::Base
|
|
47
63
|
|
48
64
|
render :inline => FEEDS[params[:id]], :type => :builder
|
49
65
|
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def rescue_action(e)
|
70
|
+
raise(e)
|
71
|
+
end
|
50
72
|
end
|
51
73
|
|
52
74
|
class AtomFeedTest < Test::Unit::TestCase
|
@@ -88,6 +110,34 @@ class AtomFeedTest < Test::Unit::TestCase
|
|
88
110
|
end
|
89
111
|
end
|
90
112
|
|
113
|
+
def test_self_url_should_default_to_current_request_url
|
114
|
+
with_restful_routing(:scrolls) do
|
115
|
+
get :index, :id => "defaults"
|
116
|
+
assert_select "link[rel=self][href=http://www.nextangle.com/scrolls?id=defaults]"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_feed_id_should_be_a_valid_tag
|
121
|
+
with_restful_routing(:scrolls) do
|
122
|
+
get :index, :id => "defaults"
|
123
|
+
assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_entry_id_should_be_a_valid_tag
|
128
|
+
with_restful_routing(:scrolls) do
|
129
|
+
get :index, :id => "defaults"
|
130
|
+
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1"
|
131
|
+
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_feed_should_allow_nested_xml_blocks
|
136
|
+
with_restful_routing(:scrolls) do
|
137
|
+
get :index, :id => "xml_block"
|
138
|
+
assert_select "author name", :text => "DHH"
|
139
|
+
end
|
140
|
+
end
|
91
141
|
|
92
142
|
private
|
93
143
|
def with_restful_routing(resources)
|
@@ -98,4 +148,4 @@ class AtomFeedTest < Test::Unit::TestCase
|
|
98
148
|
yield
|
99
149
|
end
|
100
150
|
end
|
101
|
-
end
|
151
|
+
end
|