Permalink
Browse files

merge with local tweaks

  • Loading branch information...
2 parents a14cedc + fc89a95 commit 0a6d75dedd79407376aae1f01302164dfd3e44b6 @technoweenie technoweenie committed Jul 16, 2008
Showing with 2,368 additions and 817 deletions.
  1. +1 −1 actionmailer/lib/action_mailer/base.rb
  2. +1 −2 actionmailer/test/abstract_unit.rb
  3. +15 −4 actionpack/CHANGELOG
  4. +12 −5 actionpack/lib/action_controller/assertions/response_assertions.rb
  5. +15 −15 actionpack/lib/action_controller/base.rb
  6. +28 −3 actionpack/lib/action_controller/filters.rb
  7. +1 −1 actionpack/lib/action_controller/layout.rb
  8. +43 −39 actionpack/lib/action_controller/mime_type.rb
  9. +8 −4 actionpack/lib/action_controller/request.rb
  10. +4 −0 actionpack/lib/action_controller/routing.rb
  11. +4 −15 actionpack/lib/action_controller/test_process.rb
  12. +4 −4 actionpack/lib/action_view.rb
  13. +65 −38 actionpack/lib/action_view/base.rb
  14. +42 −14 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  15. +1 −2 actionpack/lib/action_view/helpers/cache_helper.rb
  16. +1 −2 actionpack/lib/action_view/helpers/capture_helper.rb
  17. +4 −4 actionpack/lib/action_view/helpers/form_options_helper.rb
  18. +6 −3 actionpack/lib/action_view/helpers/prototype_helper.rb
  19. +1 −1 actionpack/lib/action_view/helpers/text_helper.rb
  20. +3 −5 actionpack/lib/action_view/helpers/url_helper.rb
  21. +8 −5 actionpack/lib/action_view/inline_template.rb
  22. +0 −69 actionpack/lib/action_view/partial_template.rb
  23. +21 −22 actionpack/lib/action_view/partials.rb
  24. +96 −0 actionpack/lib/action_view/paths.rb
  25. +61 −21 actionpack/lib/action_view/renderable.rb
  26. +36 −0 actionpack/lib/action_view/renderable_partial.rb
  27. +68 −54 actionpack/lib/action_view/template.rb
  28. +1 −1 actionpack/lib/action_view/template_error.rb
  29. +0 −88 actionpack/lib/action_view/template_file.rb
  30. +1 −1 actionpack/lib/action_view/template_handler.rb
  31. +2 −1 actionpack/lib/action_view/template_handlers/builder.rb
  32. +2 −52 actionpack/lib/action_view/template_handlers/compilable.rb
  33. +1 −1 actionpack/lib/action_view/template_handlers/rjs.rb
  34. +0 −103 actionpack/lib/action_view/view_load_paths.rb
  35. +3 −1 actionpack/test/abstract_unit.rb
  36. +9 −8 actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  37. +3 −11 actionpack/test/controller/action_pack_assertions_test.rb
  38. +0 −2 actionpack/test/controller/addresses_render_test.rb
  39. +11 −3 actionpack/test/controller/caching_test.rb
  40. +0 −2 actionpack/test/controller/capture_test.rb
  41. +1 −3 actionpack/test/controller/content_type_test.rb
  42. +0 −2 actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
  43. +3 −2 actionpack/test/controller/layout_test.rb
  44. +0 −2 actionpack/test/controller/mime_responds_test.rb
  45. +5 −3 actionpack/test/controller/new_render_test.rb
  46. +5 −0 actionpack/test/controller/redirect_test.rb
  47. +0 −3 actionpack/test/controller/render_test.rb
  48. +15 −17 actionpack/test/controller/resources_test.rb
  49. +0 −2 actionpack/test/controller/send_file_test.rb
  50. +0 −16 actionpack/test/controller/view_paths_test.rb
  51. +1 −0 actionpack/test/fixtures/developers/_developer.erb
  52. +1 −0 actionpack/test/fixtures/fun/games/_game.erb
  53. +1 −0 actionpack/test/fixtures/fun/serious/games/_game.erb
  54. +2 −0 actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb
  55. +1 −0 actionpack/test/fixtures/projects/_project.erb
  56. +1 −0 actionpack/test/fixtures/public/javascripts/subdir/subdir.js
  57. +1 −0 actionpack/test/fixtures/public/stylesheets/subdir/subdir.css
  58. +1 −0 actionpack/test/fixtures/replies/_reply.erb
  59. +1 −0 actionpack/test/fixtures/test/hyphen-ated.erb
  60. +43 −0 actionpack/test/template/asset_tag_helper_test.rb
  61. +907 −22 actionpack/test/template/form_options_helper_test.rb
  62. +2 −2 actionpack/test/template/prototype_helper_test.rb
  63. +5 −6 actionpack/test/template/render_test.rb
  64. +11 −9 actionpack/test/template/url_helper_test.rb
  65. +22 −0 activerecord/CHANGELOG
  66. +12 −3 activerecord/lib/active_record/association_preload.rb
  67. +20 −9 activerecord/lib/active_record/associations.rb
  68. +13 −4 activerecord/lib/active_record/associations/association_collection.rb
  69. +2 −2 activerecord/lib/active_record/associations/has_many_association.rb
  70. +8 −6 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  71. +31 −9 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  72. +13 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  73. +12 −0 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  74. +4 −3 activerecord/lib/active_record/fixtures.rb
  75. +2 −1 activerecord/lib/active_record/named_scope.rb
  76. +13 −2 activerecord/lib/active_record/test_case.rb
  77. +1 −1 activerecord/lib/active_record/validations.rb
  78. +6 −0 activerecord/test/cases/adapter_test.rb
  79. +31 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  80. +108 −0 activerecord/test/cases/associations_test.rb
  81. +36 −0 activerecord/test/cases/column_definition_test.rb
  82. +29 −0 activerecord/test/cases/fixtures_test.rb
  83. +5 −5 activerecord/test/cases/helper.rb
  84. +7 −0 activerecord/test/cases/inheritance_test.rb
  85. +56 −1 activerecord/test/cases/migration_test.rb
  86. +26 −0 activerecord/test/cases/named_scope_test.rb
  87. +6 −5 activerecord/test/cases/validations_test.rb
  88. +1 −1 activerecord/test/models/author.rb
  89. +6 −0 activerecord/test/models/post.rb
  90. +2 −0 activerecord/test/models/topic.rb
  91. +10 −0 activesupport/CHANGELOG
  92. +1 −0 activesupport/lib/active_support.rb
  93. +45 −2 activesupport/lib/active_support/core_ext/array/grouping.rb
  94. +18 −7 activesupport/lib/active_support/core_ext/module/introspection.rb
  95. +1 −1 activesupport/lib/active_support/core_ext/object/instance_variables.rb
  96. +2 −2 activesupport/lib/active_support/dependencies.rb
  97. +1 −1 activesupport/lib/active_support/json/encoders/date_time.rb
  98. +35 −0 activesupport/lib/active_support/memoizable.rb
  99. +1 −1 activesupport/lib/active_support/time_with_zone.rb
  100. +46 −4 activesupport/test/core_ext/array_ext_test.rb
  101. +6 −0 activesupport/test/core_ext/time_with_zone_test.rb
  102. +49 −0 activesupport/test/memoizable_test.rb
  103. +0 −1 cleanlogs.sh
  104. +5 −0 railties/CHANGELOG
  105. +2 −0 railties/configs/routes.rb
  106. +1 −0 railties/helpers/performance_test_helper.rb
  107. +32 −15 railties/lib/commands/plugin.rb
  108. +1 −1 railties/lib/console_with_helpers.rb
  109. +1 −1 railties/lib/initializer.rb
  110. +1 −1 railties/lib/rails/plugin/locator.rb
  111. +9 −16 railties/lib/rails_generator/commands.rb
  112. +1 −1 railties/lib/rails_generator/lookup.rb
  113. +20 −14 railties/lib/tasks/databases.rake
  114. +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,14 +1,25 @@
*Edge*
-* Disable the Accept header by default [Michael Koziarski]
+* 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
- should use formatted urls (e.g. /people/1.xml) to support API clients.
+ can use formatted urls (e.g. /people/1.xml) to support API clients in a
+ much simpler way.
- Alternatively to re-enable it you need to set:
+ To disable the header you need to set:
- config.action_controller.use_accept_header = true
+ 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]
@@ -63,11 +63,18 @@ def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
+
+ # 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 options_after_normalisation, redirected_to_after_normalisation,
- "Expected response to be a redirect to <#{options_after_normalisation}> but was a redirect to <#{redirected_to_after_normalisation}>"
+ 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
@@ -80,13 +87,13 @@ def assert_redirected_to(options = {}, message=nil)
#
def assert_template(expected = nil, message=nil)
clean_backtrace do
- rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
+ rendered = @response.rendered_template
msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
assert_block(msg) do
if expected.nil?
- !@response.rendered_with_file?
+ @response.rendered_template.nil?
else
- expected == rendered
+ rendered.to_s.match(expected)
end
end
end
@@ -343,12 +343,12 @@ class Base
# 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+ then +respond_to+ and +Request#format+ will take the Accept header into
- # account. If it is set to false (the default) then the request format will be determined solely
+ # 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 = false
+ 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
@@ -412,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.
@@ -613,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
@@ -651,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.
@@ -1200,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
@@ -1247,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)
@@ -94,7 +94,7 @@ def update_filter_in_chain(filters, options, &test)
map! do |filter|
if filters.include?(filter)
new_filter = filter.dup
- new_filter.options.merge!(options)
+ new_filter.update_options!(options)
new_filter
else
filter
@@ -104,6 +104,11 @@ def update_filter_in_chain(filters, options, &test)
end
class Filter < ActiveSupport::Callbacks::Callback #:nodoc:
+ def initialize(kind, method, options = {})
+ super
+ update_options! options
+ end
+
def before?
self.class == BeforeFilter
end
@@ -116,6 +121,18 @@ def around?
self.class == AroundFilter
end
+ # Make sets of strings from :only/:except options
+ def update_options!(other)
+ if other
+ convert_only_and_except_options_to_sets_of_strings(other)
+ if other[:skip]
+ convert_only_and_except_options_to_sets_of_strings(other[:skip])
+ end
+ end
+
+ options.update(other)
+ end
+
private
def should_not_skip?(controller)
if options[:skip]
@@ -127,9 +144,9 @@ def should_not_skip?(controller)
def included_in_action?(controller, options)
if options[:only]
- Array(options[:only]).map(&:to_s).include?(controller.action_name)
+ options[:only].include?(controller.action_name)
elsif options[:except]
- !Array(options[:except]).map(&:to_s).include?(controller.action_name)
+ !options[:except].include?(controller.action_name)
else
true
end
@@ -138,6 +155,14 @@ def included_in_action?(controller, options)
def should_run_callback?(controller)
should_not_skip?(controller) && included_in_action?(controller, options) && super
end
+
+ def convert_only_and_except_options_to_sets_of_strings(opts)
+ [:only, :except].each do |key|
+ if values = opts[key]
+ opts[key] = Array(values).map(&:to_s).to_set
+ end
+ end
+ end
end
class AroundFilter < Filter #:nodoc:
@@ -304,7 +304,7 @@ def action_has_layout?
end
def layout_directory?(layout_name)
- @template.view_paths.find_template_file_for_path("#{File.join('layouts', layout_name)}.#{@template.template_format}.erb") ? true : false
+ @template.file_exists?("#{File.join('layouts', layout_name)}.#{@template.template_format}")
end
end
end
@@ -72,57 +72,61 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
end
def parse(accept_header)
- # keep track of creation order to keep the subsequent sort stable
- list = []
- accept_header.split(/,/).each_with_index do |header, index|
- params, q = header.split(/;\s*q=/)
- if params
- params.strip!
- list << AcceptItem.new(index, params, q) unless params.empty?
+ if accept_header !~ /,/
+ [Mime::Type.lookup(accept_header)]
+ else
+ # keep track of creation order to keep the subsequent sort stable
+ list = []
+ accept_header.split(/,/).each_with_index do |header, index|
+ params, q = header.split(/;\s*q=/)
+ if params
+ params.strip!
+ list << AcceptItem.new(index, params, q) unless params.empty?
+ end
end
- end
- list.sort!
+ list.sort!
- # Take care of the broken text/xml entry by renaming or deleting it
- text_xml = list.index("text/xml")
- app_xml = list.index(Mime::XML.to_s)
+ # Take care of the broken text/xml entry by renaming or deleting it
+ text_xml = list.index("text/xml")
+ app_xml = list.index(Mime::XML.to_s)
- if text_xml && app_xml
- # set the q value to the max of the two
- list[app_xml].q = [list[text_xml].q, list[app_xml].q].max
+ if text_xml && app_xml
+ # set the q value to the max of the two
+ list[app_xml].q = [list[text_xml].q, list[app_xml].q].max
- # make sure app_xml is ahead of text_xml in the list
- if app_xml > text_xml
- list[app_xml], list[text_xml] = list[text_xml], list[app_xml]
- app_xml, text_xml = text_xml, app_xml
- end
+ # make sure app_xml is ahead of text_xml in the list
+ if app_xml > text_xml
+ list[app_xml], list[text_xml] = list[text_xml], list[app_xml]
+ app_xml, text_xml = text_xml, app_xml
+ end
- # delete text_xml from the list
- list.delete_at(text_xml)
+ # delete text_xml from the list
+ list.delete_at(text_xml)
- elsif text_xml
- list[text_xml].name = Mime::XML.to_s
- end
+ elsif text_xml
+ list[text_xml].name = Mime::XML.to_s
+ end
- # Look for more specific XML-based types and sort them ahead of app/xml
+ # Look for more specific XML-based types and sort them ahead of app/xml
- if app_xml
- idx = app_xml
- app_xml_type = list[app_xml]
+ if app_xml
+ idx = app_xml
+ app_xml_type = list[app_xml]
- while(idx < list.length)
- type = list[idx]
- break if type.q < app_xml_type.q
- if type.name =~ /\+xml$/
- list[app_xml], list[idx] = list[idx], list[app_xml]
- app_xml = idx
+ while(idx < list.length)
+ type = list[idx]
+ break if type.q < app_xml_type.q
+ if type.name =~ /\+xml$/
+ list[app_xml], list[idx] = list[idx], list[app_xml]
+ app_xml = idx
+ end
+ idx += 1
end
- idx += 1
end
- end
- list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
- list
+ list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
+ list
+ end
end
end
@@ -82,10 +82,14 @@ def content_type
# Returns the accepted MIME type for the request
def accepts
@accepts ||=
- if @env['HTTP_ACCEPT'].to_s.strip.empty?
- [ content_type, Mime::ALL ].compact # make sure content_type being nil is not included
- else
- Mime::Type.parse(@env['HTTP_ACCEPT'])
+ begin
+ header = @env['HTTP_ACCEPT'].to_s.strip
+
+ if header.empty?
+ [content_type, Mime::ALL].compact
+ else
+ Mime::Type.parse(header)
+ end
end
end
@@ -88,6 +88,10 @@ module ActionController
#
# map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' }
#
+ # Note: The default routes, as provided by the Rails generator, make all actions in every
+ # controller accessible via GET requests. You should consider removing them or commenting
+ # them out if you're using named routes and resources.
+ #
# == Named routes
#
# Routes can be named with the syntax <tt>map.name_of_route options</tt>,
Oops, something went wrong.

0 comments on commit 0a6d75d

Please sign in to comment.