Changeset 614
- Timestamp:
- 02/15/05 00:51:02 (4 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller (modified) (1 prop)
- trunk/actionpack/lib/action_controller/assertions/action_pack_assertions.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/base.rb (modified) (5 diffs)
- trunk/actionpack/lib/action_controller/cgi_process.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/helpers.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/request.rb (modified) (4 diffs)
- trunk/actionpack/lib/action_controller/rescue.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/scaffolding.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/templates/rescues/routing_error.rhtml (copied) (copied from branches/routing/actionpack/lib/action_controller/templates/rescues/routing_error.rhtml)
- trunk/actionpack/lib/action_controller/test_process.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_controller/url_rewriter.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_view/partials.rb (modified) (1 diff)
- trunk/actionpack/test/controller/cookie_test.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/helper_test.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/render_test.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/request_test.rb (modified) (1 diff)
- trunk/actionpack/test/controller/routing_tests.rb (copied) (copied from branches/routing/actionpack/test/controller/routing_tests.rb)
- trunk/actionpack/test/controller/url_obsolete.rb (copied) (copied from branches/routing/actionpack/test/controller/url_obsolete.rb)
- trunk/actionpack/test/controller/url_test.rb (deleted)
- trunk/actionpack/test/fixtures/fun (copied) (copied from branches/routing/actionpack/test/fixtures/fun)
- trunk/actionpack/test/fixtures/fun/games (copied) (copied from branches/routing/actionpack/test/fixtures/fun/games)
- trunk/actionpack/test/fixtures/fun/games/hello_world.rhtml (copied) (copied from branches/routing/actionpack/test/fixtures/fun/games/hello_world.rhtml)
- trunk/actionpack/test/fixtures/helpers/fun (copied) (copied from branches/routing/actionpack/test/fixtures/helpers/fun)
- trunk/actionpack/test/fixtures/helpers/fun/games_helper.rb (copied) (copied from branches/routing/actionpack/test/fixtures/helpers/fun/games_helper.rb)
- trunk/activerecord/lib/active_record (modified) (1 prop)
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/core_ext/hash/indifferent_access.rb (modified) (1 diff)
- trunk/activesupport/lib/core_ext/string/inflections.rb (modified) (1 diff)
- trunk/activesupport/lib/dependencies.rb (modified) (3 diffs)
- trunk/activesupport/lib/inflector.rb (modified) (2 diffs)
- trunk/activesupport/test/inflector_test.rb (modified) (4 diffs)
- trunk/activesupport/test/loading_module (copied) (copied from branches/routing/activesupport/test/loading_module)
- trunk/activesupport/test/loading_module_tests.rb (copied) (copied from branches/routing/activesupport/test/loading_module_tests.rb)
- trunk/activesupport/test/loading_module/admin (copied) (copied from branches/routing/activesupport/test/loading_module/admin)
- trunk/activesupport/test/loading_module/admin/access_controller.rb (copied) (copied from branches/routing/activesupport/test/loading_module/admin/access_controller.rb)
- trunk/activesupport/test/loading_module/admin/user_controller.rb (copied) (copied from branches/routing/activesupport/test/loading_module/admin/user_controller.rb)
- trunk/activesupport/test/loading_module/content_controller.rb (copied) (copied from branches/routing/activesupport/test/loading_module/content_controller.rb)
- trunk/activesupport/test/loading_module/resource_controller.rb (copied) (copied from branches/routing/activesupport/test/loading_module/resource_controller.rb)
- trunk/railties/bin/destroy (modified) (1 diff)
- trunk/railties/bin/generate (modified) (1 diff)
- trunk/railties/bin/rails (modified) (1 diff)
- trunk/railties/bin/update (modified) (1 diff)
- trunk/railties/configs/apache.conf (modified) (1 diff)
- trunk/railties/environments/shared_for_gem.rb (modified) (1 diff)
- trunk/railties/environments/shared.rb (modified) (1 diff)
- trunk/railties/generators (deleted)
- trunk/railties/lib/dispatcher.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator.rb (modified) (2 diffs)
- trunk/railties/lib/rails_generator/base.rb (modified) (3 diffs)
- trunk/railties/lib/rails_generator/generators/applications/app/app_generator.rb (modified) (4 diffs)
- trunk/railties/lib/rails_generator/generators/components/controller/controller_generator.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/model/model_generator.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb (modified) (5 diffs)
- trunk/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb (modified) (4 diffs)
- trunk/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml (modified) (1 diff)
- trunk/railties/lib/rails_generator/lookup.rb (modified) (2 diffs)
- trunk/railties/lib/rails_generator/options.rb (modified) (3 diffs)
- trunk/railties/lib/rails_generator/scripts.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/scripts/destroy.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/scripts/generate.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/scripts/update.rb (modified) (1 diff)
- trunk/railties/test/rails_generator_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller
- Property svn:externals changed from
support http://dev.rubyonrails.org/svn/rails/trunk/activesupport/lib
to
support http://dev.rubyonrails.org/svn/rails/branches/routing/activesupport/lib
- Property svn:externals changed from
trunk/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
r525 r614 142 142 end 143 143 end 144 144 145 145 # ensure our redirection url is an exact match 146 146 def assert_redirect_url(url=nil, message=nil) … … 157 157 msg = build_message(message, "<?> was not found in the location: <?>", pattern, response.redirect_url) 158 158 assert_block(msg) { response.redirect_url_match?(pattern) } 159 end 160 161 # -- routing assertions -------------------------------------------------- 162 163 # Asserts that the routing of the given path is handled correctly and that the parsed options match. 164 # Also verifies that the provided options can be used to generate the provided path. 165 def assert_routing(path, options, defaults={}, extras={}, message=nil) 166 defaults[:controller] ||= options[:controller] # Assume given controller, 167 request = ActionController::TestRequest.new({}, {}, nil) 168 request.path_parameters = defaults 169 170 ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? # Load routes.rb if it hasn't been loaded. 171 172 generated_path, found_extras = ActionController::Routing::Routes.generate(defaults.merge(options), request) 173 generated_path = generated_path.join('/') 174 msg = build_message(message, "found extras <?>, not <?>", found_extras, extras) 175 assert_block(msg) { found_extras == extras } 176 177 msg = build_message(message, "The generated path <?> did not match <?>", generated_path, path) 178 assert_block(msg) { path == generated_path } 179 180 request = ActionController::TestRequest.new({}, {}, nil) 181 request.path = path 182 ActionController::Routing::Routes.recognize!(request) 183 184 expected_options = options.clone 185 extras.each {|k,v| expected_options.delete k} 186 187 msg = build_message(message, "The recognized options <?> did not match <?>", request.path_parameters, expected_options) 188 assert_block(msg) { request.path_parameters == expected_options } 159 189 end 160 190 trunk/actionpack/lib/action_controller/base.rb
r525 r614 13 13 end 14 14 class MissingTemplate < ActionControllerError #:nodoc: 15 end 16 class RoutingError < ActionControllerError 17 attr_reader :failures 18 def initialize(message, failures=[]) 19 super(message) 20 @failures = failures 21 end 15 22 end 16 23 class UnknownAction < ActionControllerError #:nodoc: … … 206 213 @@consider_all_requests_local = true 207 214 cattr_accessor :consider_all_requests_local 215 216 # Enable or disable the collection of failure information for RoutingErrors. 217 # This information can be extremely useful when tweaking custom routes, but is 218 # pointless once routes have been tested and verified. 219 @@debug_routes = true 220 cattr_accessor :debug_routes 208 221 209 222 # Template root determines the base from which template references will be made. So a call to render("test/template") … … 261 274 def controller_name 262 275 Inflector.underscore(controller_class_name.sub(/Controller/, "")) 276 end 277 278 # Convert the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat". 279 def controller_path 280 components = self.name.to_s.split('::').collect { |name| name.underscore } 281 components[-1] = $1 if /^(.*)_controller$/ =~ components[-1] 282 components.shift if components.first == 'controllers' # Transitional conditional to accomodate root Controllers module 283 components.join('/') 263 284 end 264 285 end … … 336 357 when Hash then @url.rewrite(rewrite_options(options)) 337 358 end 338 end339 340 def module_name341 @params["module"]342 359 end 343 360 … … 692 709 693 710 def default_template_name(default_action_name = action_name) 694 module_name ? "#{module_name}/#{controller_name}/#{default_action_name}" : "#{controller_name}/#{default_action_name}"711 "#{self.class.controller_path}/#{default_action_name}" 695 712 end 696 713 end trunk/actionpack/lib/action_controller/cgi_process.rb
r502 r614 47 47 end 48 48 49 def query_string 50 return @cgi.query_string unless @cgi.query_string.nil? || @cgi.query_string.empty? 51 parts = env['REQUEST_URI'].split('?') 52 parts.shift 53 return parts.join('?') 54 end 55 49 56 def query_parameters 50 @cgi.query_string ? CGIMethods.parse_query_parameters(@cgi.query_string) : {} 57 qs = self.query_string 58 qs.empty? ? {} : CGIMethods.parse_query_parameters(query_string) 51 59 end 52 60 trunk/actionpack/lib/action_controller/helpers.rb
r514 r614 49 49 args.flatten.each do |arg| 50 50 case arg 51 when Module 52 add_template_helper(arg) 53 when String, Symbol 54 file_name = Inflector.underscore(arg.to_s.downcase) + '_helper' 55 class_name = Inflector.camelize(file_name) 56 begin 57 require_dependency(file_name) 58 rescue LoadError => load_error 59 requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1] 60 if requiree == file_name 61 raise LoadError, "Missing helper file helpers/#{file_name}.rb" 62 else 63 raise LoadError, "Can't load file: #{requiree}" 51 when Module 52 add_template_helper(arg) 53 when String, Symbol 54 file_name = arg.to_s.underscore + '_helper' 55 class_name = file_name.camelize 56 57 begin 58 require_dependency(file_name) 59 rescue LoadError => load_error 60 requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1] 61 raise LoadError, requiree == file_name ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}" 64 62 end 65 end 66 raise ArgumentError, "Missing #{class_name} module in helpers/#{file_name}.rb" unless Object.const_defined?(class_name) 67 add_template_helper(Object.const_get(class_name)) 68 else 69 raise ArgumentError, 'helper expects String, Symbol, or Module argument' 63 64 add_template_helper(class_name.constantize) 65 else 66 raise ArgumentError, 'helper expects String, Symbol, or Module argument' 70 67 end 71 68 end … … 96 93 inherited_without_helper(child) 97 94 begin 98 child.helper(child.controller_ name)95 child.helper(child.controller_path) 99 96 rescue ArgumentError, LoadError 100 97 # No default helper available for this controller trunk/actionpack/lib/action_controller/request.rb
r525 r614 4 4 # Returns both GET and POST parameters in a single hash. 5 5 def parameters 6 @parameters ||= request_parameters. update(query_parameters)6 @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access 7 7 end 8 8 … … 74 74 75 75 def request_uri 76 env['REQUEST_URI']76 (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri. 77 77 end 78 78 … … 86 86 87 87 def path 88 request_uri ? request_uri.split('?').first : ''88 path = request_uri ? request_uri.split('?').first : '' 89 89 end 90 90 … … 101 101 env['HTTP_HOST'] || host + port_string 102 102 end 103 104 def path_parameters=(parameters) 105 @path_parameters = parameters 106 @parameters = nil 107 end 103 108 109 def path_parameters 110 @path_parameters ||= {} 111 end 112 104 113 #-- 105 114 # Must be implemented in the concrete request trunk/actionpack/lib/action_controller/rescue.rb
r525 r614 49 49 # Overwrite to implement public exception handling (for requests answering false to <tt>local_request?</tt>). 50 50 def rescue_action_in_public(exception) #:doc: 51 render_text "<html><body><h1>Application error (Rails)</h1></body></html>" 51 case exception 52 when RoutingError, UnknownAction then 53 render_text(IO.read(File.join(RAILS_ROOT, 'public', '404.html')), "404 Not Found") 54 else render_text "<html><body><h1>Application error (Rails)</h1></body></html>" 55 end 52 56 end 53 57 … … 111 115 case exception 112 116 when MissingTemplate then "missing_template" 117 when RoutingError then "routing_error" 113 118 when UnknownAction then "unknown_action" 114 119 when ActionView::TemplateError then "template_error" 115 else "diagnostics"120 else raise ;"diagnostics" 116 121 end 117 122 ) 123 end 124 125 def response_code_for_rescue(exception) 126 case exception 127 when UnknownAction, RoutingError then "404 Page Not Found" 128 else "500 Internal Error" 129 end 118 130 end 119 131 trunk/actionpack/lib/action_controller/scaffolding.rb
r525 r614 150 150 private 151 151 def render#{suffix}_scaffold(action = caller_method_name(caller)) 152 if template_exists?("\#{ controller_name}/\#{action}")152 if template_exists?("\#{self.class.controller_path}/\#{action}") 153 153 render_action(action) 154 154 else trunk/actionpack/lib/action_controller/test_process.rb
r587 r614 32 32 class TestRequest < AbstractRequest #:nodoc: 33 33 attr_accessor :cookies 34 attr_accessor :query_parameters, :request_parameters, : session, :env35 attr_accessor :host, : path, :request_uri, :remote_addr34 attr_accessor :query_parameters, :request_parameters, :path, :session, :env 35 attr_accessor :host, :remote_addr 36 36 37 37 def initialize(query_parameters = nil, request_parameters = nil, session = nil) … … 59 59 end 60 60 61 # Used to check AbstractRequest's request_uri functionality. 62 # Disables the use of @path and @request_uri so superclass can handle those. 63 def set_REQUEST_URI(value) 64 @env["REQUEST_URI"] = value 65 @request_uri = nil 66 @path = nil 67 end 68 61 69 def request_uri=(uri) 62 70 @request_uri = uri 63 71 @path = uri.split("?").first 64 72 end 73 74 def request_uri 75 @request_uri || super() 76 end 77 78 def path 79 @path || super() 80 end 81 65 82 66 83 private … … 238 255 @request.env['REQUEST_METHOD'] ||= "GET" 239 256 @request.action = action.to_s 257 @request.path_parameters = { :controller => @controller.class.controller_path } 240 258 @request.parameters.update(parameters) unless parameters.nil? 241 259 @request.session = ActionController::TestSession.new(session) unless session.nil? trunk/actionpack/lib/action_controller/url_rewriter.rb
r580 r614 2 2 # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. 3 3 class UrlRewriter #:nodoc: 4 VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :application_prefix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params, :host, :protocol ] 5 6 def initialize(request, controller, action) 7 @request, @controller, @action = request, controller, action 4 RESERVED_OPTIONS = [:anchor, :params, :path_params, :only_path, :host, :protocol] 5 def initialize(request, parameters) 6 @request, @parameters = request, parameters 8 7 @rewritten_path = @request.path ? @request.path.dup : "" 9 8 end … … 23 22 24 23 def to_str 25 "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@controller}, #{@action}, #{@request.parameters.inspect}"24 "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@parameters[:controller]}, #{@parameters[:action]}, #{@request.parameters.inspect}" 26 25 end 27 26 … … 49 48 end 50 49 51 def rewrite_path(path, options) 52 include_id_in_path_params(options) 53 54 path = rewrite_action(path, options) if options[:action] || options[:action_prefix] 55 path = rewrite_path_params(path, options) if options[:path_params] 56 path = rewrite_controller(path, options) if options[:controller] || options[:controller_prefix] 50 def rewrite_path(options) 51 options = options.symbolize_keys 52 RESERVED_OPTIONS.each {|k| options.delete k} 53 54 path, extras = Routing::Routes.generate(options, @request) 55 path = "/#{path.join('/')}" 56 path += build_query_string(extras) 57 57 58 return path 58 59 end trunk/actionpack/lib/action_view/partials.rb
r525 r614 61 61 return File.dirname(partial_path), File.basename(partial_path) 62 62 else 63 return controller. send(:controller_name), partial_path63 return controller.class.controller_path, partial_path 64 64 end 65 65 end trunk/actionpack/test/controller/cookie_test.rb
r22 r614 27 27 cookies["login"] = "XJ-122" 28 28 render_text "hello world" 29 end30 31 def access_frozen_cookies32 @cookies["wont"] = "work"33 29 end 34 30 … … 68 64 end 69 65 70 def test_setting_cookie_on_frozen_instance_variable71 @request.action = "access_frozen_cookies"72 assert_raises(TypeError) { process_request }73 end74 75 66 private 76 67 def process_request trunk/actionpack/test/controller/helper_test.rb
r250 r614 1 1 require File.dirname(__FILE__) + '/../abstract_unit' 2 $:.unshift(File.dirname(__FILE__) + '/../fixtures/helpers') 3 4 class TestController < ActionController::Base 5 attr_accessor :delegate_attr 6 def delegate_method() end 7 def rescue_action(e) raise end 8 end 9 10 module Fun 11 class GamesController < ActionController::Base 12 def render_hello_world 13 render_template "hello: <%= stratego %>" 14 end 15 16 def rescue_action(e) raise end 17 end 18 end 19 20 module LocalAbcHelper 21 def a() end 22 def b() end 23 def c() end 24 end 2 25 3 26 class HelperTest < Test::Unit::TestCase 4 27 HELPER_PATHS = %w(/../fixtures/helpers) 5 6 class TestController < ActionController::Base7 attr_accessor :delegate_attr8 def delegate_method() end9 def rescue_action(e) raise end10 end11 12 module LocalAbcHelper13 def a() end14 def b() end15 def c() end16 end17 18 28 19 29 def setup … … 103 113 end 104 114 115 def test_helper_for_nested_controller 116 @request = ActionController::TestRequest.new 117 @response = ActionController::TestResponse.new 118 @request.action = "render_hello_world" 119 120 assert_equal "hello: Iz guuut!", Fun::GamesController.process(@request, @response).body 121 end 105 122 106 123 private trunk/actionpack/test/controller/render_test.rb
r351 r614 3 3 Customer = Struct.new("Customer", :name) 4 4 5 class RenderTest < Test::Unit::TestCase 6 class TestController < ActionController::Base 7 layout :determine_layout 8 5 module Fun 6 class GamesController < ActionController::Base 9 7 def hello_world 10 8 end 9 end 10 end 11 11 12 def render_hello_world13 render "test/hello_world"14 end15 12 16 def render_hello_world_from_variable 17 @person = "david" 18 render_text "hello #{@person}" 19 end 13 class TestController < ActionController::Base 14 layout :determine_layout 20 15 21 def render_action_hello_world 22 render_action "hello_world" 23 end 24 25 def render_text_hello_world 26 render_text "hello world" 27 end 28 29 def render_custom_code 30 render_text "hello world", "404 Moved" 31 end 32 33 def render_xml_hello 34 @name = "David" 35 render "test/hello" 36 end 37 38 def greeting 39 # let's just rely on the template 40 end 41 42 def layout_test 43 render_action "hello_world" 44 end 45 46 def builder_layout_test 47 render_action "hello" 48 end 49 50 def partials_list 51 @customers = [ Customer.new("david"), Customer.new("mary") ] 52 render_action "list" 53 end 54 55 def modgreet 56 end 57 58 def rescue_action(e) raise end 59 60 private 61 def determine_layout 62 case action_name 63 when "layout_test": "layouts/standard" 64 when "builder_layout_test": "layouts/builder" 65 end 66 end 16 def hello_world 67 17 end 68 18 69 TestController.template_root = File.dirname(__FILE__) + "/../fixtures/" 70 71 class TestLayoutController < ActionController::Base 72 layout "layouts/standard" 73 74 def hello_world 75 end 76 77 def hello_world_outside_layout 78 end 79 80 def rescue_action(e) 81 raise unless ActionController::MissingTemplate === e 82 end 19 def render_hello_world 20 render "test/hello_world" 83 21 end 84 22 23 def render_hello_world_from_variable 24 @person = "david" 25 render_text "hello #{@person}" 26 end 27 28 def render_action_hello_world 29 render_action "hello_world" 30 end 31 32 def render_text_hello_world 33 render_text "hello world" 34 end 35 36 def render_custom_code 37 render_text "hello world", "404 Moved" 38 end 39 40 def render_xml_hello 41 @name = "David" 42 render "test/hello" 43 end 44 45 def greeting 46 # let's just rely on the template 47 end 48 49 def layout_test 50 render_action "hello_world" 51 end 52 53 def builder_layout_test 54 render_action "hello" 55 end 56 57 def partials_list 58 @customers = [ Customer.new("david"), Customer.new("mary") ] 59 render_action "list" 60 end 61 62 def rescue_action(e) raise end 63 64 private 65 def determine_layout 66 case action_name 67 when "layout_test": "layouts/standard" 68 when "builder_layout_test": "layouts/builder" 69 end 70 end 71 end 72 73 TestController.template_root = File.dirname(__FILE__) + "/../fixtures/" 74 75 class TestLayoutController < ActionController::Base 76 layout "layouts/standard" 77 78 def hello_world 79 end 80 81 def hello_world_outside_layout 82 end 83 84 def rescue_action(e) 85 raise unless ActionController::MissingTemplate === e 86 end 87 end 88 89 class RenderTest < Test::Unit::TestCase 85 90 def setup 86 91 @request = ActionController::TestRequest.new … … 171 176 end 172 177 173 def test_module_rendering 174 @request.action = "modgreet" 175 @request.parameters["module"] = "scope" 176 assert_equal "<p>Beautiful modules!</p>", process_request.body 178 def test_nested_rendering 179 @request.action = "hello_world" 180 assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body 177 181 end 178 182 trunk/actionpack/test/controller/request_test.rb
r214 r614 32 32 assert_equal ":8080", @request.port_string 33 33 end 34 35 def test_request_uri 36 @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1" 37 assert_equal "/path/of/some/uri?mapped=1", @request.request_uri 38 assert_equal "/path/of/some/uri", @request.path 39 40 @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri" 41 assert_equal "/path/of/some/uri", @request.request_uri 42 assert_equal "/path/of/some/uri", @request.path 43 44 @request.set_REQUEST_URI "/path/of/some/uri" 45 assert_equal "/path/of/some/uri", @request.request_uri 46 assert_equal "/path/of/some/uri", @request.path 47 48 @request.set_REQUEST_URI "/" 49 assert_equal "/", @request.request_uri 50 assert_equal "/", @request.path 51 52 @request.set_REQUEST_URI "/?m=b" 53 assert_equal "/?m=b", @request.request_uri 54 assert_equal "/", @request.path 55 end 34 56 35 57 def test_host_with_port trunk/activerecord/lib/active_record
- Property svn:externals changed from
support http://dev.rubyonrails.org/svn/rails/trunk/activesupport/lib
to
support http://dev.rubyonrails.org/svn/rails/branches/routing/activesupport/lib
- Property svn:externals changed from
trunk/activesupport/CHANGELOG
r586 r614 2 2 3 3 * Added IndifferentAccess as a way to wrap a hash by a symbol-based store that also can be accessed by string keys 4 5 * Added Inflector.constantize to turn "Admin::User" into a reference for the constant Admin::User 6 7 * Added that Inflector.camelize and Inflector.underscore can deal with modules like turning "Admin::User" into "admin/user" and back 4 8 5 9 * Added Inflector.humanize to turn attribute names like employee_salary into "Employee salary". Used by automated error reporting in AR. trunk/activesupport/lib/core_ext/hash/indifferent_access.rb
r581 r614 9 9 end 10 10 11 alias_method :regular_read , :[]11 alias_method :regular_reader, :[] unless method_defined?(:regular_reader) 12 12 13 13 def [](key) 14 14 case key 15 when Symbol: regular_read (key) || regular_read(key.to_s)16 when String: regular_read (key) || regular_read(key.to_sym)17 else regular_read (key)15 when Symbol: regular_reader(key) || regular_reader(key.to_s) 16 when String: regular_reader(key) || regular_reader(key.to_sym) 17 else regular_reader(key) 18 18 end 19 19 end 20 20 21 alias_method :regular_writer, :[]= 21 alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) 22 22 23 23 def []=(key, value) trunk/activesupport/lib/core_ext/string/inflections.rb
r450 r614 40 40 Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) 41 41 end 42 43 def constantize 44 Inflector.constantize(self) 45 end 42 46 end 43 47 end trunk/activesupport/lib/dependencies.rb
r510 r614 3 3 module Dependencies 4 4 extend self 5 5 6 6 @@loaded = [ ] 7 7 mattr_accessor :loaded … … 42 42 classes.each { |klass| klass.remove_subclasses } 43 43 end 44 45 # LoadingModules implement namespace-safe dynamic loading. 46 # They support automatic loading via const_missing, allowing contained items to be automatically 47 # loaded when required. No extra syntax is required, as expressions such as Controller::Admin::UserController 48 # load the relavent files automatically. 49 # 50 # Ruby-style modules are supported, as a folder named 'submodule' will load 'submodule.rb' when available. 51 class LoadingModule < Module 52 attr_reader :path 53 54 def initialize(filesystem_root, path=[]) 55 @path = path 56 @filesystem_root = filesystem_root 57 end 58 59 # The path to this module in the filesystem. 60 # Any subpath provided is taken to be composed of filesystem names. 61 def filesystem_path(subpath=[]) 62 File.join(@filesystem_root, self.path, subpath) 63 end 64 65 # Load missing constants if possible. 66 def const_missing(name) 67 return const_get(name) if const_defined?(name) == false && const_load!(name) 68 super(name) 69 end 70 71 # Load the controller class or a parent module. 72 def const_load!(name) 73 name = name.to_s if name.kind_of? Symbol 74 75 if File.directory? filesystem_path(name.underscore) 76 # Is it a submodule? If so, create a new LoadingModule *before* loading it. 77 # This ensures that subitems will be loadable 78 new_module = LoadingModule.new(@filesystem_root, self.path + [name.underscore]) 79 const_set(name, new_module) 80 Object.const_set(name, new_module) if @path.empty? 81 end 82 83 source_file = filesystem_path("#{(name == 'ApplicationController' ? 'Application' : name).underscore}.rb") 84 self.load_file(source_file) if File.file?(source_file) 85 self.const_defined?(name.camelize) 86 end 87 88 # Is this name present or loadable? 89 # This method is used by Routes to find valid controllers. 90 def const_available?(name) 91 name = name.to_s unless name.kind_of? String 92 File.directory?(filesystem_path(name.underscore)) || File.file?(filesystem_path("#{name.underscore}.rb")) 93 end 94 95 def clear 96 constants.each do |name| 97 Object.send(:remove_const, name) if Object.const_defined?(name) && @path.empty? 98 self.send(:remove_const, name) 99 end 100 end 101 102 def load_file(file_path) 103 Controllers.module_eval(IO.read(file_path), file_path, 1) # Hard coded Controller line here!!! 104 end 105 end 44 106 end 45 107 … … 53 115 # require_association when using single-table inheritance. 54 116 def const_missing(class_id) 117 if Object.const_defined?(:Controllers) and Object::Controllers.const_available?(class_id) 118 return Object::Controllers.const_get(class_id) 119 end 55 120 begin 56 121 require_or_load(class_id.to_s.demodulize.underscore) trunk/activesupport/lib/inflector.rb
r525 r614 21 21 22 22 def camelize(lower_case_and_underscored_word) 23 lower_case_and_underscored_word.to_s.gsub(/ (^|_)(.)/){$2.upcase}23 lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } 24 24 end 25 25 26 26 def underscore(camel_cased_word) 27 camel_cased_word.to_s.gsub(/ ([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase27 camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase 28 28 end 29 29 … … 48 48 (separate_class_name_and_id_with_underscore ? "_id" : "id") 49 49 end 50 50 51 def constantize(camel_cased_word) 52 camel_cased_word.split("::").inject(Object) do |final_type, part| 53 final_type = final_type.const_get(part) 54 end 55 end 56 51 57 private 52 58 def plural_rules #:doc: trunk/activesupport/test/inflector_test.rb
r449