Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'rails/master'

  • Loading branch information...
commit b9088dce07f8525cdb84a1312a77b81db79067d6 2 parents 4864f92 + 4417a19
@miloops miloops authored
Showing with 813 additions and 698 deletions.
  1. +8 −0 actionpack/lib/action_controller/base/compatibility.rb
  2. +1 −4 actionpack/lib/action_controller/base/filter_parameter_logging.rb
  3. +21 −53 actionpack/lib/action_controller/base/flash.rb
  4. +1 −1  actionpack/lib/action_controller/base/http.rb
  5. +2 −5 actionpack/lib/action_controller/base/layouts.rb
  6. +2 −5 actionpack/lib/action_controller/base/mime_responds.rb
  7. +7 −11 actionpack/lib/action_controller/base/request_forgery_protection.rb
  8. +1 −4 actionpack/lib/action_controller/base/streaming.rb
  9. +1 −4 actionpack/lib/action_controller/base/verification.rb
  10. +5 −21 actionpack/lib/action_controller/caching/actions.rb
  11. +0 −3  actionpack/lib/action_controller/legacy/layout.rb
  12. +1 −2  actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb
  13. +13 −1 actionpack/lib/action_dispatch/http/mime_type.rb
  14. +4 −6 actionpack/lib/action_dispatch/http/request.rb
  15. +15 −14 actionpack/lib/action_view.rb
  16. +17 −38 actionpack/lib/action_view/base.rb
  17. +11 −48 actionpack/lib/action_view/helpers/active_record_helper.rb
  18. +24 −7 actionpack/lib/action_view/helpers/capture_helper.rb
  19. +1 −1  actionpack/lib/action_view/paths.rb
  20. +0 −7 actionpack/lib/action_view/render/partials.rb
  21. +48 −22 actionpack/lib/action_view/render/rendering.rb
  22. +1 −2  actionpack/lib/action_view/template/handlers/builder.rb
  23. +0 −1  actionpack/lib/action_view/template/handlers/rjs.rb
  24. +0 −152 actionpack/lib/action_view/template/path.rb
  25. +150 −0 actionpack/lib/action_view/template/resolver.rb
  26. +2 −2 actionpack/lib/action_view/template/template.rb
  27. +1 −1  actionpack/lib/action_view/template/text.rb
  28. +1 −1  actionpack/test/abstract_controller/layouts_test.rb
  29. +1 −0  actionpack/test/abstract_unit.rb
  30. +6 −3 actionpack/test/activerecord/polymorphic_routes_test.rb
  31. +1 −0  actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  32. +19 −5 actionpack/test/controller/action_pack_assertions_test.rb
  33. +1 −5 actionpack/test/controller/base_test.rb
  34. +18 −50 actionpack/test/controller/filters_test.rb
  35. +3 −16 actionpack/test/controller/helper_test.rb
  36. +3 −19 actionpack/test/controller/layout_test.rb
  37. +10 −22 actionpack/test/controller/mime_responds_test.rb
  38. +2 −0  actionpack/test/controller/record_identifier_test.rb
  39. +1 −0  actionpack/test/controller/redirect_test.rb
  40. +7 −7 actionpack/test/controller/render_test.rb
  41. +2 −2 actionpack/test/controller/send_file_test.rb
  42. +2 −2 actionpack/test/dispatch/mime_type_test.rb
  43. +1 −1  actionpack/test/fixtures/layouts/builder.builder
  44. +1 −1  actionpack/test/fixtures/layouts/standard.html.erb
  45. +2 −2 actionpack/test/fixtures/layouts/talk_from_action.erb
  46. +1 −0  actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb
  47. +6 −0 actionpack/test/lib/controller/fake_models.rb
  48. +2 −39 actionpack/test/lib/fixture_template.rb
  49. +1 −1  actionpack/test/new_base/content_type_test.rb
  50. +1 −1  actionpack/test/new_base/etag_test.rb
  51. +4 −4 actionpack/test/new_base/render_action_test.rb
  52. +1 −1  actionpack/test/new_base/render_implicit_action_test.rb
  53. +3 −3 actionpack/test/new_base/render_layout_test.rb
  54. +1 −1  actionpack/test/new_base/render_partial_test.rb
  55. +46 −0 actionpack/test/new_base/render_rjs_test.rb
  56. +3 −3 actionpack/test/new_base/render_template_test.rb
  57. +1 −1  actionpack/test/new_base/render_test.rb
  58. +2 −2 actionpack/test/new_base/render_text_test.rb
  59. +1 −1  actionpack/test/new_base/render_xml_test.rb
  60. +7 −7 actionpack/test/template/active_record_helper_test.rb
  61. +1 −0  actionpack/test/template/atom_feed_helper_test.rb
  62. +5 −8 actionpack/test/template/body_parts_test.rb
  63. +15 −0 actionpack/test/template/capture_helper_test.rb
  64. +1 −1  actionpack/test/template/compiled_templates_test.rb
  65. +2 −2 actionpack/test/template/form_helper_test.rb
  66. +3 −0  actionpack/test/template/prototype_helper_test.rb
  67. +1 −0  actionpack/test/template/record_tag_helper_test.rb
  68. +3 −26 actionpack/test/template/render_test.rb
  69. +1 −0  actionpack/test/template/test_test.rb
  70. +2 −0  actionpack/test/template/url_helper_test.rb
  71. +7 −0 activemodel/lib/active_model.rb
  72. +17 −0 activemodel/lib/active_model/attributes.rb
  73. +3 −3 activemodel/lib/active_model/errors.rb
  74. +8 −8 activesupport/lib/active_support/core_ext/module/model_naming.rb → activemodel/lib/active_model/naming.rb
  75. +38 −0 activemodel/lib/active_model/serializers/json.rb
  76. +1 −5 activemodel/lib/active_model/validations.rb
  77. +30 −0 activemodel/test/cases/attributes_test.rb
  78. +64 −0 activemodel/test/cases/json_serialization_test.rb
  79. +3 −4 activesupport/test/core_ext/module/model_naming_test.rb → activemodel/test/cases/naming_test.rb
  80. +9 −9 activemodel/test/cases/validations/presence_validation_test.rb
  81. +7 −0 activerecord/lib/active_record/associations/through_association_scope.rb
  82. +1 −0  activerecord/lib/active_record/base.rb
  83. +1 −1  activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  84. +1 −1  activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  85. +1 −1  activerecord/lib/active_record/serializers/json_serializer.rb
  86. +0 −4 activerecord/lib/active_record/validations.rb
  87. +6 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
  88. +33 −0 activerecord/test/cases/migration_test.rb
  89. +2 −0  activerecord/test/models/post.rb
  90. +1 −0  activerecord/test/schema/schema.rb
  91. +1 −0  activeresource/lib/active_resource/base.rb
  92. +10 −2 activesupport/lib/active_support/cache.rb
  93. +13 −1 activesupport/lib/active_support/cache/file_store.rb
  94. +0 −4 activesupport/lib/active_support/cache/mem_cache_store.rb
  95. +0 −1  activesupport/lib/active_support/core_ext/module.rb
  96. +1 −0  activesupport/lib/active_support/json/decoding.rb
  97. +5 −0 activesupport/lib/active_support/json/encoding.rb
  98. +16 −0 activesupport/test/caching_test.rb
  99. +1 −1  railties/lib/initializer.rb
  100. +1 −1  railties/test/rails_info_controller_test.rb
View
8 actionpack/lib/action_controller/base/compatibility.rb
@@ -118,6 +118,14 @@ def _find_by_parts(name, details)
details[:prefix] = nil if name =~ /\blayouts/
super
end
+
+ # Move this into a "don't run in production" module
+ def _default_layout(details, require_layout = false)
+ super
+ rescue ActionView::MissingTemplate
+ _find_by_parts(_layout({}), {})
+ nil
+ end
def performed?
response_body
View
5 actionpack/lib/action_controller/base/filter_parameter_logging.rb
@@ -2,10 +2,7 @@ module ActionController
module FilterParameterLogging
extend ActiveSupport::Concern
- # TODO : Remove the defined? check when new base is the main base
- if defined?(ActionController::Http)
- include AbstractController::Logger
- end
+ include AbstractController::Logger
included do
include InstanceMethodsForNewBase
View
74 actionpack/lib/action_controller/base/flash.rb
@@ -28,20 +28,7 @@ module ActionController #:nodoc:
module Flash
extend ActiveSupport::Concern
- # TODO : Remove the defined? check when new base is the main base
- include Session if defined?(ActionController::Http)
-
- included do
- # TODO : Remove the defined? check when new base is the main base
- if defined?(ActionController::Http)
- include InstanceMethodsForNewBase
- else
- include InstanceMethodsForBase
-
- alias_method_chain :perform_action, :flash
- alias_method_chain :reset_session, :flash
- end
- end
+ include Session
class FlashNow #:nodoc:
def initialize(flash)
@@ -148,49 +135,30 @@ def use(key = nil, used = true)
end
end
- module InstanceMethodsForBase #:nodoc:
- protected
- def perform_action_with_flash
- perform_action_without_flash
- if defined? @_flash
- @_flash.store(session)
- remove_instance_variable(:@_flash)
- end
- end
-
- def reset_session_with_flash
- reset_session_without_flash
- remove_instance_variable(:@_flash) if defined?(@_flash)
- end
+ protected
+ def process_action(method_name)
+ super
+ if defined? @_flash
+ @_flash.store(session)
+ remove_instance_variable(:@_flash)
+ end
end
- module InstanceMethodsForNewBase #:nodoc:
- protected
- def process_action(method_name)
- super
- if defined? @_flash
- @_flash.store(session)
- remove_instance_variable(:@_flash)
- end
- end
-
- def reset_session
- super
- remove_instance_variable(:@_flash) if defined?(@_flash)
- end
+ def reset_session
+ super
+ remove_instance_variable(:@_flash) if defined?(@_flash)
end
- protected
- # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
- # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
- # to put a new one.
- def flash #:doc:
- if !defined?(@_flash)
- @_flash = session["flash"] || FlashHash.new
- @_flash.sweep
- end
-
- @_flash
+ # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
+ # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
+ # to put a new one.
+ def flash #:doc:
+ if !defined?(@_flash)
+ @_flash = session["flash"] || FlashHash.new
+ @_flash.sweep
end
+
+ @_flash
+ end
end
end
View
2  actionpack/lib/action_controller/base/http.rb
@@ -36,7 +36,7 @@ def controller_name
# ==== Returns
# String
def self.controller_path
- @controller_path ||= self.name.sub(/Controller$/, '').underscore
+ @controller_path ||= name && name.sub(/Controller$/, '').underscore
end
# Delegates to the class' #controller_path
View
7 actionpack/lib/action_controller/base/layouts.rb
@@ -26,9 +26,6 @@ module ActionController
# hello world
# // The footer part of this layout
#
- # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance
- # variable. The preferred notation now is to use <tt>yield</tt>, as documented above.
- #
# == Accessing shared variables
#
# Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
@@ -176,7 +173,7 @@ def _determine_template(options)
super
return if (options.key?(:text) || options.key?(:inline) || options.key?(:partial)) && !options.key?(:layout)
- layout = options.key?(:layout) ? options[:layout] : :none
+ layout = options.key?(:layout) ? options[:layout] : :default
options[:_layout] = _layout_for_option(layout, options[:_template].details)
end
@@ -184,7 +181,7 @@ def _layout_for_option(name, details)
case name
when String then _layout_for_name(name, details)
when true then _default_layout(details, true)
- when :none then _default_layout(details, false)
+ when :default then _default_layout(details, false)
when false, nil then nil
else
raise ArgumentError,
View
7 actionpack/lib/action_controller/base/mime_responds.rb
@@ -120,12 +120,9 @@ def custom(mime_type, &block)
@responses[mime_type] ||= Proc.new do
# TODO: Remove this when new base is merged in
- if defined?(Http)
- @controller.formats = [mime_type.to_sym]
- end
-
+ @controller.formats = [mime_type.to_sym]
+ @controller.content_type = mime_type
@controller.template.formats = [mime_type.to_sym]
- @response.content_type = mime_type
block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
end
View
18 actionpack/lib/action_controller/base/request_forgery_protection.rb
@@ -6,20 +6,16 @@ module RequestForgeryProtection
extend ActiveSupport::Concern
# TODO : Remove the defined? check when new base is the main base
- if defined?(ActionController::Http)
- include AbstractController::Helpers, Session
- end
+ include AbstractController::Helpers, Session
included do
- if defined?(ActionController::Http)
- # Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
- # sets it to <tt>:authenticity_token</tt> by default.
- cattr_accessor :request_forgery_protection_token
+ # Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
+ # sets it to <tt>:authenticity_token</tt> by default.
+ cattr_accessor :request_forgery_protection_token
- # 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
- end
+ # 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
helper_method :form_authenticity_token
helper_method :protect_against_forgery?
View
5 actionpack/lib/action_controller/base/streaming.rb
@@ -4,10 +4,7 @@ module ActionController #:nodoc:
module Streaming
extend ActiveSupport::Concern
- # TODO : Remove the defined? check when new base is the main base
- if defined?(ActionController::Http)
- include ActionController::Renderer
- end
+ include ActionController::Renderer
DEFAULT_SEND_FILE_OPTIONS = {
:type => 'application/octet-stream'.freeze,
View
5 actionpack/lib/action_controller/base/verification.rb
@@ -2,10 +2,7 @@ module ActionController #:nodoc:
module Verification #:nodoc:
extend ActiveSupport::Concern
- # TODO : Remove the defined? check when new base is the main base
- if defined?(ActionController::Http)
- include AbstractController::Callbacks, Session, Flash, Renderer
- end
+ include AbstractController::Callbacks, Session, Flash, Renderer
# This module provides a class-level method for specifying that certain
# actions are guarded against being called without certain prerequisites
View
26 actionpack/lib/action_controller/caching/actions.rb
@@ -62,14 +62,7 @@ def caches_action(*actions)
cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path), :store_options => options)
- # TODO: Remove this once new base is swapped in.
- if defined?(ActionController::Http)
- around_filter cache_filter, filter_options
- else
- around_filter(filter_options) do |controller, action|
- cache_filter.filter(controller, action)
- end
- end
+ around_filter cache_filter, filter_options
end
end
@@ -91,19 +84,10 @@ def initialize(options, &block)
@options = options
end
- # TODO: Remove once New Base is merged
- if defined?(ActionController::Http)
- def filter(controller)
- should_continue = before(controller)
- yield if should_continue
- after(controller)
- end
- else
- def filter(controller, action)
- should_continue = before(controller)
- action.call if should_continue
- after(controller)
- end
+ def filter(controller)
+ should_continue = before(controller)
+ yield if should_continue
+ after(controller)
end
def before(controller)
View
3  actionpack/lib/action_controller/legacy/layout.rb
@@ -44,9 +44,6 @@ def self.included(base)
# hello world
# // The footer part of this layout
#
- # NOTE: The old notation for rendering the view from a layout was to expose the magic <tt>@content_for_layout</tt> instance
- # variable. The preferred notation now is to use <tt>yield</tt>, as documented above.
- #
# == Accessing shared variables
#
# Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with
View
3  actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb
@@ -112,8 +112,7 @@ def polymorphic_url(record_or_hash_or_array, options = {})
# Returns the path component of a URL for the given record. It uses
# <tt>polymorphic_url</tt> with <tt>:routing_type => :path</tt>.
def polymorphic_path(record_or_hash_or_array, options = {})
- options[:routing_type] = :path
- polymorphic_url(record_or_hash_or_array, options)
+ polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path))
end
%w(edit new).each do |action|
View
14 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -2,7 +2,19 @@
require 'active_support/core_ext/class/attribute_accessors'
module Mime
- SET = []
+ class Mimes < Array
+ def symbols
+ @symbols ||= map {|m| m.to_sym }
+ end
+
+ %w(<< concat shift unshift push pop []= clear compact! collect!
+ delete delete_at delete_if flatten! map! insert reject! reverse!
+ replace slice! sort! uniq!).each do |method|
+ define_method(method) {|*args| @symbols = nil; super(*args) }
+ end
+ end
+
+ SET = Mimes.new
EXTENSION_LOOKUP = {}
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
View
10 actionpack/lib/action_dispatch/http/request.rb
@@ -180,12 +180,10 @@ def formats
else
accepts.dup
end.tap do |ret|
- if defined?(ActionController::Http)
- if ret == ONLY_ALL
- ret.replace Mime::SET
- elsif all = ret.index(Mime::ALL)
- ret.delete_at(all) && ret.insert(all, *Mime::SET)
- end
+ if ret == ONLY_ALL
+ ret.replace Mime::SET
+ elsif all = ret.index(Mime::ALL)
+ ret.delete_at(all) && ret.insert(all, *Mime::SET)
end
end
else
View
29 actionpack/lib/action_view.rb
@@ -33,21 +33,22 @@ def self.load_all!
[Base, InlineTemplate, TemplateError]
end
- autoload :Base, 'action_view/base'
- autoload :Helpers, 'action_view/helpers'
- autoload :InlineTemplate, 'action_view/template/inline'
- autoload :Partials, 'action_view/render/partials'
- autoload :Path, 'action_view/template/path'
- autoload :PathSet, 'action_view/paths'
- autoload :Rendering, 'action_view/render/rendering'
- autoload :Renderable, 'action_view/template/renderable'
+ autoload :Base, 'action_view/base'
+ autoload :Helpers, 'action_view/helpers'
+ autoload :InlineTemplate, 'action_view/template/inline'
+ autoload :Partials, 'action_view/render/partials'
+ autoload :Resolver, 'action_view/template/resolver'
+ autoload :PathSet, 'action_view/paths'
+ autoload :Rendering, 'action_view/render/rendering'
+ autoload :Renderable, 'action_view/template/renderable'
autoload :RenderablePartial, 'action_view/template/partial'
- autoload :Template, 'action_view/template/template'
- autoload :TemplateError, 'action_view/template/error'
- autoload :TemplateHandler, 'action_view/template/handler'
- autoload :TemplateHandlers, 'action_view/template/handlers'
- autoload :TextTemplate, 'action_view/template/text'
- autoload :Helpers, 'action_view/helpers'
+ autoload :Template, 'action_view/template/template'
+ autoload :TemplateError, 'action_view/template/error'
+ autoload :TemplateHandler, 'action_view/template/handler'
+ autoload :TemplateHandlers, 'action_view/template/handlers'
+ autoload :TextTemplate, 'action_view/template/text'
+ autoload :Helpers, 'action_view/helpers'
+ autoload :FileSystemResolverWithFallback, 'action_view/template/resolver'
end
class ERB
View
55 actionpack/lib/action_view/base.rb
@@ -170,12 +170,13 @@ class Base
attr_accessor :base_path, :assigns, :template_extension, :formats
attr_accessor :controller
+ attr_internal :captures
attr_accessor :output_buffer
class << self
delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB'
- delegate :logger, :to => 'ActionController::Base'
+ delegate :logger, :to => 'ActionController::Base', :allow_nil => true
end
@@debug_rjs = false
@@ -229,38 +230,27 @@ def include(*args)
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil, formats = nil)#:nodoc:
@formats = formats || [:html]
- @assigns = assigns_for_first_render
- @assigns_added = nil
+ @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
@controller = controller
@helpers = ProxyModule.new(self)
+ @_content_for = Hash.new {|h,k| h[k] = "" }
self.view_paths = view_paths
-
- @_first_render = nil
- @_current_render = nil
end
+ attr_internal :template
attr_reader :view_paths
def view_paths=(paths)
@view_paths = self.class.process_view_paths(paths)
end
- # Access the current template being rendered.
- # Returns a ActionView::Template object.
- def template
- @_current_render
- end
-
- def template=(template) #:nodoc:
- @_first_render ||= template
- @_current_render = template
- end
-
def with_template(current_template)
+ _evaluate_assigns_and_ivars
last_template, self.template = template, current_template
+ last_formats, self.formats = formats, [current_template.mime_type.to_sym] + Mime::SET.symbols
yield
ensure
- self.template = last_template
+ self.template, self.formats = last_template, last_formats
end
def punctuate_body!(part)
@@ -271,30 +261,19 @@ def punctuate_body!(part)
# Evaluates the local assigns and controller ivars, pushes them to the view.
def _evaluate_assigns_and_ivars #:nodoc:
- unless @assigns_added
- @assigns.each { |key, value| instance_variable_set("@#{key}", value) }
- _copy_ivars_from_controller
- @assigns_added = true
- end
+ @assigns_added ||= _copy_ivars_from_controller
end
- private
+ private
- def _copy_ivars_from_controller #:nodoc:
- if @controller
- variables = @controller.instance_variable_names
- variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
- variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
- end
+ def _copy_ivars_from_controller #:nodoc:
+ if @controller
+ variables = @controller.instance_variable_names
+ variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
+ variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
end
+ true
+ end
- def _set_controller_content_type(content_type) #:nodoc:
- # TODO: Remove this method when new base is switched
- unless defined?(ActionController::Http)
- if controller.respond_to?(:response)
- controller.response.content_type ||= content_type
- end
- end
- end
end
end
View
59 actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -122,9 +122,9 @@ def error_message_on(object, method, *args)
options.reverse_merge!(:prepend_text => '', :append_text => '', :css_class => 'formError')
if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
- (errors = obj.errors.on(method))
+ (errors = obj.errors[method])
content_tag("div",
- "#{options[:prepend_text]}#{ERB::Util.html_escape(errors.is_a?(Array) ? errors.first : errors)}#{options[:append_text]}",
+ "#{options[:prepend_text]}#{ERB::Util.html_escape(errors.first)}#{options[:append_text]}",
:class => options[:css_class]
)
else
@@ -247,59 +247,22 @@ def to_tag(options = {})
end
end
- alias_method :tag_without_error_wrapping, :tag
- def tag(name, options)
- if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(tag_without_error_wrapping(name, options), object.errors.on(@method_name))
- else
- tag_without_error_wrapping(name, options)
- end
- end
-
- alias_method :content_tag_without_error_wrapping, :content_tag
- def content_tag(name, value, options)
- if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(content_tag_without_error_wrapping(name, value, options), object.errors.on(@method_name))
- else
- content_tag_without_error_wrapping(name, value, options)
- end
- end
-
- alias_method :to_date_select_tag_without_error_wrapping, :to_date_select_tag
- def to_date_select_tag(options = {}, html_options = {})
- if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(to_date_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
- else
- to_date_select_tag_without_error_wrapping(options, html_options)
- end
- end
-
- alias_method :to_datetime_select_tag_without_error_wrapping, :to_datetime_select_tag
- def to_datetime_select_tag(options = {}, html_options = {})
- if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(to_datetime_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
- else
- to_datetime_select_tag_without_error_wrapping(options, html_options)
+ %w(tag content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth|
+ without = "#{meth}_without_error_wrapping"
+ define_method "#{meth}_with_error_wrapping" do |*args|
+ error_wrapping(send(without, *args))
end
+ alias_method_chain meth, :error_wrapping
end
- alias_method :to_time_select_tag_without_error_wrapping, :to_time_select_tag
- def to_time_select_tag(options = {}, html_options = {})
- if object.respond_to?(:errors) && object.errors.respond_to?(:on)
- error_wrapping(to_time_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
+ def error_wrapping(html_tag)
+ if object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && object.errors[@method_name].any?
+ Base.field_error_proc.call(html_tag, self)
else
- to_time_select_tag_without_error_wrapping(options, html_options)
+ html_tag
end
end
- def error_wrapping(html_tag, has_error)
- has_error ? Base.field_error_proc.call(html_tag, self) : html_tag
- end
-
- def error_message
- object.errors.on(@method_name)
- end
-
def column_type
object.send(:column_for_attribute, @method_name).type
end
View
31 actionpack/lib/action_view/helpers/capture_helper.rb
@@ -111,15 +111,32 @@ def capture(*args, &block)
#
# WARNING: content_for is ignored in caches. So you shouldn't use it
# for elements that will be fragment cached.
- #
- # The deprecated way of accessing a content_for block is to use an instance variable
- # named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
- # <tt><%= yield :footer %></tt>.
def content_for(name, content = nil, &block)
- ivar = "@content_for_#{name}"
content = capture(&block) if block_given?
- instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{content}")
- nil
+ return @_content_for[name] << content if content
+ @_content_for[name]
+ end
+
+ # content_for? simply checks whether any content has been captured yet using content_for
+ # Useful to render parts of your layout differently based on what is in your views.
+ #
+ # ==== Examples
+ #
+ # Perhaps you will use different css in you layout if no content_for :right_column
+ #
+ # <%# This is the layout %>
+ # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ # <head>
+ # <title>My Website</title>
+ # <%= yield :script %>
+ # </head>
+ # <body class="<%= content_for?(:right_col) ? 'one-column' : 'two-column' %>">
+ # <%= yield %>
+ # <%= yield :right_col %>
+ # </body>
+ # </html>
+ def content_for?(name)
+ @_content_for[name].present?
end
# Use an alternate output buffer for the duration of the block.
View
2  actionpack/lib/action_view/paths.rb
@@ -3,7 +3,7 @@ class PathSet < Array #:nodoc:
def self.type_cast(obj)
if obj.is_a?(String)
cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes
- Template::FileSystemPathWithFallback.new(obj, :cache => cache)
+ FileSystemResolverWithFallback.new(obj, :cache => cache)
else
obj
end
View
7 actionpack/lib/action_view/render/partials.rb
@@ -245,13 +245,6 @@ def _deprecated_ivar_assign(template)
end
end
- def _render_partial_with_block(layout, block, options)
- @_proc_for_layout = block
- concat(_render_partial(options.merge(:partial => layout)))
- ensure
- @_proc_for_layout = nil
- end
-
def _render_partial_with_layout(layout, options)
if layout
prefix = controller && !layout.include?("/") ? controller.controller_path : nil
View
70 actionpack/lib/action_view/render/rendering.rb
@@ -51,32 +51,60 @@ def _render_content_with_layout(content, layout, locals)
end
begin
- original_content_for_layout = @content_for_layout if defined?(@content_for_layout)
- @content_for_layout = content
+ old_content, @_content_for[:layout] = @_content_for[:layout], content
- @cached_content_for_layout = @content_for_layout
+ @cached_content_for_layout = @_content_for[:layout]
_render_template(layout, locals)
ensure
- @content_for_layout = original_content_for_layout
+ @_content_for[:layout] = old_content
end
end
+ # You can think of a layout as a method that is called with a block. This method
+ # returns the block that the layout is called with. If the user calls yield :some_name,
+ # the block, by default, returns content_for(:some_name). If the user calls yield,
+ # the default block returns content_for(:layout).
+ #
+ # The user can override this default by passing a block to the layout.
+ #
+ # ==== Example
+ #
+ # # The template
+ # <% render :layout => "my_layout" do %>Content<% end %>
+ #
+ # # The layout
+ # <html><% yield %></html>
+ #
+ # In this case, instead of the default block, which would return content_for(:layout),
+ # this method returns the block that was passed in to render layout, and the response
+ # would be <html>Content</html>.
+ #
+ # Finally, the block can take block arguments, which can be passed in by yield.
+ #
+ # ==== Example
+ #
+ # # The template
+ # <% render :layout => "my_layout" do |customer| %>Hello <%= customer.name %><% end %>
+ #
+ # # The layout
+ # <html><% yield Struct.new(:name).new("David") %></html>
+ #
+ # In this case, the layout would receive the block passed into <tt>render :layout</tt>,
+ # and the Struct specified in the layout would be passed into the block. The result
+ # would be <html>Hello David</html>.
+ def layout_proc(name)
+ @_default_layout ||= proc { |*names| @_content_for[names.first || :layout] }
+ !@_content_for.key?(name) && @_proc_for_layout || @_default_layout
+ end
+
def _render_template(template, local_assigns = {})
with_template(template) do
- _evaluate_assigns_and_ivars
- _set_controller_content_type(template.mime_type) if template.respond_to?(:mime_type)
-
template.render(self, local_assigns) do |*names|
- if !instance_variable_defined?(:"@content_for_#{names.first}") &&
- instance_variable_defined?(:@_proc_for_layout) && (proc = @_proc_for_layout)
- capture(*names, &proc)
- elsif instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}")
- instance_variable_get(ivar)
- end
+ capture(*names, &layout_proc(names.first))
end
end
rescue Exception => e
- if TemplateError === e
+ if e.is_a?(TemplateError)
e.sub_template_of(template)
raise e
else
@@ -101,20 +129,18 @@ def _render_template_from_controller(*args)
end
def _render_template_with_layout(template, layout = nil, options = {}, partial = false)
- if controller && logger
- logger.info("Rendering #{template.identifier}" +
- (options[:status] ? " (#{options[:status]})" : ''))
- end
-
+ logger && logger.info("Rendering #{template.identifier}#{' (#{options[:status]})' if options[:status]}")
+
+ locals = options[:locals] || {}
+
content = if partial
object = partial unless partial == true
_render_partial_object(template, options, object)
else
- _render_template(template, options[:locals] || {})
+ _render_template(template, locals)
end
- return content unless layout
- _render_content_with_layout(content, layout, options[:locals] || {})
+ layout ? _render_content_with_layout(content, layout, locals) : content
end
end
end
View
3  actionpack/lib/action_view/template/handlers/builder.rb
@@ -8,8 +8,7 @@ class Builder < TemplateHandler
self.default_format = Mime::XML
def compile(template)
- "_set_controller_content_type(Mime::XML);" +
- "xml = ::Builder::XmlMarkup.new(:indent => 2);" +
+ "xml = ::Builder::XmlMarkup.new(:indent => 2);" +
"self.output_buffer = xml.target!;" +
template.source +
";xml.target!;"
View
1  actionpack/lib/action_view/template/handlers/rjs.rb
@@ -6,7 +6,6 @@ class RJS < TemplateHandler
self.default_format = Mime::JS
def compile(template)
- "@formats = [:html];" +
"controller.response.content_type ||= Mime::JS;" +
"update_page do |page|;#{template.source}\nend"
end
View
152 actionpack/lib/action_view/template/path.rb
@@ -1,152 +0,0 @@
-require "pathname"
-
-module ActionView
- class Template
- # Abstract super class
- class Path
- def initialize(options)
- @cache = options[:cache]
- @cached = {}
- end
-
- # Normalizes the arguments and passes it on to find_template
- def find_by_parts(*args)
- find_all_by_parts(*args).first
- end
-
- def find_all_by_parts(name, details = {}, prefix = nil, partial = nil)
- details[:locales] = [I18n.locale]
- name = name.to_s.gsub(handler_matcher, '').split("/")
- find_templates(name.pop, details, [prefix, *name].compact.join("/"), partial)
- end
-
- private
-
- # This is what child classes implement. No defaults are needed
- # because Path guarentees that the arguments are present and
- # normalized.
- def find_templates(name, details, prefix, partial)
- raise NotImplementedError
- end
-
- def valid_handlers
- @valid_handlers ||= TemplateHandlers.extensions
- end
-
- def handler_matcher
- @handler_matcher ||= begin
- e = valid_handlers.join('|')
- /\.(?:#{e})$/
- end
- end
-
- def handler_glob
- e = TemplateHandlers.extensions.map{|h| ".#{h},"}.join
- "{#{e}}"
- end
-
- def formats_glob
- @formats_glob ||= begin
- formats = Mime::SET.map { |m| m.symbol }
- '{' + formats.map { |l| ".#{l}," }.join + '}'
- end
- end
-
- def cached(key)
- return yield unless @cache
- return @cached[key] if @cached.key?(key)
- @cached[key] = yield
- end
- end
-
- class FileSystemPath < Path
-
- def initialize(path, options = {})
- raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
- super(options)
- @path = Pathname.new(path).expand_path
- end
-
- # TODO: This is the currently needed API. Make this suck less
- # ==== <suck>
- attr_reader :path
-
- def to_s
- path.to_s
- end
-
- def to_str
- path.to_s
- end
-
- def ==(path)
- to_str == path.to_str
- end
-
- def eql?(path)
- to_str == path.to_str
- end
- # ==== </suck>
-
- def find_templates(name, details, prefix, partial, root = "#{@path}/")
- if glob = details_to_glob(name, details, prefix, partial, root)
- cached(glob) do
- Dir[glob].map do |path|
- next if File.directory?(path)
- source = File.read(path)
- identifier = Pathname.new(path).expand_path.to_s
-
- Template.new(source, identifier, *path_to_details(path))
- end.compact
- end
- end
- end
-
- private
-
- # :api: plugin
- def details_to_glob(name, details, prefix, partial, root)
- path = ""
- path << "#{prefix}/" unless prefix.empty?
- path << (partial ? "_#{name}" : name)
-
- extensions = ""
- [:locales, :formats].each do |k|
- extensions << if exts = details[k]
- '{' + exts.map {|e| ".#{e},"}.join + '}'
- else
- k == :formats ? formats_glob : ''
- end
- end
-
- "#{root}#{path}#{extensions}#{handler_glob}"
- end
-
- # TODO: fix me
- # :api: plugin
- def path_to_details(path)
- # [:erb, :format => :html, :locale => :en, :partial => true/false]
- if m = path.match(%r'/(_)?[\w-]+(\.[\w-]+)*\.(\w+)$')
- partial = m[1] == '_'
- details = (m[2]||"").split('.').reject { |e| e.empty? }
- handler = Template.handler_class_for_extension(m[3])
-
- format = Mime[details.last] && details.pop.to_sym
- locale = details.last && details.pop.to_sym
-
- return handler, :format => format, :locale => locale, :partial => partial
- end
- end
- end
-
- class FileSystemPathWithFallback < FileSystemPath
-
- def find_templates(name, details, prefix, partial)
- templates = super
- return super(name, details, prefix, partial, '') if templates.empty?
- templates
- end
-
- end
- end
-end
View
150 actionpack/lib/action_view/template/resolver.rb
@@ -0,0 +1,150 @@
+require "pathname"
+require "action_view/template/template"
+
+module ActionView
+ # Abstract superclass
+ class Resolver
+ def initialize(options)
+ @cache = options[:cache]
+ @cached = {}
+ end
+
+ # Normalizes the arguments and passes it on to find_template
+ def find_by_parts(*args)
+ find_all_by_parts(*args).first
+ end
+
+ def find_all_by_parts(name, details = {}, prefix = nil, partial = nil)
+ details[:locales] = [I18n.locale]
+ name = name.to_s.gsub(handler_matcher, '').split("/")
+ find_templates(name.pop, details, [prefix, *name].compact.join("/"), partial)
+ end
+
+ private
+
+ # This is what child classes implement. No defaults are needed
+ # because Resolver guarantees that the arguments are present and
+ # normalized.
+ def find_templates(name, details, prefix, partial)
+ raise NotImplementedError
+ end
+
+ def valid_handlers
+ @valid_handlers ||= TemplateHandlers.extensions
+ end
+
+ def handler_matcher
+ @handler_matcher ||= begin
+ e = valid_handlers.join('|')
+ /\.(?:#{e})$/
+ end
+ end
+
+ def handler_glob
+ e = TemplateHandlers.extensions.map{|h| ".#{h},"}.join
+ "{#{e}}"
+ end
+
+ def formats_glob
+ @formats_glob ||= begin
+ '{' + Mime::SET.symbols.map { |l| ".#{l}," }.join + '}'
+ end
+ end
+
+ def cached(key)
+ return yield unless @cache
+ return @cached[key] if @cached.key?(key)
+ @cached[key] = yield
+ end
+ end
+
+ class FileSystemResolver < Resolver
+
+ def initialize(path, options = {})
+ raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
+ super(options)
+ @path = Pathname.new(path).expand_path
+ end
+
+ # TODO: This is the currently needed API. Make this suck less
+ # ==== <suck>
+ attr_reader :path
+
+ def to_s
+ path.to_s
+ end
+
+ def to_str
+ path.to_s
+ end
+
+ def ==(path)
+ to_str == path.to_str
+ end
+
+ def eql?(path)
+ to_str == path.to_str
+ end
+ # ==== </suck>
+
+ def find_templates(name, details, prefix, partial, root = "#{@path}/")
+ if glob = details_to_glob(name, details, prefix, partial, root)
+ cached(glob) do
+ Dir[glob].map do |path|
+ next if File.directory?(path)
+ source = File.read(path)
+ identifier = Pathname.new(path).expand_path.to_s
+
+ Template.new(source, identifier, *path_to_details(path))
+ end.compact
+ end
+ end
+ end
+
+ private
+
+ # :api: plugin
+ def details_to_glob(name, details, prefix, partial, root)
+ path = ""
+ path << "#{prefix}/" unless prefix.empty?
+ path << (partial ? "_#{name}" : name)
+
+ extensions = ""
+ [:locales, :formats].each do |k|
+ extensions << if exts = details[k]
+ '{' + exts.map {|e| ".#{e},"}.join + '}'
+ else
+ k == :formats ? formats_glob : ''
+ end
+ end
+
+ "#{root}#{path}#{extensions}#{handler_glob}"
+ end
+
+ # TODO: fix me
+ # :api: plugin
+ def path_to_details(path)
+ # [:erb, :format => :html, :locale => :en, :partial => true/false]
+ if m = path.match(%r'/(_)?[\w-]+(\.[\w-]+)*\.(\w+)$')
+ partial = m[1] == '_'
+ details = (m[2]||"").split('.').reject { |e| e.empty? }
+ handler = Template.handler_class_for_extension(m[3])
+
+ format = Mime[details.last] && details.pop.to_sym
+ locale = details.last && details.pop.to_sym
+
+ return handler, :format => format, :locale => locale, :partial => partial
+ end
+ end
+ end
+
+ class FileSystemResolverWithFallback < FileSystemResolver
+
+ def find_templates(name, details, prefix, partial)
+ templates = super
+ return super(name, details, prefix, partial, '') if templates.empty?
+ templates
+ end
+
+ end
+end
View
4 actionpack/lib/action_view/template/template.rb
@@ -2,7 +2,7 @@
# This is so that templates compiled in this file are UTF-8
require 'set'
-require "action_view/template/path"
+require "action_view/template/resolver"
module ActionView
class Template
@@ -20,7 +20,7 @@ def initialize(source, identifier, handler, details)
handler.respond_to?(:default_format) ? handler.default_format.to_sym.to_s : "html"
end
@mime_type = Mime::Type.lookup_by_extension(format.to_s)
- @details[:formats] = Array.wrap(format && format.to_sym)
+ @details[:formats] = Array.wrap(format.to_sym)
end
def render(view, locals, &blk)
View
2  actionpack/lib/action_view/template/text.rb
@@ -3,7 +3,7 @@ class TextTemplate < String #:nodoc:
def initialize(string, content_type = Mime[:html])
super(string.to_s)
- @content_type = Mime[content_type]
+ @content_type = Mime[content_type] || content_type
end
def details
View
2  actionpack/test/abstract_controller/layouts_test.rb
@@ -9,7 +9,7 @@ class Base < AbstractController::Base
include AbstractController::Renderer
include AbstractController::Layouts
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"layouts/hello.erb" => "With String <%= yield %>",
"layouts/hello_override.erb" => "With Override <%= yield %>",
"layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" =>
View
1  actionpack/test/abstract_unit.rb
@@ -1,5 +1,6 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
+$:.unshift(File.dirname(__FILE__) + '/../../activemodel/lib')
$:.unshift(File.dirname(__FILE__) + '/lib')
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
View
9 actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -234,10 +234,13 @@ def test_polymorphic_path_does_not_modify_arguments
with_admin_test_routes do
@project.save
@task.save
+
+ options = {}
object_array = [:admin, @project, @task]
- assert_no_difference 'object_array.size' do
- polymorphic_url(object_array)
- end
+ original_args = [object_array.dup, options.dup]
+
+ assert_no_difference('object_array.size') { polymorphic_path(object_array, options) }
+ assert_equal original_args, [object_array, options]
end
end
View
1  actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -126,6 +126,7 @@ def render_with_record_collection
end
class Game < Struct.new(:name, :id)
+ extend ActiveModel::Naming
def to_param
id.to_s
end
View
24 actionpack/test/controller/action_pack_assertions_test.rb
@@ -13,6 +13,18 @@ def hello_world() render :template => "test/hello_world"; end
# a standard template
def hello_xml_world() render :template => "test/hello_xml_world"; end
+ # a standard template rendering PDF
+ def hello_xml_world_pdf
+ self.content_type = "application/pdf"
+ render :template => "test/hello_xml_world"
+ end
+
+ # a standard template rendering PDF
+ def hello_xml_world_pdf_header
+ response.headers["Content-Type"] = "application/pdf; charset=utf-8"
+ render :template => "test/hello_xml_world"
+ end
+
# a standard partial
def partial() render :partial => 'test/partial'; end
@@ -537,11 +549,13 @@ def test_rendering_xml_sets_content_type
end
def test_rendering_xml_respects_content_type
- pending do
- @response.headers['type'] = 'application/pdf'
- process :hello_xml_world
- assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
- end
+ process :hello_xml_world_pdf
+ assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
+ end
+
+ def test_rendering_xml_respects_content_type_when_set_in_the_header
+ process :hello_xml_world_pdf_header
+ assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type'])
end
def test_render_text_with_custom_content_type
View
6 actionpack/test/controller/base_test.rb
@@ -146,11 +146,7 @@ def test_get_on_priv_should_show_selector
def test_method_missing_is_not_an_action_name
use_controller MethodMissingController
- if defined?(ActionController::Http)
- assert ! @controller.__send__(:action_method?, 'method_missing')
- else
- assert ! @controller.__send__(:action_methods).include?('method_missing')
- end
+ assert ! @controller.__send__(:action_method?, 'method_missing')
get :method_missing
assert_response :success
View
68 actionpack/test/controller/filters_test.rb
@@ -9,24 +9,20 @@ class << self
end unless method_defined?(pending)
end
- if defined?(ActionController::Http)
- def before_filters
- filters = _process_action_callbacks.select { |c| c.kind == :before }
- filters.map! { |c| c.instance_variable_get(:@raw_filter) }
- end
+ def before_filters
+ filters = _process_action_callbacks.select { |c| c.kind == :before }
+ filters.map! { |c| c.instance_variable_get(:@raw_filter) }
end
end
- if defined?(ActionController::Http)
- def assigns(key = nil)
- assigns = {}
- instance_variable_names.each do |ivar|
- next if ActionController::Base.protected_instance_variables.include?(ivar)
- assigns[ivar[1..-1]] = instance_variable_get(ivar)
- end
-
- key.nil? ? assigns : assigns[key.to_s]
+ def assigns(key = nil)
+ assigns = {}
+ instance_variable_names.each do |ivar|
+ next if ActionController::Base.protected_instance_variables.include?(ivar)
+ assigns[ivar[1..-1]] = instance_variable_get(ivar)
end
+
+ key.nil? ? assigns : assigns[key.to_s]
end
end
@@ -598,22 +594,11 @@ def test_having_properties_in_around_filter
assert_equal "before and after", assigns["execution_log"]
end
- for_tag(:old_base) do
- def test_prepending_and_appending_around_filter
- controller = test_process(MixedFilterController)
- assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
- " after appended aroundfilter after aroundfilter after procfilter ",
- MixedFilterController.execution_log
- end
- end
-
- for_tag(:new_base) do
- def test_prepending_and_appending_around_filter
- controller = test_process(MixedFilterController)
- assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
- " after appended aroundfilter after procfilter after aroundfilter ",
- MixedFilterController.execution_log
- end
+ def test_prepending_and_appending_around_filter
+ controller = test_process(MixedFilterController)
+ assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
+ " after appended aroundfilter after procfilter after aroundfilter ",
+ MixedFilterController.execution_log
end
def test_rendering_breaks_filtering_chain
@@ -876,14 +861,6 @@ def test_with_instance
assert_raise(After) { test_process(controller,'raises_after') }
end
- for_tag(:old_base) do
- def test_with_method
- controller = ControllerWithFilterMethod
- assert_nothing_raised { test_process(controller,'no_raise') }
- assert_raise(After) { test_process(controller,'raises_after') }
- end
- end
-
def test_with_proc
test_process(ControllerWithProcFilter,'no_raise')
assert assigns['before']
@@ -906,18 +883,9 @@ def test_nested_filters
end
end
- for_tag(:old_base) do
- def test_filter_order_with_all_filter_types
- test_process(ControllerWithAllTypesOfFilters,'no_raise')
- assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after', assigns['ran_filter'].join(' ')
- end
- end
-
- for_tag(:new_base) do
- def test_filter_order_with_all_filter_types
- test_process(ControllerWithAllTypesOfFilters,'no_raise')
- assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ')
- end
+ def test_filter_order_with_all_filter_types
+ test_process(ControllerWithAllTypesOfFilters,'no_raise')
+ assert_equal 'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)', assigns['ran_filter'].join(' ')
end
def test_filter_order_with_skip_filter_method
View
19 actionpack/test/controller/helper_test.rb
@@ -127,11 +127,7 @@ def test_helper_for_acronym_controller
end
def test_all_helpers
- methods = if defined?(ActionController::Http)
- AllHelpersController._helpers.instance_methods.map {|m| m.to_s}
- else
- AllHelpersController.master_helper_module.instance_methods.map {|m| m.to_s}
- end
+ methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s}
# abc_helper.rb
assert methods.include?('bare_a')
@@ -147,12 +143,7 @@ def test_all_helpers_with_alternate_helper_dir
@controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers'
# Reload helpers
- if defined?(ActionController::Http)
- @controller_class._helpers = Module.new
- else
- @controller_class.master_helper_module = Module.new
- end
-
+ @controller_class._helpers = Module.new
@controller_class.helper :all
# helpers/abc_helper.rb should not be included
@@ -184,11 +175,7 @@ def expected_helper_methods
end
def master_helper_methods
- if defined?(ActionController::Http)
- @controller_class._helpers.instance_methods.map {|m| m.to_s }
- else
- @controller_class.master_helper_module.instance_methods.map {|m| m.to_s }
- end
+ @controller_class._helpers.instance_methods.map {|m| m.to_s }
end
def missing_methods
View
22 actionpack/test/controller/layout_test.rb
@@ -165,26 +165,10 @@ def test_layout_is_not_set_when_none_rendered
assert_nil @controller.template.layout
end
- for_tag(:old_base) do
- # exempt_from_layout is deprecated
- def test_exempt_from_layout_honored_by_render_template
- ActionController::Base.exempt_from_layout :erb
- @controller = RenderWithTemplateOptionController.new
-
- get :hello
- assert_equal "alt/hello.rhtml", @response.body.strip
-
- ensure
- ActionController::Base.exempt_from_layout.delete(ERB)
- end
- end
-
def test_layout_is_picked_from_the_controller_instances_view_path
- pending do
- @controller = PrependsViewPathController.new
- get :hello
- assert_equal 'layouts/alt', @controller.template.layout
- end
+ @controller = PrependsViewPathController.new
+ get :hello
+ assert @controller.template.layout =~ /layouts\/alt\.\w+/
end
def test_absolute_pathed_layout
View
32 actionpack/test/controller/mime_responds_test.rb
@@ -375,11 +375,9 @@ def test_handle_any_any_xml
end
def test_rjs_type_skips_layout
- pending(:new_base) do
- @request.accept = "text/javascript"
- get :all_types_with_layout
- assert_equal 'RJS for all_types_with_layout', @response.body
- end
+ @request.accept = "text/javascript"
+ get :all_types_with_layout
+ assert_equal 'RJS for all_types_with_layout', @response.body
end
def test_html_type_with_layout
@@ -467,14 +465,6 @@ def test_format_with_custom_response_type_and_request_headers
assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
assert_equal "text/html", @response.content_type
end
-
- def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present
- get :iphone_with_html_response_type_without_layout
- assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
-
- @request.accept = "text/iphone"
- assert_raise(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
- end
end
class AbstractPostController < ActionController::Base
@@ -529,16 +519,14 @@ def test_missing_layout_renders_properly
assert_equal 'Hello iPhone', @response.body
end
- for_tag(:old_base) do
- def test_format_with_inherited_layouts
- @controller = SuperPostController.new
+ def test_format_with_inherited_layouts
+ @controller = SuperPostController.new
- get :index
- assert_equal 'Super Firefox', @response.body
+ get :index
+ assert_equal '<html><div id="html">Super Firefox</div></html>', @response.body
- @request.accept = "text/iphone"
- get :index
- assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
- end
+ @request.accept = "text/iphone"
+ get :index
+ assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
end
end
View
2  actionpack/test/controller/record_identifier_test.rb
@@ -1,6 +1,8 @@
require 'abstract_unit'
class Comment
+ extend ActiveModel::Naming
+
attr_reader :id
def save; @id = 1 end
def new_record?; @id.nil? end
View
1  actionpack/test/controller/redirect_test.rb
@@ -4,6 +4,7 @@ class WorkshopsController < ActionController::Base
end
class Workshop
+ extend ActiveModel::Naming
attr_accessor :id, :new_record
def initialize(id, new_record)
View
14 actionpack/test/controller/render_test.rb
@@ -301,6 +301,9 @@ def accessing_local_assigns_in_inline_template
def render_implicit_html_template_from_xhr_request
end
+ def render_implicit_js_template_without_layout
+ end
+
def formatted_html_erb
end
@@ -928,16 +931,13 @@ def test_accessing_local_assigns_in_inline_template
end
def test_should_implicitly_render_html_template_from_xhr_request
- pending
- # xhr :get, :render_implicit_html_template_from_xhr_request
- # assert_equal "XHR!\nHello HTML!", @response.body
+ xhr :get, :render_implicit_html_template_from_xhr_request
+ assert_equal "XHR!\nHello HTML!", @response.body
end
def test_should_implicitly_render_js_template_without_layout
- pending do
- get :render_implicit_js_template_without_layout, :format => :js
- assert_no_match %r{<html>}, @response.body
- end
+ get :render_implicit_js_template_without_layout, :format => :js
+ assert_no_match %r{<html>}, @response.body
end
def test_should_render_formatted_template
View
4 actionpack/test/controller/send_file_test.rb
@@ -45,8 +45,8 @@ def test_file_nostream
assert_equal file_data, response.body
end
- for_tag(:old_base) do
- def test_file_stream
+ def test_file_stream
+ pending do
response = nil
assert_nothing_raised { response = process('file') }
assert_not_nil response
View
4 actionpack/test/dispatch/mime_type_test.rb
@@ -56,7 +56,7 @@ class MimeTypeTest < ActiveSupport::TestCase
test "type convenience methods" do
# Don't test Mime::ALL, since it Mime::ALL#html? == true
- types = Mime::SET.to_a.map{|m| m.to_sym }.uniq - [:all]
+ types = Mime::SET.symbols.uniq - [:all]
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
@@ -76,7 +76,7 @@ class MimeTypeTest < ActiveSupport::TestCase
end
test "verifiable mime types" do
- all_types = Mime::SET.to_a.map{|m| m.to_sym}
+ all_types = Mime::SET.symbols
all_types.uniq!
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
View
2  actionpack/test/fixtures/layouts/builder.builder
@@ -1,3 +1,3 @@
xml.wrapper do
- xml << @content_for_layout
+ xml << yield
end
View
2  actionpack/test/fixtures/layouts/standard.html.erb
@@ -1 +1 @@
-<html><%= @content_for_layout %><%= @variable_for_layout %></html>
+<html><%= yield %><%= @variable_for_layout %></html>
View
4 actionpack/test/fixtures/layouts/talk_from_action.erb
@@ -1,2 +1,2 @@
-<title><%= @title || @content_for_title %></title>
-<%= @content_for_layout -%>
+<title><%= @title || yield(:title) %></title>
+<%= yield -%>
View
1  actionpack/test/fixtures/test/render_implicit_js_template_without_layout.js.erb
@@ -0,0 +1 @@
+alert('hello');
View
6 actionpack/test/lib/controller/fake_models.rb
@@ -1,4 +1,8 @@
+require "active_model"
+
class Customer < Struct.new(:name, :id)
+ extend ActiveModel::Naming
+
def to_param
id.to_s
end
@@ -12,6 +16,8 @@ class GoodCustomer < Customer
module Quiz
class Question < Struct.new(:name, :id)
+ extend ActiveModel::Naming
+
def to_param
id.to_s
end
View
41 actionpack/test/lib/fixture_template.rb
@@ -1,6 +1,5 @@
module ActionView #:nodoc:
-class Template
- class FixturePath < Path
+ class FixtureResolver < Resolver
def initialize(hash = {}, options = {})
super(options)
@hash = hash
@@ -22,7 +21,7 @@ def find_templates(name, details, prefix, partial)
def formats_regexp
@formats_regexp ||= begin
- formats = Mime::SET.map { |m| m.symbol }
+ formats = Mime::SET.symbols
'(?:' + formats.map { |l| "\\.#{Regexp.escape(l.to_s)}" }.join('|') + ')?'
end
end
@@ -65,40 +64,4 @@ def path_to_details(path)
end
end
end
-
-
- # class FixtureTemplate < Template
- # class FixturePath < Template::Path
- # def initialize(hash = {})
- # @hash = {}
- #
- # hash.each do |k, v|
- # @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self)
- # end
- #
- # super("fixtures://root")
- # end
- #
- # def find_template(path)
- # @hash[path]
- # end
- # end
- #
- # def initialize(body, *args)
- # @body = body
- # super(*args)
- # end
- #
- # def source
- # @body
- # end
- #
- # private
- #
- # def find_full_path(path, load_paths)
- # return '/', path
- # end
- #
- # end
-end
end
View
2  actionpack/test/new_base/content_type_test.rb
@@ -19,7 +19,7 @@ def set_on_render
class ImpliedController < ActionController::Base
# Template's mime type is used if no content_type is specified
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
"content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
"content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'",
View
2  actionpack/test/new_base/etag_test.rb
@@ -2,7 +2,7 @@
module Etags
class BasicController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"etags/basic/base.html.erb" => "Hello from without_layout.html.erb",
"layouts/etags.html.erb" => "teh <%= yield %> tagz"
)]
View
8 actionpack/test/new_base/render_action_test.rb
@@ -3,7 +3,7 @@
module RenderAction
# This has no layout and it works
class BasicController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"render_action/basic/hello_world.html.erb" => "Hello world!"
)]
@@ -117,7 +117,7 @@ module RenderActionWithApplicationLayout
# # ==== Render actions with layouts ====
class BasicController < ::ApplicationController
# Set the view path to an application view structure with layouts
- self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
"render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
"render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
@@ -202,7 +202,7 @@ class TestLayout < SimpleRouteCase
module RenderActionWithControllerLayout
class BasicController < ActionController::Base
- self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
)]
@@ -263,7 +263,7 @@ class ControllerLayoutTest < SimpleRouteCase
module RenderActionWithBothLayouts
class BasicController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new({
+ self.view_paths = [ActionView::FixtureResolver.new({
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
"layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
View
2  actionpack/test/new_base/render_implicit_action_test.rb
@@ -2,7 +2,7 @@
module RenderImplicitAction
class SimpleController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
"render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!"
)]
View
6 actionpack/test/new_base/render_layout_test.rb
@@ -2,7 +2,7 @@
module ControllerLayouts
class ImplicitController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
"layouts/override.html.erb" => "Override! <%= yield %>",
"basic.html.erb" => "Hello world!",
@@ -26,7 +26,7 @@ def builder_override
end
class ImplicitNameController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI",
"basic.html.erb" => "Hello world!"
)]
@@ -68,7 +68,7 @@ class LayoutOptionsTest < SimpleRouteCase
end
class MismatchFormatController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "<html><%= yield %></html>",
"controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg",
"controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg"
View
2  actionpack/test/new_base/render_partial_test.rb
@@ -4,7 +4,7 @@ module RenderPartial
class BasicController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"render_partial/basic/_basic.html.erb" => "OMG!",
"render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>"
)]
View
46 actionpack/test/new_base/render_rjs_test.rb
@@ -0,0 +1,46 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module RenderRjs
+
+ class BasicController < ActionController::Base
+
+ self.view_paths = [ActionView::FixtureResolver.new(
+ "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')",
+ "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.js.erb" => "JS Partial",
+ "render_rjs/basic/_customer.html.erb" => "HTML Partial",
+ "render_rjs/basic/index_locale.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
+ "render_rjs/basic/_customer.da.html.erb" => "Danish HTML Partial",
+ "render_rjs/basic/_customer.da.js.erb" => "Danish JS Partial"
+ )]
+
+ def index
+ render
+ end
+
+ def index_locale
+ old_locale, I18n.locale = I18n.locale, :da
+ end
+
+ end
+
+ class TestBasic < SimpleRouteCase
+ testing BasicController
+
+ test "rendering a partial in an RJS template should pick the JS template over the HTML one" do
+ get :index
+ assert_response("$(\"customer\").update(\"JS Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template should pick the HTML template over the JS one" do
+ get :index_html
+ assert_response("$(\"customer\").update(\"HTML Partial\");")
+ end
+
+ test "replacing an element with a partial in an RJS template with a locale should pick the localed HTML template" do
+ get :index_locale, :format => :js
+ assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
+ end
+
+ end
+end
View
6 actionpack/test/new_base/render_template_test.rb
@@ -3,7 +3,7 @@
module RenderTemplate
class WithoutLayoutController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica",
"locals.html.erb" => "The secret is <%= secret %>",
@@ -79,7 +79,7 @@ class TestWithoutLayout < SimpleRouteCase
end
class WithLayoutController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica",
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
@@ -148,7 +148,7 @@ class TestWithLayout < SimpleRouteCase
module Compatibility
class WithoutLayoutController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica"
)]
View
2  actionpack/test/new_base/render_test.rb
@@ -2,7 +2,7 @@
module Render
class BlankRenderController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"render/blank_render/index.html.erb" => "Hello world!",
"render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
"render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>",
View
4 actionpack/test/new_base/render_text_test.rb
@@ -2,7 +2,7 @@
module RenderText
class SimpleController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new]
+ self.view_paths = [ActionView::FixtureResolver.new]
def index
render :text => "hello david"
@@ -10,7 +10,7 @@ def index
end
class WithLayoutController < ::ApplicationController
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
"layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.",
"layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>"
View
2  actionpack/test/new_base/render_xml_test.rb
@@ -4,7 +4,7 @@ module RenderXml
# This has no layout and it works
class BasicController < ActionController::Base
- self.view_paths = [ActionView::Template::FixturePath.new(
+ self.view_paths = [ActionView::FixtureResolver.new(
"render_xml/basic/with_render_erb" => "Hello world!"
)]
end
View
14 actionpack/test/template/active_record_helper_test.rb
@@ -33,8 +33,8 @@ def full_messages
["Author name can't be <em>empty</em>"]
end
- def on(field)
- "can't be <em>empty</em>"
+ def [](field)
+ ["can't be <em>empty</em>"]
end
end
@@ -47,14 +47,14 @@ def setup_post
@post = Post.new
def @post.errors
Class.new {
- def on(field)
+ def [](field)
case field.to_s
when "author_name"
- "can't be empty"
+ ["can't be empty"]
when "body"
- true
+ ['foo']
else
- false
+ []
end
end
def empty?() false end
@@ -85,7 +85,7 @@ def setup_user
@user = User.new
def @user.errors
Class.new {
- def on(field) field == "email" end
+ def [](field) field == "email" ? ['nonempty'] : [] end
def empty?() false end
def count() 1 end
def full_messages() [ "User email can't be empty" ] end
View
1  actionpack/test/template/atom_feed_helper_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
+Scroll.extend ActiveModel::Naming
class ScrollsController < ActionController::Base
FEEDS = {}
View
13 actionpack/test/template/body_parts_test.rb
@@ -4,9 +4,8 @@ class BodyPartsTest < ActionController::TestCase
RENDERINGS = [Object.new, Object.new, Object.new]
class TestController < ActionController::Base
- def performed?
- defined?(ActionController::Http) ? true : super
- end
+ def performed?() true end
+
def index
RENDERINGS.each do |rendering|
@template.punctuate_body! rendering
@@ -19,11 +18,9 @@ def index
def test_body_parts
get :index
- pending(:old_base) do
- # TestProcess buffers body_parts into body
- # TODO: Rewrite test w/o going through process
- assert_equal RENDERINGS, @response.body_parts
- end
+ # TestProcess buffers body_parts into body
+ # TODO: Rewrite test w/o going through process
+ assert_equal RENDERINGS, @response.body_parts
assert_equal RENDERINGS.join, @response.body
end
end
View
15 actionpack/test/template/capture_helper_test.rb
@@ -0,0 +1,15 @@
+require 'abstract_unit'
+
+class CaptureHelperTest < ActionView::TestCase
+ def setup
+ super
+ @_content_for = Hash.new {|h,k| h[k] = "" }
+ end
+
+ def test_content_for
+ assert ! content_for?(:title)
+ content_for :title, 'title'
+ assert content_for?(:title)
+ assert ! content_for?(:something_else)
+ end
+end
View
2  actionpack/test/template/compiled_templates_test.rb