Changeset 617
- Timestamp:
- 02/15/05 01:45:35 (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) (7 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) (3 diffs)
- trunk/actionpack/lib/action_controller/routing.rb (copied) (copied from branches/routing/actionpack/lib/action_controller/routing.rb)
- 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) (5 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/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/configs/routes.rb (copied) (copied from branches/routing/railties/configs/routes.rb)
- 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/lib/webrick_server.rb (modified) (4 diffs)
- trunk/railties/Rakefile (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
r616 r617 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.clone 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(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
r616 r617 1 1 require 'action_controller/request' 2 2 require 'action_controller/response' 3 require 'action_controller/routing' 3 4 require 'action_controller/url_rewriter' 4 5 require 'action_controller/support/class_attribute_accessors' … … 13 14 end 14 15 class MissingTemplate < ActionControllerError #:nodoc: 16 end 17 class RoutingError < ActionControllerError 18 attr_reader :failures 19 def initialize(message, failures=[]) 20 super(message) 21 @failures = failures 22 end 23 end 24 class UnknownController < ActionControllerError #:nodoc: 15 25 end 16 26 class UnknownAction < ActionControllerError #:nodoc: … … 206 216 @@consider_all_requests_local = true 207 217 cattr_accessor :consider_all_requests_local 218 219 # Enable or disable the collection of failure information for RoutingErrors. 220 # This information can be extremely useful when tweaking custom routes, but is 221 # pointless once routes have been tested and verified. 222 @@debug_routes = true 223 cattr_accessor :debug_routes 208 224 209 225 # Template root determines the base from which template references will be made. So a call to render("test/template") … … 261 277 def controller_name 262 278 Inflector.underscore(controller_class_name.sub(/Controller/, "")) 279 end 280 281 # Convert the class name from something like "OneModule::TwoModule::NeatController" to "one_module/two_module/neat". 282 def controller_path 283 components = self.name.to_s.split('::').collect { |name| name.underscore } 284 components[-1] = $1 if /^(.*)_controller$/ =~ components[-1] 285 components.shift if components.first == 'controllers' # Transitional conditional to accomodate root Controllers module 286 components.join('/') 263 287 end 264 288 end … … 336 360 when Hash then @url.rewrite(rewrite_options(options)) 337 361 end 338 end339 340 def module_name341 @params["module"]342 362 end 343 363 … … 595 615 596 616 def initialize_current_url 597 @url = UrlRewriter.new(@request, controller_name, action_name)617 @url = UrlRewriter.new(@request, @params.clone()) 598 618 end 599 619 … … 692 712 693 713 def default_template_name(default_action_name = action_name) 694 module_name ? "#{module_name}/#{controller_name}/#{default_action_name}" : "#{controller_name}/#{default_action_name}"714 "#{self.class.controller_path}/#{default_action_name}" 695 715 end 696 716 end trunk/actionpack/lib/action_controller/cgi_process.rb
r616 r617 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
r616 r617 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
r616 r617 4 4 # Returns both GET and POST parameters in a single hash. 5 5 def parameters 6 @parameters ||= request_parameters.update(query_parameters) 6 # puts "#{request_parameters.inspect} | #{query_parameters.inspect} | #{path_parameters.inspect}" 7 @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access 7 8 end 8 9 … … 74 75 75 76 def request_uri 76 env['REQUEST_URI']77 (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri. 77 78 end 78 79 … … 86 87 87 88 def path 88 request_uri ? request_uri.split('?').first : ''89 path = request_uri ? request_uri.split('?').first : '' 89 90 end 90 91 … … 101 102 env['HTTP_HOST'] || host + port_string 102 103 end 104 105 def path_parameters=(parameters) 106 @path_parameters = parameters 107 @parameters = nil 108 end 103 109 110 def path_parameters 111 @path_parameters ||= {} 112 end 113 104 114 #-- 105 115 # Must be implemented in the concrete request trunk/actionpack/lib/action_controller/rescue.rb
r616 r617 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 … … 67 71 68 72 @headers["Content-Type"] = "text/html" 69 render_file(rescues_path("layout"), "500 Internal Error")73 render_file(rescues_path("layout"), response_code_for_rescue(exception)) 70 74 end 71 75 … … 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
r616 r617 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
r616 r617 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
r616 r617 1 1 module ActionController 2 2 # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. 3 3 4 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 5 RESERVED_OPTIONS = [:anchor, :params, :path_params, :only_path, :host, :protocol] 6 def initialize(request, parameters) 7 @request, @parameters = request, parameters 8 8 @rewritten_path = @request.path ? @request.path.dup : "" 9 9 end 10 10 11 11 def rewrite(options = {}) 12 validate_options(VALID_OPTIONS, options.keys) 13 14 rewrite_url( 15 rewrite_path(@rewritten_path, resolve_aliases(options)), 16 options 17 ) 18 end 19 20 def to_s 21 to_str 12 rewrite_url(rewrite_path(options), options) 22 13 end 23 14 24 15 def to_str 25 "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@controller}, #{@action}, #{@request.parameters.inspect}"16 "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@parameters[:controller]}, #{@parameters[:action]}, #{@request.parameters.inspect}" 26 17 end 18 19 alias_method :to_s, :to_str 27 20 28 21 private … … 31 24 raise(ActionController::ActionControllerError, "Unknown options: #{unknown_option_keys}") unless unknown_option_keys.empty? 32 25 end 33 34 def resolve_aliases(options) 35 options[:controller_prefix] = options[:module] unless options[:module].nil? 36 options 37 end 38 26 39 27 def rewrite_url(path, options) 40 28 rewritten_url = "" … … 46 34 rewritten_url << build_query_string(new_parameters(options)) if options[:params] || options[:overwrite_params] 47 35 rewritten_url << "##{options[:anchor]}" if options[:anchor] 36 48 37 return rewritten_url 49 38 end 50 39 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] 40 def rewrite_path(options) 41 options = options.symbolize_keys 42 RESERVED_OPTIONS.each {|k| options.delete k} 43 44 path, extras = Routing::Routes.generate(options, @request) 45 path = "/#{path.join('/')}" 46 path += build_query_string(extras) 47 57 48 return path 58 49 end … … 75 66 end 76 67 end 77 end78 79 def rewrite_action(path, options)80 # This regex assumes that "index" actions won't be included in the URL81 all, controller_prefix, action_prefix, action_suffix =82 /^\/(.*)#{@controller}\/(.*)#{@action == "index" ? "" : @action}(.*)/.match(path).to_a83 84 if @action == "index"85 if action_prefix == "index"86 # we broke the parsing assumption that this would be excluded, so87 # don't tell action_name about our little boo-boo88 path = path.sub(action_prefix, action_name(options, nil))89 elsif action_prefix && !action_prefix.empty?90 path = path.sub(%r(/#{action_prefix}/?), "/" + action_name(options, action_prefix))91 else92 path = path.sub(%r(#{@controller}/?$), @controller + "/" + action_name(options)) # " ruby-mode93 end94 else95 path = path.sub(96 @controller + "/" + (action_prefix || "") + @action + (action_suffix || ""),97 @controller + "/" + action_name(options, action_prefix)98 )99 end100 101 if options[:controller_prefix] && !options[:controller]102 ensure_slash_suffix(options, :controller_prefix)103 if controller_prefix104 path = path.sub(controller_prefix, options[:controller_prefix])105 else106 path = options[:controller_prefix] + path107 end108 end109 110 return path111 end112 113 def rewrite_controller(path, options)114 all, controller_prefix = /^\/(.*?)#{@controller}/.match(path).to_a115 path = "/"116 path << controller_name(options, controller_prefix)117 path << action_name(options) if options[:action]118 path << path_params_in_list(options) if options[:path_params]119 return path120 68 end 121 69 … … 175 123 elements = [] 176 124 query_string = "" 177 125 178 126 hash.each do |key, value| 127 key = key.to_s 179 128 key = CGI.escape key 180 129 key += '[]' if value.class == Array 181 130 value = [ value ] unless value.class == Array 182 131 value.each { |val| elements << "#{key}=#{CGI.escape(val.to_s)}" } 183 end 184 185 unless elements.empty? then query_string << ("?" + elements.join("&")) end 132 end 186 133 134 query_string << ("?" + elements.join("&")) unless elements.empty? 187 135 return query_string 188 136 end trunk/actionpack/lib/action_view/partials.rb
r616 r617 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
r616 r617 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
r616 r617 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
r616 r617 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
r616 r617 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
r616 r617 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
r616 r617 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 &nb