Permalink
Browse files

Merge commit 'mainstream/master'

Conflicts:

	actionpack/lib/action_controller/base.rb
	railties/lib/rails_generator/commands.rb
  • Loading branch information...
lifo committed Jul 12, 2008
2 parents ef67bd4 + 99cc85b commit 0cfa3574d599f3bc134cd13fa00d8f22809dd67b
Showing with 1,243 additions and 1,203 deletions.
  1. +1 −1 actionmailer/lib/action_mailer/base.rb
  2. +1 −2 actionmailer/test/abstract_unit.rb
  3. +39 −0 actionpack/CHANGELOG
  4. +27 −76 actionpack/lib/action_controller/assertions/response_assertions.rb
  5. +40 −28 actionpack/lib/action_controller/base.rb
  6. +12 −11 actionpack/lib/action_controller/caching/actions.rb
  7. +229 −197 actionpack/lib/action_controller/filters.rb
  8. +1 −1 actionpack/lib/action_controller/layout.rb
  9. +5 −1 actionpack/lib/action_controller/mime_responds.rb
  10. +43 −39 actionpack/lib/action_controller/mime_type.rb
  11. +33 −13 actionpack/lib/action_controller/request.rb
  12. +4 −0 actionpack/lib/action_controller/routing.rb
  13. +3 −16 actionpack/lib/action_controller/test_process.rb
  14. +4 −4 actionpack/lib/action_view.rb
  15. +67 −51 actionpack/lib/action_view/base.rb
  16. +42 −14 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  17. +1 −1 actionpack/lib/action_view/helpers/cache_helper.rb
  18. +1 −2 actionpack/lib/action_view/helpers/capture_helper.rb
  19. +5 −2 actionpack/lib/action_view/helpers/date_helper.rb
  20. +6 −3 actionpack/lib/action_view/helpers/prototype_helper.rb
  21. +1 −1 actionpack/lib/action_view/helpers/text_helper.rb
  22. +3 −5 actionpack/lib/action_view/helpers/url_helper.rb
  23. +10 −7 actionpack/lib/action_view/inline_template.rb
  24. +0 −69 actionpack/lib/action_view/partial_template.rb
  25. +36 −22 actionpack/lib/action_view/partials.rb
  26. +96 −0 actionpack/lib/action_view/paths.rb
  27. +79 −0 actionpack/lib/action_view/renderable.rb
  28. +19 −0 actionpack/lib/action_view/renderable_partial.rb
  29. +0 −29 actionpack/lib/action_view/renderer.rb
  30. +84 −51 actionpack/lib/action_view/template.rb
  31. +2 −2 actionpack/lib/action_view/template_error.rb
  32. +0 −88 actionpack/lib/action_view/template_file.rb
  33. +1 −9 actionpack/lib/action_view/template_handler.rb
  34. +4 −9 actionpack/lib/action_view/template_handlers/builder.rb
  35. +2 −116 actionpack/lib/action_view/template_handlers/compilable.rb
  36. +2 −6 actionpack/lib/action_view/template_handlers/rjs.rb
  37. +0 −103 actionpack/lib/action_view/view_load_paths.rb
  38. +3 −1 actionpack/test/abstract_unit.rb
  39. +9 −8 actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  40. +4 −30 actionpack/test/controller/action_pack_assertions_test.rb
  41. +0 −2 actionpack/test/controller/addresses_render_test.rb
  42. +14 −12 actionpack/test/controller/caching_test.rb
  43. +0 −2 actionpack/test/controller/capture_test.rb
  44. +1 −1 actionpack/test/controller/components_test.rb
  45. +14 −2 actionpack/test/controller/content_type_test.rb
  46. +0 −2 actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
  47. +4 −3 actionpack/test/controller/layout_test.rb
  48. +5 −2 actionpack/test/controller/mime_responds_test.rb
  49. +5 −3 actionpack/test/controller/new_render_test.rb
  50. +8 −16 actionpack/test/controller/redirect_test.rb
  51. +0 −3 actionpack/test/controller/render_test.rb
  52. +1 −1 actionpack/test/controller/request_test.rb
  53. +15 −17 actionpack/test/controller/resources_test.rb
  54. +0 −2 actionpack/test/controller/send_file_test.rb
  55. +0 −18 actionpack/test/controller/test_test.rb
  56. +0 −16 actionpack/test/controller/view_paths_test.rb
  57. +1 −0 actionpack/test/fixtures/developers/_developer.erb
  58. +1 −0 actionpack/test/fixtures/fun/games/_game.erb
  59. +1 −0 actionpack/test/fixtures/fun/serious/games/_game.erb
  60. +1 −0 actionpack/test/fixtures/projects/_project.erb
  61. +1 −0 actionpack/test/fixtures/public/javascripts/subdir/subdir.js
  62. +1 −0 actionpack/test/fixtures/public/stylesheets/subdir/subdir.css
  63. +1 −0 actionpack/test/fixtures/replies/_reply.erb
  64. +1 −0 actionpack/test/fixtures/test/hyphen-ated.erb
  65. +43 −0 actionpack/test/template/asset_tag_helper_test.rb
  66. +15 −0 actionpack/test/template/date_helper_test.rb
  67. +2 −2 actionpack/test/template/prototype_helper_test.rb
  68. +9 −10 actionpack/test/template/render_test.rb
  69. +11 −9 actionpack/test/template/url_helper_test.rb
  70. +5 −0 activerecord/CHANGELOG
  71. +7 −5 activerecord/lib/active_record/associations.rb
  72. +1 −1 activerecord/lib/active_record/associations/association_collection.rb
  73. +10 −2 activerecord/lib/active_record/associations/has_many_association.rb
  74. +10 −1 activerecord/lib/active_record/associations/has_one_association.rb
  75. +1 −1 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  76. +5 −2 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  77. +2 −1 activerecord/lib/active_record/named_scope.rb
  78. +11 −7 activerecord/lib/active_record/validations.rb
  79. +4 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  80. +7 −0 activerecord/test/cases/associations/has_one_associations_test.rb
  81. +26 −0 activerecord/test/cases/named_scope_test.rb
  82. +3 −3 activerecord/test/cases/reflection_test.rb
  83. +18 −5 activerecord/test/cases/validations_test.rb
  84. +1 −0 activerecord/test/fixtures/companies.yml
  85. +3 −0 activerecord/test/models/company.rb
  86. +2 −0 activerecord/test/models/topic.rb
  87. +1 −0 activerecord/test/schema/schema.rb
  88. +2 −0 activesupport/CHANGELOG
  89. +1 −1 activesupport/lib/active_support/core_ext/module/introspection.rb
  90. +1 −1 activesupport/lib/active_support/core_ext/object/instance_variables.rb
  91. +0 −1 activesupport/lib/active_support/core_ext/test.rb
  92. +2 −2 activesupport/lib/active_support/dependencies.rb
  93. +1 −5 activesupport/lib/active_support/test_case.rb
  94. +6 −0 activesupport/lib/active_support/testing/core_ext/test.rb
  95. +4 −3 activesupport/lib/active_support/{ → testing}/core_ext/test/unit/assertions.rb
  96. +2 −0 railties/configs/routes.rb
  97. +1 −1 railties/lib/console_with_helpers.rb
  98. +1 −1 railties/lib/initializer.rb
  99. +1 −1 railties/lib/rails/plugin/locator.rb
  100. +9 −16 railties/lib/rails_generator/commands.rb
  101. +1 −1 railties/lib/rails_generator/lookup.rb
  102. +1 −1 railties/lib/tasks/misc.rake
  103. +19 −0 railties/test/generators/rails_controller_generator_test.rb
@@ -426,7 +426,7 @@ def register_template_extension(extension)
end
def template_root=(root)
- write_inheritable_attribute(:template_root, ActionView::ViewLoadPaths.new(Array(root)))
+ write_inheritable_attribute(:template_root, ActionView::PathSet.new(Array(root)))
end
end
@@ -32,8 +32,7 @@ def self.start(*args)
# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
- gem 'mocha', ">=0.5"
- require 'stubba'
+ gem 'mocha', ">=0.9.0"
yield
rescue Gem::LoadError
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
View
@@ -1,5 +1,34 @@
*Edge*
+* Set config.action_view.warn_cache_misses = true to receive a warning if you perform an action that results in an expensive disk operation that could be cached [Josh Peek]
+
+* Refactor template preloading. New abstractions include Renderable mixins and a refactored Template class [Josh Peek]
+
+* Changed ActionView::TemplateHandler#render API method signature to render(template, local_assigns = {}) [Josh Peek]
+
+* Changed PrototypeHelper#submit_to_remote to PrototypeHelper#button_to_remote to stay consistent with link_to_remote (submit_to_remote still works as an alias) #8994 [clemens]
+
+* Add :recursive option to javascript_include_tag and stylesheet_link_tag to be used along with :all. #480 [Damian Janowski]
+
+* Allow users to disable the use of the Accept header [Michael Koziarski]
+
+ The accept header is poorly implemented by browsers and causes strange
+ errors when used on public sites where crawlers make requests too. You
+ can use formatted urls (e.g. /people/1.xml) to support API clients in a
+ much simpler way.
+
+ To disable the header you need to set:
+
+ config.action_controller.use_accept_header = false
+
+* Do not stat template files in production mode before rendering. You will no longer be able to modify templates in production mode without restarting the server [Josh Peek]
+
+* Deprecated TemplateHandler line offset [Josh Peek]
+
+* Allow caches_action to accept cache store options. #416. [José Valim]. Example:
+
+ caches_action :index, :redirected, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
+
* Remove define_javascript_functions, javascript_include_tag and friends are far superior. [Michael Koziarski]
* Deprecate :use_full_path render option. The supplying the option no longer has an effect [Josh Peek]
@@ -14,6 +43,16 @@
* Made ActionView::Base#render_file private [Josh Peek]
+* Refactor and simplify the implementation of assert_redirected_to. Arguments are now normalised relative to the controller being tested, not the root of the application. [Michael Koziarski]
+
+ This could cause some erroneous test failures if you were redirecting between controllers
+ in different namespaces and wrote your assertions relative to the root of the application.
+
+* Remove follow_redirect from controller functional tests.
+
+ If you want to follow redirects you can use integration tests. The functional test
+ version was only useful if you were using redirect_to :id=>...
+
* Fix polymorphic_url with singleton resources. #461 [Tammer Saleh]
* Replaced TemplateFinder abstraction with ViewLoadPaths [Josh Peek]
@@ -56,74 +56,24 @@ def assert_response(type, message = nil)
# # assert that the redirection was to the named route login_url
# assert_redirected_to login_url
#
+ # # assert that the redirection was to the url for @customer
+ # assert_redirected_to @customer
+ #
def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
-
- begin
- url = {}
- original = { :expected => options, :actual => @response.redirected_to.is_a?(Symbol) ? @response.redirected_to : @response.redirected_to.dup }
- original.each do |key, value|
- if value.is_a?(Symbol)
- value = @controller.respond_to?(value, true) ? @controller.send(value) : @controller.send("hash_for_#{value}_url")
- end
-
- unless value.is_a?(Hash)
- request = case value
- when NilClass then nil
- when /^\w+:\/\// then recognized_request_for(%r{^(\w+://.*?(/|$|\?))(.*)$} =~ value ? $3 : nil)
- else recognized_request_for(value)
- end
- value = request.path_parameters if request
- end
-
- if value.is_a?(Hash) # stringify 2 levels of hash keys
- if name = value.delete(:use_route)
- route = ActionController::Routing::Routes.named_routes[name]
- value.update(route.parameter_shell)
- end
-
- value.stringify_keys!
- value.values.select { |v| v.is_a?(Hash) }.collect { |v| v.stringify_keys! }
- if key == :expected && value['controller'] == @controller.controller_name && original[:actual].is_a?(Hash)
- original[:actual].stringify_keys!
- value.delete('controller') if original[:actual]['controller'].nil? || original[:actual]['controller'] == value['controller']
- end
- end
-
- if value.respond_to?(:[]) && value['controller']
- value['controller'] = value['controller'].to_s
- if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
- new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
- value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) && @response.redirected_to.is_a?(Hash)
- end
- value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
- end
- url[key] = value
- end
-
- @response_diff = url[:actual].diff(url[:expected]) if url[:actual]
- msg = build_message(message, "expected a redirect to <?>, found one to <?>, a difference of <?> ", url[:expected], url[:actual], @response_diff)
-
- assert_block(msg) do
- url[:expected].keys.all? do |k|
- if k == :controller then url[:expected][k] == ActionController::Routing.controller_relative_to(url[:actual][k], @controller.class.controller_path)
- else parameterize(url[:expected][k]) == parameterize(url[:actual][k])
- end
- end
- end
- rescue ActionController::RoutingError # routing failed us, so match the strings only.
- msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url)
- url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$}
- eurl, epath, url, path = [options, @response.redirect_url].collect do |url|
- u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]
- [u, (p.first == '/') ? p : '/' + p]
- end.flatten
+
+ # Support partial arguments for hash redirections
+ if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
+ return true if options.all? {|(key, value)| @response.redirected_to[key] == value}
+ end
+
+ redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
+ options_after_normalisation = normalize_argument_to_redirection(options)
- assert_equal(eurl, url, msg) if eurl && url
- assert_equal(epath, path, msg) if epath && path
+ if redirected_to_after_normalisation != options_after_normalisation
+ flunk "Expected response to be a redirect to <#{options_after_normalisation}> but was a redirect to <#{redirected_to_after_normalisation}>"
end
end
end
@@ -143,30 +93,31 @@ def assert_template(expected = nil, message=nil)
if expected.nil?
!@response.rendered_with_file?
else
- expected == rendered
+ rendered.match(expected)
end
end
end
end
private
- # Recognizes the route for a given path.
- def recognized_request_for(path, request_method = nil)
- path = "/#{path}" unless path.first == '/'
-
- # Assume given controller
- request = ActionController::TestRequest.new({}, {}, nil)
- request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
- request.path = path
-
- ActionController::Routing::Routes.recognize(request)
- request
- end
# Proxy to to_param if the object will respond to it.
def parameterize(value)
value.respond_to?(:to_param) ? value.to_param : value
end
+
+ def normalize_argument_to_redirection(fragment)
+ after_routing = @controller.url_for(fragment)
+ if after_routing =~ %r{^\w+://.*}
+ after_routing
+ else
+ # FIXME - this should probably get removed.
+ if after_routing.first != '/'
+ after_routing = '/' + after_routing
+ end
+ @request.protocol + @request.host_with_port + after_routing
+ end
+ end
end
end
end
@@ -340,7 +340,17 @@ class Base
cattr_accessor :optimise_named_routes
self.optimise_named_routes = true
- # Controls whether request forgery protection is turned on or not. Turned off by default only in test mode.
+ # Indicates whether the response format should be determined by examining the Accept HTTP header,
+ # or by using the simpler params + ajax rules.
+ #
+ # If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept
+ # header into account. If it is set to false then the request format will be determined solely
+ # by examining params[:format]. If params format is missing, the format will be either HTML or
+ # Javascript depending on whether the request is an AJAX request.
+ cattr_accessor :use_accept_header
+ self.use_accept_header = true
+
+ # Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode.
class_inheritable_accessor :allow_forgery_protection
self.allow_forgery_protection = true
@@ -402,26 +412,26 @@ def controller_path
# More methods can be hidden using <tt>hide_actions</tt>.
def hidden_actions
unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s))
+ write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map { |m| m.to_s })
end
read_inheritable_attribute(:hidden_actions)
end
# Hide each of the given methods from being callable as actions.
def hide_action(*names)
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
+ write_inheritable_attribute(:hidden_actions, hidden_actions | names.map { |name| name.to_s })
end
- ## View load paths determine the bases from which template references can be made. So a call to
- ## render("test/template") will be looked up in the view load paths array and the closest match will be
- ## returned.
+ # View load paths determine the bases from which template references can be made. So a call to
+ # render("test/template") will be looked up in the view load paths array and the closest match will be
+ # returned.
def view_paths
@view_paths || superclass.view_paths
end
def view_paths=(value)
- @view_paths = ActionView::ViewLoadPaths.new(Array(value)) if value
+ @view_paths = ActionView::Base.process_view_paths(value) if value
end
# Adds a view_path to the front of the view_paths array.
@@ -603,7 +613,8 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
#
# This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action => 'print'</tt>
# would have slashed-off the path components after the changed action.
- def url_for(options = {}) #:doc:
+ def url_for(options = {})
+ options ||= {}
case options
when String
options
@@ -641,7 +652,7 @@ def view_paths
end
def view_paths=(value)
- @template.view_paths = ViewLoadPaths.new(value)
+ @template.view_paths = ActionView::Base.process_view_paths(value)
end
# Adds a view_path to the front of the view_paths array.
@@ -1042,29 +1053,31 @@ def redirect_to(options = {}, response_status = {}) #:doc:
status = 302
end
+ response.redirected_to= options
+ logger.info("Redirected to #{options}") if logger && logger.info?
+
case options
when %r{^\w+://.*}
- raise DoubleRenderError if performed?
- logger.info("Redirected to #{options}") if logger && logger.info?
- response.redirect(options, interpret_status(status))
- response.redirected_to = options
- @performed_redirect = true
-
+ redirect_to_full_url(options, status)
when String
- redirect_to(request.protocol + request.host_with_port + options, :status=>status)
-
+ redirect_to_full_url(request.protocol + request.host_with_port + options, status)
when :back
- request.env["HTTP_REFERER"] ? redirect_to(request.env["HTTP_REFERER"], :status=>status) : raise(RedirectBackError)
-
- when Hash
- redirect_to(url_for(options), :status=>status)
- response.redirected_to = options
-
+ if referer = request.headers["Referer"]
+ redirect_to(referer, :status=>status)
+ else
+ raise RedirectBackError
+ end
else
- redirect_to(url_for(options), :status=>status)
+ redirect_to_full_url(url_for(options), status)
end
end
+ def redirect_to_full_url(url, status)
+ raise DoubleRenderError if performed?
+ response.redirect(url, interpret_status(status))
+ @performed_redirect = true
+ end
+
# Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that
# intermediate caches shouldn't cache the response.
#
@@ -1188,7 +1201,7 @@ def action_methods
end
def self.action_methods
- @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions
+ @action_methods ||= Set.new(public_instance_methods.map { |m| m.to_s }) - hidden_actions
end
def add_variables_to_assigns
@@ -1235,9 +1248,8 @@ def template_public?(template_name = default_template_name)
end
def template_exempt_from_layout?(template_name = default_template_name)
- extension = @template && @template.pick_template_extension(template_name)
- name_with_extension = !template_name.include?('.') && extension ? "#{template_name}.#{extension}" : template_name
- @@exempt_from_layout.any? { |ext| name_with_extension =~ ext }
+ template_name = @template.pick_template(template_name).to_s if @template
+ @@exempt_from_layout.any? { |ext| template_name =~ ext }
end
def default_template_name(action_name = self.action_name)
Oops, something went wrong.

0 comments on commit 0cfa357

Please sign in to comment.