actionpack 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- data/test/template/deprecate_ivars_test.rb +0 -51
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'controller/fake_controllers'
|
|
3
3
|
require 'action_controller/routing'
|
|
4
4
|
|
|
5
5
|
class MilestonesController < ActionController::Base
|
|
@@ -25,28 +25,37 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
|
|
|
25
25
|
ActionController::Routing.use_controllers! ['controller']
|
|
26
26
|
@set = ActionController::Routing::RouteSet.new
|
|
27
27
|
@set.draw do |map|
|
|
28
|
-
map.connect ':controller/:action/:variable'
|
|
28
|
+
map.connect ':controller/:action/:variable/*additional'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
safe, unsafe = %w(: @ & = + $ , ;), %w(^ / ? # [ ])
|
|
32
32
|
hex = unsafe.map { |char| '%' + char.unpack('H2').first.upcase }
|
|
33
33
|
|
|
34
|
-
@segment = "#{safe}#{unsafe}".freeze
|
|
35
|
-
@escaped = "#{safe}#{hex}".freeze
|
|
34
|
+
@segment = "#{safe.join}#{unsafe.join}".freeze
|
|
35
|
+
@escaped = "#{safe.join}#{hex.join}".freeze
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def test_route_generation_escapes_unsafe_path_characters
|
|
39
|
-
assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable",
|
|
39
|
+
assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2",
|
|
40
40
|
@set.generate(:controller => "contr#{@segment}oller",
|
|
41
41
|
:action => "act#{@segment}ion",
|
|
42
|
-
:variable => "var#{@segment}iable"
|
|
42
|
+
:variable => "var#{@segment}iable",
|
|
43
|
+
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"])
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def test_route_recognition_unescapes_path_components
|
|
46
47
|
options = { :controller => "controller",
|
|
47
48
|
:action => "act#{@segment}ion",
|
|
48
|
-
:variable => "var#{@segment}iable"
|
|
49
|
-
|
|
49
|
+
:variable => "var#{@segment}iable",
|
|
50
|
+
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
|
|
51
|
+
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_route_generation_allows_passing_non_string_values_to_generated_helper
|
|
55
|
+
assert_equal "/controller/action/variable/1/2", @set.generate(:controller => "controller",
|
|
56
|
+
:action => "action",
|
|
57
|
+
:variable => "variable",
|
|
58
|
+
:additional => [1, 2])
|
|
50
59
|
end
|
|
51
60
|
end
|
|
52
61
|
|
|
@@ -84,20 +93,47 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
|
|
84
93
|
end
|
|
85
94
|
|
|
86
95
|
def test_time_recognition
|
|
87
|
-
|
|
96
|
+
# We create many routes to make situation more realistic
|
|
97
|
+
@rs = ::ActionController::Routing::RouteSet.new
|
|
98
|
+
@rs.draw { |map|
|
|
99
|
+
map.frontpage '', :controller => 'search', :action => 'new'
|
|
100
|
+
map.resources :videos do |video|
|
|
101
|
+
video.resources :comments
|
|
102
|
+
video.resource :file, :controller => 'video_file'
|
|
103
|
+
video.resource :share, :controller => 'video_shares'
|
|
104
|
+
video.resource :abuse, :controller => 'video_abuses'
|
|
105
|
+
end
|
|
106
|
+
map.resources :abuses, :controller => 'video_abuses'
|
|
107
|
+
map.resources :video_uploads
|
|
108
|
+
map.resources :video_visits
|
|
109
|
+
|
|
110
|
+
map.resources :users do |user|
|
|
111
|
+
user.resource :settings
|
|
112
|
+
user.resources :videos
|
|
113
|
+
end
|
|
114
|
+
map.resources :channels do |channel|
|
|
115
|
+
channel.resources :videos, :controller => 'channel_videos'
|
|
116
|
+
end
|
|
117
|
+
map.resource :session
|
|
118
|
+
map.resource :lost_password
|
|
119
|
+
map.search 'search', :controller => 'search'
|
|
120
|
+
map.resources :pages
|
|
121
|
+
map.connect ':controller/:action/:id'
|
|
122
|
+
}
|
|
123
|
+
n = 1000
|
|
88
124
|
if RunTimeTests
|
|
89
125
|
GC.start
|
|
90
126
|
rectime = Benchmark.realtime do
|
|
91
127
|
n.times do
|
|
92
|
-
rs.recognize_path("
|
|
93
|
-
rs.recognize_path("
|
|
94
|
-
rs.recognize_path("
|
|
95
|
-
rs.recognize_path("
|
|
96
|
-
rs.recognize_path("
|
|
97
|
-
rs.recognize_path("admin/user/show/10")
|
|
128
|
+
rs.recognize_path("/videos/1234567", {:method => :get})
|
|
129
|
+
rs.recognize_path("/videos/1234567/abuse", {:method => :get})
|
|
130
|
+
rs.recognize_path("/users/1234567/settings", {:method => :get})
|
|
131
|
+
rs.recognize_path("/channels/1234567", {:method => :get})
|
|
132
|
+
rs.recognize_path("/session/new", {:method => :get})
|
|
133
|
+
rs.recognize_path("/admin/user/show/10", {:method => :get})
|
|
98
134
|
end
|
|
99
135
|
end
|
|
100
|
-
puts "\n\nRecognition (
|
|
136
|
+
puts "\n\nRecognition (#{rs.routes.size} routes):"
|
|
101
137
|
per_url = rectime / (n * 6)
|
|
102
138
|
puts "#{per_url * 1000} ms/url"
|
|
103
139
|
puts "#{1 / per_url} url/s\n\n"
|
|
@@ -909,6 +945,16 @@ class DynamicSegmentTest < Test::Unit::TestCase
|
|
|
909
945
|
a_segment.key = :action
|
|
910
946
|
assert a_segment.optionality_implied?
|
|
911
947
|
end
|
|
948
|
+
|
|
949
|
+
def test_modifiers_must_be_handled_sensibly
|
|
950
|
+
a_segment = ROUTING::DynamicSegment.new
|
|
951
|
+
a_segment.regexp = /david|jamis/i
|
|
952
|
+
assert_equal "((?i-mx:david|jamis))stuff", a_segment.build_pattern('stuff')
|
|
953
|
+
a_segment.regexp = /david|jamis/x
|
|
954
|
+
assert_equal "((?x-mi:david|jamis))stuff", a_segment.build_pattern('stuff')
|
|
955
|
+
a_segment.regexp = /david|jamis/
|
|
956
|
+
assert_equal "(david|jamis)stuff", a_segment.build_pattern('stuff')
|
|
957
|
+
end
|
|
912
958
|
end
|
|
913
959
|
|
|
914
960
|
class ControllerSegmentTest < Test::Unit::TestCase
|
|
@@ -1696,7 +1742,7 @@ class RouteSetTest < Test::Unit::TestCase
|
|
|
1696
1742
|
end
|
|
1697
1743
|
end
|
|
1698
1744
|
end
|
|
1699
|
-
|
|
1745
|
+
|
|
1700
1746
|
def test_non_path_route_requirements_match_all
|
|
1701
1747
|
set.draw do |map|
|
|
1702
1748
|
map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/
|
|
@@ -1781,6 +1827,30 @@ class RouteSetTest < Test::Unit::TestCase
|
|
|
1781
1827
|
Object.send(:remove_const, :PeopleController)
|
|
1782
1828
|
end
|
|
1783
1829
|
|
|
1830
|
+
def test_recognize_with_alias_in_conditions
|
|
1831
|
+
Object.const_set(:PeopleController, Class.new)
|
|
1832
|
+
|
|
1833
|
+
set.draw do |map|
|
|
1834
|
+
map.people "/people", :controller => 'people', :action => "index",
|
|
1835
|
+
:conditions => { :method => :get }
|
|
1836
|
+
map.root :people
|
|
1837
|
+
end
|
|
1838
|
+
|
|
1839
|
+
request.path = "/people"
|
|
1840
|
+
request.method = :get
|
|
1841
|
+
assert_nothing_raised { set.recognize(request) }
|
|
1842
|
+
assert_equal("people", request.path_parameters[:controller])
|
|
1843
|
+
assert_equal("index", request.path_parameters[:action])
|
|
1844
|
+
|
|
1845
|
+
request.path = "/"
|
|
1846
|
+
request.method = :get
|
|
1847
|
+
assert_nothing_raised { set.recognize(request) }
|
|
1848
|
+
assert_equal("people", request.path_parameters[:controller])
|
|
1849
|
+
assert_equal("index", request.path_parameters[:action])
|
|
1850
|
+
ensure
|
|
1851
|
+
Object.send(:remove_const, :PeopleController)
|
|
1852
|
+
end
|
|
1853
|
+
|
|
1784
1854
|
def test_typo_recognition
|
|
1785
1855
|
Object.const_set(:ArticlesController, Class.new)
|
|
1786
1856
|
|
|
@@ -2059,6 +2129,138 @@ class RouteSetTest < Test::Unit::TestCase
|
|
|
2059
2129
|
end
|
|
2060
2130
|
end
|
|
2061
2131
|
end
|
|
2132
|
+
|
|
2133
|
+
def test_route_requirements_with_unsupported_regexp_options_must_error
|
|
2134
|
+
assert_raises ArgumentError do
|
|
2135
|
+
set.draw do |map|
|
|
2136
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2137
|
+
:action => 'show',
|
|
2138
|
+
:requirements => {:name => /(david|jamis)/m}
|
|
2139
|
+
end
|
|
2140
|
+
end
|
|
2141
|
+
end
|
|
2142
|
+
|
|
2143
|
+
def test_route_requirements_with_supported_options_must_not_error
|
|
2144
|
+
assert_nothing_raised do
|
|
2145
|
+
set.draw do |map|
|
|
2146
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2147
|
+
:action => 'show',
|
|
2148
|
+
:requirements => {:name => /(david|jamis)/i}
|
|
2149
|
+
end
|
|
2150
|
+
end
|
|
2151
|
+
assert_nothing_raised do
|
|
2152
|
+
set.draw do |map|
|
|
2153
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2154
|
+
:action => 'show',
|
|
2155
|
+
:requirements => {:name => / # Desperately overcommented regexp
|
|
2156
|
+
( #Either
|
|
2157
|
+
david #The Creator
|
|
2158
|
+
| #Or
|
|
2159
|
+
jamis #The Deployer
|
|
2160
|
+
)/x}
|
|
2161
|
+
end
|
|
2162
|
+
end
|
|
2163
|
+
end
|
|
2164
|
+
|
|
2165
|
+
def test_route_requirement_recognize_with_ignore_case
|
|
2166
|
+
set.draw do |map|
|
|
2167
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2168
|
+
:action => 'show',
|
|
2169
|
+
:requirements => {:name => /(david|jamis)/i}
|
|
2170
|
+
end
|
|
2171
|
+
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
|
|
2172
|
+
assert_raises ActionController::RoutingError do
|
|
2173
|
+
set.recognize_path('/page/davidjamis')
|
|
2174
|
+
end
|
|
2175
|
+
assert_equal({:controller => 'pages', :action => 'show', :name => 'DAVID'}, set.recognize_path('/page/DAVID'))
|
|
2176
|
+
end
|
|
2177
|
+
|
|
2178
|
+
def test_route_requirement_generate_with_ignore_case
|
|
2179
|
+
set.draw do |map|
|
|
2180
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2181
|
+
:action => 'show',
|
|
2182
|
+
:requirements => {:name => /(david|jamis)/i}
|
|
2183
|
+
end
|
|
2184
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
|
|
2185
|
+
assert_equal "/page/david", url
|
|
2186
|
+
assert_raises ActionController::RoutingError do
|
|
2187
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
|
|
2188
|
+
end
|
|
2189
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
|
2190
|
+
assert_equal "/page/JAMIS", url
|
|
2191
|
+
end
|
|
2192
|
+
|
|
2193
|
+
def test_route_requirement_recognize_with_extended_syntax
|
|
2194
|
+
set.draw do |map|
|
|
2195
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2196
|
+
:action => 'show',
|
|
2197
|
+
:requirements => {:name => / # Desperately overcommented regexp
|
|
2198
|
+
( #Either
|
|
2199
|
+
david #The Creator
|
|
2200
|
+
| #Or
|
|
2201
|
+
jamis #The Deployer
|
|
2202
|
+
)/x}
|
|
2203
|
+
end
|
|
2204
|
+
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
|
|
2205
|
+
assert_equal({:controller => 'pages', :action => 'show', :name => 'david'}, set.recognize_path('/page/david'))
|
|
2206
|
+
assert_raises ActionController::RoutingError do
|
|
2207
|
+
set.recognize_path('/page/david #The Creator')
|
|
2208
|
+
end
|
|
2209
|
+
assert_raises ActionController::RoutingError do
|
|
2210
|
+
set.recognize_path('/page/David')
|
|
2211
|
+
end
|
|
2212
|
+
end
|
|
2213
|
+
|
|
2214
|
+
def test_route_requirement_generate_with_extended_syntax
|
|
2215
|
+
set.draw do |map|
|
|
2216
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2217
|
+
:action => 'show',
|
|
2218
|
+
:requirements => {:name => / # Desperately overcommented regexp
|
|
2219
|
+
( #Either
|
|
2220
|
+
david #The Creator
|
|
2221
|
+
| #Or
|
|
2222
|
+
jamis #The Deployer
|
|
2223
|
+
)/x}
|
|
2224
|
+
end
|
|
2225
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
|
|
2226
|
+
assert_equal "/page/david", url
|
|
2227
|
+
assert_raises ActionController::RoutingError do
|
|
2228
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
|
|
2229
|
+
end
|
|
2230
|
+
assert_raises ActionController::RoutingError do
|
|
2231
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
|
2232
|
+
end
|
|
2233
|
+
end
|
|
2234
|
+
|
|
2235
|
+
def test_route_requirement_generate_with_xi_modifiers
|
|
2236
|
+
set.draw do |map|
|
|
2237
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2238
|
+
:action => 'show',
|
|
2239
|
+
:requirements => {:name => / # Desperately overcommented regexp
|
|
2240
|
+
( #Either
|
|
2241
|
+
david #The Creator
|
|
2242
|
+
| #Or
|
|
2243
|
+
jamis #The Deployer
|
|
2244
|
+
)/xi}
|
|
2245
|
+
end
|
|
2246
|
+
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
|
|
2247
|
+
assert_equal "/page/JAMIS", url
|
|
2248
|
+
end
|
|
2249
|
+
|
|
2250
|
+
def test_route_requirement_recognize_with_xi_modifiers
|
|
2251
|
+
set.draw do |map|
|
|
2252
|
+
map.connect 'page/:name', :controller => 'pages',
|
|
2253
|
+
:action => 'show',
|
|
2254
|
+
:requirements => {:name => / # Desperately overcommented regexp
|
|
2255
|
+
( #Either
|
|
2256
|
+
david #The Creator
|
|
2257
|
+
| #Or
|
|
2258
|
+
jamis #The Deployer
|
|
2259
|
+
)/xi}
|
|
2260
|
+
end
|
|
2261
|
+
assert_equal({:controller => 'pages', :action => 'show', :name => 'JAMIS'}, set.recognize_path('/page/JAMIS'))
|
|
2262
|
+
end
|
|
2263
|
+
|
|
2062
2264
|
|
|
2063
2265
|
end
|
|
2064
2266
|
|
|
@@ -2139,7 +2341,7 @@ class RoutingTest < Test::Unit::TestCase
|
|
|
2139
2341
|
ActionController::Routing::Routes.install_helpers c
|
|
2140
2342
|
assert c.ancestors.include?(h)
|
|
2141
2343
|
end
|
|
2142
|
-
|
|
2344
|
+
|
|
2143
2345
|
end
|
|
2144
2346
|
|
|
2145
2347
|
uses_mocha 'route loading' do
|
|
@@ -2148,11 +2350,13 @@ uses_mocha 'route loading' do
|
|
|
2148
2350
|
def setup
|
|
2149
2351
|
routes.instance_variable_set '@routes_last_modified', nil
|
|
2150
2352
|
silence_warnings { Object.const_set :RAILS_ROOT, '.' }
|
|
2353
|
+
ActionController::Routing::Routes.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
|
|
2151
2354
|
|
|
2152
2355
|
@stat = stub_everything
|
|
2153
2356
|
end
|
|
2154
2357
|
|
|
2155
2358
|
def teardown
|
|
2359
|
+
ActionController::Routing::Routes.configuration_file = nil
|
|
2156
2360
|
Object.send :remove_const, :RAILS_ROOT
|
|
2157
2361
|
end
|
|
2158
2362
|
|
|
@@ -2193,6 +2397,14 @@ uses_mocha 'route loading' do
|
|
|
2193
2397
|
|
|
2194
2398
|
Inflector.inflections { |inflect| inflect.uncountable('equipment') }
|
|
2195
2399
|
end
|
|
2400
|
+
|
|
2401
|
+
def test_load_with_configuration
|
|
2402
|
+
routes.configuration_file = "foobarbaz"
|
|
2403
|
+
File.expects(:stat).returns(@stat)
|
|
2404
|
+
routes.expects(:load).with("foobarbaz")
|
|
2405
|
+
|
|
2406
|
+
routes.reload
|
|
2407
|
+
end
|
|
2196
2408
|
|
|
2197
2409
|
private
|
|
2198
2410
|
def routes
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
# Under MIT and/or CC By license.
|
|
4
4
|
#++
|
|
5
5
|
|
|
6
|
-
require
|
|
7
|
-
require
|
|
6
|
+
require 'abstract_unit'
|
|
7
|
+
require 'controller/fake_controllers'
|
|
8
8
|
|
|
9
9
|
class SelectorTest < Test::Unit::TestCase
|
|
10
10
|
#
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
module TestFileUtils
|
|
@@ -27,7 +27,7 @@ class SendFileTest < Test::Unit::TestCase
|
|
|
27
27
|
include TestFileUtils
|
|
28
28
|
|
|
29
29
|
Mime::Type.register "image/png", :png unless defined? Mime::PNG
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def setup
|
|
32
32
|
@controller = SendFileController.new
|
|
33
33
|
@request = ActionController::TestRequest.new
|
|
@@ -55,7 +55,7 @@ class SendFileTest < Test::Unit::TestCase
|
|
|
55
55
|
assert_nothing_raised { response.body.call(response, output) }
|
|
56
56
|
assert_equal file_data, output.string
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
def test_file_url_based_filename
|
|
60
60
|
@controller.options = { :url_based_filename => true }
|
|
61
61
|
response = nil
|
|
@@ -64,6 +64,17 @@ class SendFileTest < Test::Unit::TestCase
|
|
|
64
64
|
assert_equal "attachment", response.headers["Content-Disposition"]
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
def test_x_sendfile_header
|
|
68
|
+
@controller.options = { :x_sendfile => true }
|
|
69
|
+
|
|
70
|
+
response = nil
|
|
71
|
+
assert_nothing_raised { response = process('file') }
|
|
72
|
+
assert_not_nil response
|
|
73
|
+
|
|
74
|
+
assert_equal @controller.file_path, response.headers['X-Sendfile']
|
|
75
|
+
assert response.body.blank?
|
|
76
|
+
end
|
|
77
|
+
|
|
67
78
|
def test_data
|
|
68
79
|
response = nil
|
|
69
80
|
assert_nothing_raised { response = process('data') }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
require 'action_controller/cgi_process'
|
|
3
3
|
require 'action_controller/cgi_ext'
|
|
4
4
|
|
|
@@ -43,7 +43,9 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
|
43
43
|
{ :empty => ['BAgw--0686dcaccc01040f4bd4f35fe160afe9bc04c330', {}],
|
|
44
44
|
:a_one => ['BAh7BiIGYWkG--5689059497d7f122a7119f171aef81dcfd807fec', { 'a' => 1 }],
|
|
45
45
|
:typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--9d20154623b9eeea05c62ab819be0e2483238759', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}],
|
|
46
|
-
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA
|
|
46
|
+
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--bf9785a666d3c4ac09f7fe3353496b437546cfbf', { 'user_id' => 123, 'flash' => {} }],
|
|
47
|
+
:double_escaped => [CGI.escape('BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--bf9785a666d3c4ac09f7fe3353496b437546cfbf'), { 'user_id' => 123, 'flash' => {} }] }
|
|
48
|
+
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
def setup
|
|
@@ -101,6 +103,15 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
|
101
103
|
end
|
|
102
104
|
end
|
|
103
105
|
|
|
106
|
+
def test_restores_double_encoded_cookies
|
|
107
|
+
set_cookie! cookie_value(:double_escaped)
|
|
108
|
+
new_session do |session|
|
|
109
|
+
session.dbman.restore
|
|
110
|
+
assert_equal session["user_id"], 123
|
|
111
|
+
assert_equal session["flash"], {}
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
104
115
|
def test_close_doesnt_write_cookie_if_data_is_blank
|
|
105
116
|
new_session do |session|
|
|
106
117
|
assert_no_cookies session
|
|
@@ -175,7 +186,7 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
|
175
186
|
def assert_cookie_deleted(session, message = 'Expected session deletion cookie to be set')
|
|
176
187
|
assert_equal 1, session.cgi.output_cookies.size
|
|
177
188
|
cookie = session.cgi.output_cookies.first
|
|
178
|
-
assert_cookie cookie, nil, 1.year.ago.to_date, message
|
|
189
|
+
assert_cookie cookie, nil, 1.year.ago.to_date, "#{message}: #{cookie.name} => #{cookie.value}"
|
|
179
190
|
end
|
|
180
191
|
|
|
181
192
|
def assert_cookie(cookie, value = nil, expires = nil, message = nil)
|
|
@@ -241,6 +252,7 @@ class CookieStoreWithMD5DigestTest < CookieStoreTest
|
|
|
241
252
|
{ :empty => ['BAgw--0415cc0be9579b14afc22ee2d341aa21', {}],
|
|
242
253
|
:a_one => ['BAh7BiIGYWkG--5a0ed962089cc6600ff44168a5d59bc8', { 'a' => 1 }],
|
|
243
254
|
:typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--f426763f6ef435b3738b493600db8d64', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}],
|
|
244
|
-
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA
|
|
255
|
+
:flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--0af9156650dab044a53a91a4ddec2c51', { 'user_id' => 123, 'flash' => {} }],
|
|
256
|
+
:double_escaped => [CGI.escape('BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--0af9156650dab044a53a91a4ddec2c51'), { 'user_id' => 123, 'flash' => {} }] }
|
|
245
257
|
end
|
|
246
258
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
require 'action_controller/cgi_process'
|
|
3
3
|
require 'action_controller/cgi_ext'
|
|
4
4
|
|
|
@@ -62,9 +62,8 @@ class MemCacheStoreTest < Test::Unit::TestCase
|
|
|
62
62
|
assert_equal d, s.cache.get(session_key)[:test]
|
|
63
63
|
assert_equal d, s[:test]
|
|
64
64
|
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
end
|
|
66
|
+
|
|
68
67
|
def test_deletion
|
|
69
68
|
new_session do |s|
|
|
70
69
|
session_key = 'session:' + s.session_id
|