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 a294d8362bfb62b7133ad0799ae1327cd5ddd1e4 2 parents 378b02d + e2d0b0e
@miloops miloops authored
Showing with 498 additions and 708 deletions.
  1. +6 −13 actionpack/Rakefile
  2. +8 −6 actionpack/lib/abstract_controller/logger.rb
  3. +4 −6 actionpack/lib/action_controller/dispatch/middlewares.rb
  4. +2 −0  actionpack/lib/action_controller/metal.rb
  5. +3 −42 actionpack/lib/action_controller/metal/rescuable.rb
  6. +4 −4 actionpack/lib/action_dispatch.rb
  7. +16 −4 actionpack/lib/action_dispatch/middleware/rescue.rb
  8. +2 −2 actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
  9. +5 −8 actionpack/lib/action_view.rb
  10. +0 −19 actionpack/lib/action_view/template/inline.rb
  11. +0 −18 actionpack/lib/action_view/template/partial.rb
  12. +0 −93 actionpack/lib/action_view/template/renderable.rb
  13. +1 −1  actionpack/test/{abstract_controller → abstract}/abstract_controller_test.rb
  14. +1 −1  actionpack/test/{abstract_controller → abstract}/callbacks_test.rb
  15. +1 −1  actionpack/test/{abstract_controller → abstract}/helper_test.rb
  16. +1 −1  actionpack/test/{abstract_controller → abstract}/layouts_test.rb
  17. 0  actionpack/test/{abstract_controller → abstract}/views/abstract_controller/testing/me3/formatted.html.erb
  18. 0  actionpack/test/{abstract_controller → abstract}/views/abstract_controller/testing/me3/index.erb
  19. 0  actionpack/test/{abstract_controller → abstract}/views/abstract_controller/testing/me4/index.erb
  20. 0  actionpack/test/{abstract_controller → abstract}/views/abstract_controller/testing/me5/index.erb
  21. 0  actionpack/test/{abstract_controller → abstract}/views/action_with_ivars.erb
  22. 0  actionpack/test/{abstract_controller → abstract}/views/helper_test.erb
  23. 0  actionpack/test/{abstract_controller → abstract}/views/index.erb
  24. 0  actionpack/test/{abstract_controller → abstract}/views/layouts/abstract_controller/testing/me4.erb
  25. 0  actionpack/test/{abstract_controller → abstract}/views/layouts/application.erb
  26. 0  actionpack/test/{abstract_controller → abstract}/views/naked_render.erb
  27. +79 −9 actionpack/test/abstract_unit.rb
  28. +0 −119 actionpack/test/abstract_unit2.rb
  29. +0 −10 actionpack/test/bundler_helper.rb
  30. +2 −2 actionpack/test/controller/caching_test.rb
  31. +7 −8 actionpack/test/controller/content_type_test.rb
  32. +1 −1  actionpack/test/controller/integration_test.rb
  33. +21 −17 actionpack/test/controller/render_js_test.rb
  34. +31 −27 actionpack/test/controller/render_json_test.rb
  35. +128 −123 actionpack/test/controller/render_other_test.rb
  36. +36 −32 actionpack/test/controller/render_xml_test.rb
  37. +10 −19 actionpack/test/controller/rescue_test.rb
  38. +1 −2  actionpack/test/dispatch/show_exceptions_test.rb
  39. 0  ...ck/test/fixtures/{content_type → old_content_type}/render_default_content_types_for_respond_to.xml.erb
  40. 0  actionpack/test/fixtures/{content_type → old_content_type}/render_default_for_rhtml.rhtml
  41. 0  actionpack/test/fixtures/{content_type → old_content_type}/render_default_for_rjs.rjs
  42. 0  actionpack/test/fixtures/{content_type → old_content_type}/render_default_for_rxml.rxml
  43. +1 −1  actionpack/test/new_base/base_test.rb
  44. +1 −1  actionpack/test/new_base/content_negotiation_test.rb
  45. +1 −1  actionpack/test/new_base/content_type_test.rb
  46. +1 −1  actionpack/test/new_base/etag_test.rb
  47. +1 −1  actionpack/test/new_base/metal_test.rb
  48. +1 −1  actionpack/test/new_base/middleware_test.rb
  49. +1 −1  actionpack/test/new_base/render_action_test.rb
  50. +1 −1  actionpack/test/new_base/render_file_test.rb
  51. +1 −1  actionpack/test/new_base/render_implicit_action_test.rb
  52. +1 −1  actionpack/test/new_base/render_layout_test.rb
  53. +1 −1  actionpack/test/new_base/render_partial_test.rb
  54. +9 −4 actionpack/test/new_base/render_rjs_test.rb
  55. +1 −1  actionpack/test/new_base/render_template_test.rb
  56. +1 −1  actionpack/test/new_base/render_test.rb
  57. +1 −1  actionpack/test/new_base/render_text_test.rb
  58. +1 −1  actionpack/test/new_base/render_xml_test.rb
  59. +5 −9 actionpack/test/template/render_test.rb
  60. +1 −1  activemodel/examples/validations.rb
  61. +1 −1  activemodel/lib/active_model/errors.rb
  62. +3 −4 activemodel/lib/active_model/lint.rb
  63. +19 −29 activerecord/lib/active_record/base.rb
  64. +4 −1 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  65. +8 −0 activerecord/test/cases/connection_test_mysql.rb
  66. +12 −0 activerecord/test/schema/mysql_specific_schema.rb
  67. +2 −2 activeresource/lib/active_resource/validations.rb
  68. +2 −2 activeresource/test/cases/base_errors_test.rb
  69. +0 −9 activesupport/lib/active_support/mini.rb
  70. +13 −21 activesupport/lib/active_support/xml_mini/nokogiri.rb
  71. +11 −0 activesupport/test/xml_mini/nokogiri_engine_test.rb
  72. +1 −1  ci/ci_build.rb
  73. +11 −13 railties/lib/generators.rb
  74. +1 −0  railties/lib/generators/base.rb
  75. +4 −2 railties/test/generators/generators_test_helper.rb
  76. +6 −6 railties/test/initializer/test_helper.rb
View
19 actionpack/Rakefile
@@ -32,24 +32,24 @@ end
# Run the unit tests
desc "Run all unit tests"
-task :test => [:test_action_pack, :test_active_record_integration, :test_new_base]
+task :test => [:test_action_pack, :test_active_record_integration]
+
+TESTS_GLOB = "test/{abstract,controller,dispatch,new_base,template,html-scanner}/**/*_test.rb"
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << 'test'
# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
- t.test_files = Dir.glob( "test/{controller,dispatch,template,html-scanner}/**/*_test.rb" ).sort
+ t.test_files = Dir.glob(TESTS_GLOB).sort
t.verbose = true
- #t.warning = true
+ # t.warning = true
end
task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- Dir.glob("test/{controller,dispatch,template}/**/*_test.rb").all? do |file|
- system(ruby, "-Itest", file)
- end or raise "Failures"
+ Dir.glob(TESTS_GLOB).all? { |file| system(ruby, '-Ilib:test', file) } or raise "Failures"
end
desc 'ActiveRecord Integration Tests'
@@ -59,13 +59,6 @@ Rake::TestTask.new(:test_active_record_integration) do |t|
t.verbose = true
end
-desc 'New Controller Tests'
-Rake::TestTask.new(:test_new_base) do |t|
- t.libs << 'test'
- t.test_files = Dir.glob("test/{abstract_controller,new_base}/*_test.rb")
- t.verbose = true
-end
-
# Genereate the RDoc documentation
Rake::RDocTask.new { |rdoc|
View
14 actionpack/lib/abstract_controller/logger.rb
@@ -11,15 +11,17 @@ module Logger
# just discard the String if the log level is too low.
#
# TODO: Require that Rails loggers accept a block.
- class DelayedLog
- def initialize(&blk)
- @blk = blk
+ class DelayedLog < ActiveSupport::BasicObject
+ def initialize(&block)
+ @str, @block = nil, block
end
- def to_s
- @blk.call
+ def method_missing(*args, &block)
+ unless @str
+ @str, @block = @block.call, nil
+ end
+ @str.send(*args, &block)
end
- alias to_str to_s
end
included do
View
10 actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -4,15 +4,13 @@
use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
use "ActionDispatch::Callbacks", lambda { ActionController::Dispatcher.prepare_each_request }
-use "ActionDispatch::Rescue", lambda {
- controller = (::ApplicationController rescue ActionController::Base)
- # TODO: Replace with controller.action(:_rescue_action)
- controller.method(:rescue_action)
-}
+
+# TODO: Redirect global exceptions somewhere?
+# use "ActionDispatch::Rescue"
use lambda { ActionController::Base.session_store },
lambda { ActionController::Base.session_options }
use "ActionDispatch::ParamsParser"
use "Rack::MethodOverride"
-use "Rack::Head"
+use "Rack::Head"
View
2  actionpack/lib/action_controller/metal.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/inheritable_attributes'
+
module ActionController
# ActionController::Metal provides a way to get a valid Rack application from a controller.
#
View
45 actionpack/lib/action_controller/metal/rescuable.rb
@@ -1,52 +1,13 @@
module ActionController #:nodoc:
- # Actions that fail to perform as expected throw exceptions. These
- # exceptions can either be rescued for the public view (with a nice
- # user-friendly explanation) or for the developers view (with tons of
- # debugging information). The developers view is already implemented by
- # the Action Controller, but the public view should be tailored to your
- # specific application.
- #
- # The default behavior for public exceptions is to render a static html
- # file with the name of the error code thrown. If no such file exists, an
- # empty response is sent with the correct status code.
- #
- # You can override what constitutes a local request by overriding the
- # <tt>local_request?</tt> method in your own controller. Custom rescue
- # behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
- # and <tt>rescue_action_locally</tt> methods.
module Rescue
extend ActiveSupport::Concern
-
- included do
- include ActiveSupport::Rescuable
- end
-
- module ClassMethods
- # This can be removed once we can move action(:_rescue_action) into middlewares.rb
- # Currently, it does controller.method(:rescue_action), which is hiding the implementation
- # difference between the old and new base.
- def rescue_action(env)
- action(:_rescue_action).call(env)
- end
- end
-
- attr_internal :rescued_exception
+ include ActiveSupport::Rescuable
private
- def method_for_action(action_name)
- return action_name if self.rescued_exception = request.env.delete("action_dispatch.rescue.exception")
- super
- end
-
- def _rescue_action
- rescue_with_handler(rescued_exception) || raise(rescued_exception)
- end
-
- def process_action(*)
+ def process_action(*args)
super
rescue Exception => exception
- self.rescued_exception = exception
- _rescue_action
+ rescue_with_handler(exception) || raise(exception)
end
end
end
View
8 actionpack/lib/action_dispatch.rb
@@ -21,10 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
-$:.unshift activesupport_path if File.directory?(activesupport_path)
-require 'active_support'
-
require 'rack'
module Rack
@@ -59,3 +55,7 @@ module Session
end
autoload :Mime, 'action_dispatch/http/mime_type'
+
+activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+$:.unshift activesupport_path if File.directory?(activesupport_path)
+require 'active_support'
View
20 actionpack/lib/action_dispatch/middleware/rescue.rb
@@ -1,14 +1,26 @@
module ActionDispatch
class Rescue
- def initialize(app, rescuer)
- @app, @rescuer = app, rescuer
+ def initialize(app, rescuers = {}, &block)
+ @app, @rescuers = app, {}
+ rescuers.each { |exception, rescuer| rescue_from(exception, rescuer) }
+ instance_eval(&block) if block_given?
end
def call(env)
@app.call(env)
rescue Exception => exception
- env['action_dispatch.rescue.exception'] = exception
- @rescuer.call(env)
+ if rescuer = @rescuers[exception.class.name]
+ env['action_dispatch.rescue.exception'] = exception
+ rescuer.call(env)
+ else
+ raise exception
+ end
end
+
+ protected
+ def rescue_from(exception, rescuer)
+ exception = exception.class.name if exception.is_a?(Exception)
+ @rescuers[exception.to_s] = rescuer
+ end
end
end
View
4 actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
@@ -15,12 +15,12 @@
show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';"
hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"}
%>
- <a href="#" onclick="<%= hide %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
+ <a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
<% end %>
<% traces.each do |name, trace| %>
<div id="<%= name.gsub /\s/, '-' %>" style="display: <%= name == "Application Trace" ? 'block' : 'none' %>;">
- <pre><code><%= trace.join "\n" %></code></pre>
+ <pre><code><%=h trace.join "\n" %></code></pre>
</div>
<% end %>
</div>
View
13 actionpack/lib/action_view.rb
@@ -21,11 +21,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
-$:.unshift activesupport_path if File.directory?(activesupport_path)
-require 'active_support'
-require 'active_support/core_ext/class/attribute_accessors'
-
require File.join(File.dirname(__FILE__), "action_pack")
module ActionView
@@ -36,15 +31,12 @@ def self.load_all!
autoload :Base, 'action_view/base'
autoload :Context, 'action_view/context'
autoload :Helpers, 'action_view/helpers'
- autoload :InlineTemplate, 'action_view/template/inline'
autoload :MissingTemplate, 'action_view/base'
autoload :Partials, 'action_view/render/partials'
autoload :Resolver, 'action_view/template/resolver'
autoload :PathResolver, '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'
@@ -59,3 +51,8 @@ class ERB
end
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
+
+activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+$:.unshift activesupport_path if File.directory?(activesupport_path)
+require 'active_support'
+require 'active_support/core_ext/class/attribute_accessors'
View
19 actionpack/lib/action_view/template/inline.rb
@@ -1,19 +0,0 @@
-module ActionView #:nodoc:
- class InlineTemplate #:nodoc:
- include Renderable
-
- attr_reader :source, :extension, :method_segment
-
- def initialize(source, type = nil)
- @source = source
- @extension = type
- @method_segment = "inline_#{@source.hash.abs}"
- end
-
- private
- # Always recompile inline templates
- def recompile?
- true
- end
- end
-end
View
18 actionpack/lib/action_view/template/partial.rb
@@ -1,18 +0,0 @@
-module ActionView
- # NOTE: The template that this mixin is being included into is frozen
- # so you cannot set or modify any instance variables
- module RenderablePartial #:nodoc:
- extend ActiveSupport::Memoizable
-
- def variable_name
- name.sub(/\A_/, '').to_sym
- end
- memoize :variable_name
-
- def counter_name
- "#{variable_name}_counter".to_sym
- end
- memoize :counter_name
-
- end
-end
View
93 actionpack/lib/action_view/template/renderable.rb
@@ -1,93 +0,0 @@
-# encoding: utf-8
-
-module ActionView
- # NOTE: The template that this mixin is being included into is frozen
- # so you cannot set or modify any instance variables
- module Renderable #:nodoc:
- extend ActiveSupport::Memoizable
-
- def render(view, locals)
- compile(locals)
- view.send(method_name(locals), locals) {|*args| yield(*args) }
- end
-
- def load!
- names = CompiledTemplates.instance_methods.grep(/#{method_name_without_locals}/)
- names.each do |name|
- CompiledTemplates.class_eval do
- remove_method(name)
- end
- end
- super
- end
-
- private
-
- def filename
- 'compiled-template'
- end
-
- def handler
- Template.handler_class_for_extension(extension)
- end
- memoize :handler
-
- def compiled_source
- handler.call(self)
- end
- memoize :compiled_source
-
- def method_name_without_locals
- ['_run', extension, method_segment].compact.join('_')
- end
- memoize :method_name_without_locals
-
- def method_name(local_assigns)
- if local_assigns && local_assigns.any?
- method_name = method_name_without_locals.dup
- method_name << "_locals_#{local_assigns.keys.map { |k| k.to_s }.sort.join('_')}"
- else
- method_name = method_name_without_locals
- end
- method_name.to_sym
- end
-
- # Compile and evaluate the template's code (if necessary)
- def compile(local_assigns)
- render_symbol = method_name(local_assigns)
-
- if !CompiledTemplates.method_defined?(render_symbol) || recompile?
- compile!(render_symbol, local_assigns)
- end
- end
-
- private
- def compile!(render_symbol, local_assigns)
- locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
-
- source = <<-end_src
- def #{render_symbol}(local_assigns)
- old_output_buffer = output_buffer;#{locals_code};#{compiled_source}
- ensure
- self.output_buffer = old_output_buffer
- end
- end_src
-
- begin
- ActionView::CompiledTemplates.module_eval(source, filename.to_s, 0)
- rescue Exception => e # errors from template code
- if logger = defined?(ActionController) && Base.logger
- logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
- logger.debug "Function body: #{source}"
- logger.debug "Backtrace: #{e.backtrace.join("\n")}"
- end
-
- raise ActionView::TemplateError.new(self, {}, e)
- end
- end
-
- def recompile?
- false
- end
- end
-end
View
2  ...t/abstract_controller/abstract_controller_test.rb → actionpack/test/abstract/abstract_controller_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
View
2  ...onpack/test/abstract_controller/callbacks_test.rb → actionpack/test/abstract/callbacks_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
View
2  actionpack/test/abstract_controller/helper_test.rb → actionpack/test/abstract/helper_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
View
2  actionpack/test/abstract_controller/layouts_test.rb → actionpack/test/abstract/layouts_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
require 'active_support/core_ext/class/removal'
module AbstractControllerTests
View
0  ...bstract_controller/testing/me3/formatted.html.erb → ...bstract_controller/testing/me3/formatted.html.erb
File renamed without changes
View
0  ...r/views/abstract_controller/testing/me3/index.erb → ...t/views/abstract_controller/testing/me3/index.erb
File renamed without changes
View
0  ...r/views/abstract_controller/testing/me4/index.erb → ...t/views/abstract_controller/testing/me4/index.erb
File renamed without changes
View
0  ...r/views/abstract_controller/testing/me5/index.erb → ...t/views/abstract_controller/testing/me5/index.erb
File renamed without changes
View
0  ...t/abstract_controller/views/action_with_ivars.erb → actionpack/test/abstract/views/action_with_ivars.erb
File renamed without changes
View
0  ...ck/test/abstract_controller/views/helper_test.erb → actionpack/test/abstract/views/helper_test.erb
File renamed without changes
View
0  actionpack/test/abstract_controller/views/index.erb → actionpack/test/abstract/views/index.erb
File renamed without changes
View
0  ...views/layouts/abstract_controller/testing/me4.erb → ...views/layouts/abstract_controller/testing/me4.erb
File renamed without changes
View
0  ...abstract_controller/views/layouts/application.erb → ...npack/test/abstract/views/layouts/application.erb
File renamed without changes
View
0  ...k/test/abstract_controller/views/naked_render.erb → actionpack/test/abstract/views/naked_render.erb
File renamed without changes
View
88 actionpack/test/abstract_unit.rb
@@ -6,26 +6,31 @@
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
-require 'bundler_helper'
-ensure_requirable %w( rack rack/test sqlite3 )
+bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
+require bundler if File.exist?("#{bundler}.rb")
-ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
+begin
+ %w( rack rack/test sqlite3 ).each { |lib| require lib }
+rescue LoadError => e
+ abort e.message
+end
-ENV['new_base'] = "true"
-$stderr.puts "Running old tests on new_base"
+ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
+require 'abstract_controller'
require 'action_controller'
+require 'action_view'
+require 'action_view/base'
+require 'action_dispatch'
+require 'active_model'
require 'fixture_template'
require 'action_controller/testing/process'
-require 'action_view/test_case'
require 'action_controller/testing/integration'
+require 'action_view/test_case'
require 'active_support/dependencies'
-require 'active_model'
-
-$tags[:new_base] = true
begin
require 'ruby-debug'
@@ -35,6 +40,8 @@
# Debugging disabled. `gem install ruby-debug` to enable.
end
+require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
+
ActiveSupport::Dependencies.hook!
# Show backtraces for deprecated behavior for quicker cleanup.
@@ -57,6 +64,61 @@ class TestCase
end
end
+# Temporary base class
+class Rack::TestCase < ActionController::IntegrationTest
+ setup do
+ ActionController::Base.session_options[:key] = "abc"
+ ActionController::Base.session_options[:secret] = ("*" * 30)
+ end
+
+ def app
+ @app ||= ActionController::Dispatcher.new
+ end
+
+ def self.testing(klass = nil)
+ if klass
+ @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '')
+ else
+ @testing
+ end
+ end
+
+ def get(thing, *args)
+ if thing.is_a?(Symbol)
+ super("#{self.class.testing}/#{thing}", *args)
+ else
+ super
+ end
+ end
+
+ def assert_body(body)
+ assert_equal body, Array.wrap(response.body).join
+ end
+
+ def assert_status(code)
+ assert_equal code, response.status
+ end
+
+ def assert_response(body, status = 200, headers = {})
+ assert_body body
+ assert_status status
+ headers.each do |header, value|
+ assert_header header, value
+ end
+ end
+
+ def assert_content_type(type)
+ assert_equal type, response.headers["Content-Type"]
+ end
+
+ def assert_header(name, value)
+ assert_equal value, response.headers[name]
+ end
+end
+
+class ::ApplicationController < ActionController::Base
+end
+
module ActionController
Base.session = {
:key => '_testing_session',
@@ -133,3 +195,11 @@ def assert_template(options = {}, message = nil)
end
end
end
+
+class SimpleRouteCase < Rack::TestCase
+ setup do
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
+ end
+end
View
119 actionpack/test/abstract_unit2.rb
@@ -1,119 +0,0 @@
-# TODO: Unify with abstract_unit
-
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/lib')
-
-require 'bundler_helper'
-ensure_requirable %w( rack rack/test )
-
-require 'test/unit'
-require 'active_support'
-require 'active_support/test_case'
-require 'abstract_controller'
-require 'action_view'
-require 'action_view/base'
-require 'action_dispatch'
-require 'fixture_template'
-
-begin
- require 'ruby-debug'
- Debugger.settings[:autoeval] = true
- Debugger.start
-rescue LoadError
- # Debugging disabled. `gem install ruby-debug` to enable.
-end
-
-require 'action_controller'
-require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
-
-require 'action_controller/testing/process'
-require 'action_controller/testing/integration'
-
-module Rails
- def self.env
- x = Object.new
- def x.test?() true end
- x
- end
-end
-
-# Temporary base class
-class Rack::TestCase < ActionController::IntegrationTest
- setup do
- ActionController::Base.session_options[:key] = "abc"
- ActionController::Base.session_options[:secret] = ("*" * 30)
- end
-
- def app
- @app ||= ActionController::Dispatcher.new
- end
-
- def self.testing(klass = nil)
- if klass
- @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '')
- else
- @testing
- end
- end
-
- def get(thing, *args)
- if thing.is_a?(Symbol)
- super("#{self.class.testing}/#{thing}", *args)
- else
- super
- end
- end
-
- def assert_body(body)
- assert_equal body, Array.wrap(response.body).join
- end
-
- def assert_status(code)
- assert_equal code, response.status
- end
-
- def assert_response(body, status = 200, headers = {})
- assert_body body
- assert_status status
- headers.each do |header, value|
- assert_header header, value
- end
- end
-
- def assert_content_type(type)
- assert_equal type, response.headers["Content-Type"]
- end
-
- def assert_header(name, value)
- assert_equal value, response.headers[name]
- end
-end
-
-class ::ApplicationController < ActionController::Base
-end
-
-module ActionController
- class << Routing
- def possible_controllers
- @@possible_controllers ||= []
- end
- end
-
- class Base
- def self.inherited(klass)
- name = klass.name.underscore.sub(/_controller$/, '')
- ActionController::Routing.possible_controllers << name unless name.blank?
- super
- end
- end
-end
-
-class SimpleRouteCase < Rack::TestCase
- setup do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- end
- end
-end
View
10 actionpack/test/bundler_helper.rb
@@ -1,10 +0,0 @@
-def ensure_requirable(libs)
- bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
- require bundler if File.exist?("#{bundler}.rb")
-
- begin
- libs.each { |lib| require lib }
- rescue LoadError => e
- abort e.message
- end
-end
View
4 actionpack/test/controller/caching_test.rb
@@ -441,8 +441,8 @@ def test_xml_version_of_resource_is_treated_as_different_cache
def test_correct_content_type_is_returned_for_cache_hit
# run it twice to cache it the first time
- get :index, :id => 'content-type.xml'
- get :index, :id => 'content-type.xml'
+ get :index, :id => 'content-type', :format => 'xml'
+ get :index, :id => 'content-type', :format => 'xml'
assert_equal 'application/xml', @response.content_type
end
View
15 actionpack/test/controller/content_type_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class ContentTypeController < ActionController::Base
+class OldContentTypeController < ActionController::Base
# :ported:
def render_content_type_from_body
response.content_type = Mime::RSS
@@ -56,7 +56,7 @@ def rescue_action(e) raise end
end
class ContentTypeTest < ActionController::TestCase
- tests ContentTypeController
+ tests OldContentTypeController
def setup
super
@@ -73,11 +73,11 @@ def test_render_defaults
end
def test_render_changed_charset_default
- ContentTypeController.default_charset = "utf-16"
+ OldContentTypeController.default_charset = "utf-16"
get :render_defaults
assert_equal "utf-16", @response.charset
assert_equal Mime::HTML, @response.content_type
- ContentTypeController.default_charset = "utf-8"
+ OldContentTypeController.default_charset = "utf-8"
end
# :ported:
@@ -109,12 +109,12 @@ def test_nil_charset_from_body
end
def test_nil_default_for_rhtml
- ContentTypeController.default_charset = nil
+ OldContentTypeController.default_charset = nil
get :render_default_for_rhtml
assert_equal Mime::HTML, @response.content_type
assert_nil @response.charset, @response.headers.inspect
ensure
- ContentTypeController.default_charset = "utf-8"
+ OldContentTypeController.default_charset = "utf-8"
end
def test_default_for_rhtml
@@ -143,8 +143,7 @@ def test_change_for_rxml
end
class AcceptBasedContentTypeTest < ActionController::TestCase
-
- tests ContentTypeController
+ tests OldContentTypeController
def setup
super
View
2  actionpack/test/controller/integration_test.rb
@@ -377,7 +377,7 @@ def with_test_route_set
end
end
-class MetalTest < ActionController::IntegrationTest
+class MetalIntegrationTest < ActionController::IntegrationTest
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/success/
View
38 actionpack/test/controller/render_js_test.rb
@@ -2,23 +2,27 @@
require 'controller/fake_models'
require 'pathname'
-class TestController < ActionController::Base
- protect_from_forgery
+class RenderJSTest < ActionController::TestCase
+ class TestController < ActionController::Base
+ protect_from_forgery
- def render_vanilla_js_hello
- render :js => "alert('hello')"
- end
-
- def greeting
- # let's just rely on the template
+ def self.controller_path
+ 'test'
+ end
+
+ def render_vanilla_js_hello
+ render :js => "alert('hello')"
+ end
+
+ def greeting
+ # let's just rely on the template
+ end
+
+ def show_partial
+ render :partial => 'partial'
+ end
end
-
- def show_partial
- render :partial => 'partial'
- end
-end
-class RenderTest < ActionController::TestCase
tests TestController
def test_render_vanilla_js
@@ -26,14 +30,14 @@ def test_render_vanilla_js
assert_equal "alert('hello')", @response.body
assert_equal "text/javascript", @response.content_type
end
-
+
def test_render_with_default_from_accept_header
xhr :get, :greeting
assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
end
-
+
def test_should_render_js_partial
xhr :get, :show_partial, :format => 'js'
assert_equal 'partial js', @response.body
end
-end
+end
View
58 actionpack/test/controller/render_json_test.rb
@@ -2,35 +2,39 @@
require 'controller/fake_models'
require 'pathname'
-class TestController < ActionController::Base
- protect_from_forgery
-
- def render_json_nil
- render :json => nil
- end
+class RenderJsonTest < ActionController::TestCase
+ class TestController < ActionController::Base
+ protect_from_forgery
- def render_json_hello_world
- render :json => ActiveSupport::JSON.encode(:hello => 'world')
- end
+ def self.controller_path
+ 'test'
+ end
- def render_json_hello_world_with_callback
- render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
- end
+ def render_json_nil
+ render :json => nil
+ end
- def render_json_with_custom_content_type
- render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
- end
+ def render_json_hello_world
+ render :json => ActiveSupport::JSON.encode(:hello => 'world')
+ end
- def render_symbol_json
- render :json => ActiveSupport::JSON.encode(:hello => 'world')
- end
+ def render_json_hello_world_with_callback
+ render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
+ end
- def render_json_with_render_to_string
- render :json => {:hello => render_to_string(:partial => 'partial')}
- end
-end
+ def render_json_with_custom_content_type
+ render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
+ end
+
+ def render_symbol_json
+ render :json => ActiveSupport::JSON.encode(:hello => 'world')
+ end
+
+ def render_json_with_render_to_string
+ render :json => {:hello => render_to_string(:partial => 'partial')}
+ end
+ end
-class RenderTest < ActionController::TestCase
tests TestController
def setup
@@ -40,8 +44,8 @@ def setup
@controller.logger = Logger.new(nil)
@request.host = "www.nextangle.com"
- end
-
+ end
+
def test_render_json_nil
get :render_json_nil
assert_equal 'null', @response.body
@@ -76,5 +80,5 @@ def test_render_json_with_render_to_string
get :render_json_with_render_to_string
assert_equal '{"hello":"partial html"}', @response.body
assert_equal 'application/json', @response.content_type
- end
-end
+ end
+end
View
251 actionpack/test/controller/render_other_test.rb
@@ -2,139 +2,144 @@
require 'controller/fake_models'
require 'pathname'
-class TestController < ActionController::Base
- protect_from_forgery
- layout :determine_layout
+class RenderOtherTest < ActionController::TestCase
+ class TestController < ActionController::Base
+ protect_from_forgery
- module RenderTestHelper
- def rjs_helper_method_from_module
- page.visual_effect :highlight
+ def self.controller_path
+ 'test'
end
- end
- helper RenderTestHelper
- helper do
- def rjs_helper_method(value)
- page.visual_effect :highlight, value
+ layout :determine_layout
+
+ module RenderTestHelper
+ def rjs_helper_method_from_module
+ page.visual_effect :highlight
+ end
end
- end
- def enum_rjs_test
- render :update do |page|
- page.select('.product').each do |value|
- page.rjs_helper_method_from_module
- page.rjs_helper_method(value)
- page.sortable(value, :url => { :action => "order" })
- page.draggable(value)
+ helper RenderTestHelper
+ helper do
+ def rjs_helper_method(value)
+ page.visual_effect :highlight, value
end
end
- end
-
- def render_explicit_html_template
- end
-
- def render_custom_code_rjs
- render :update, :status => 404 do |page|
- page.replace :foo, :partial => 'partial'
+
+ def enum_rjs_test
+ render :update do |page|
+ page.select('.product').each do |value|
+ page.rjs_helper_method_from_module
+ page.rjs_helper_method(value)
+ page.sortable(value, :url => { :action => "order" })
+ page.draggable(value)
+ end
+ end
end
- end
-
- def render_implicit_html_template
- end
-
- def render_js_with_explicit_template
- @project_id = 4
- render :template => 'test/delete_with_js'
- end
- def render_js_with_explicit_action_template
- @project_id = 4
- render :action => 'delete_with_js'
- end
-
- def delete_with_js
- @project_id = 4
- end
-
- def update_page
- render :update do |page|
- page.replace_html 'balance', '$37,000,000.00'
- page.visual_effect :highlight, 'balance'
+ def render_explicit_html_template
+ end
+
+ def render_custom_code_rjs
+ render :update, :status => 404 do |page|
+ page.replace :foo, :partial => 'partial'
+ end
end
- end
- def update_page_with_instance_variables
- @money = '$37,000,000.00'
- @div_id = 'balance'
- render :update do |page|
- page.replace_html @div_id, @money
- page.visual_effect :highlight, @div_id
+ def render_implicit_html_template
end
- end
- def update_page_with_view_method
- render :update do |page|
- page.replace_html 'person', pluralize(2, 'person')
+ def render_js_with_explicit_template
+ @project_id = 4
+ render :template => 'test/delete_with_js'
end
- end
-
- def partial_as_rjs
- render :update do |page|
- page.replace :foo, :partial => 'partial'
+
+ def render_js_with_explicit_action_template
+ @project_id = 4
+ render :action => 'delete_with_js'
end
- end
- def respond_to_partial_as_rjs
- respond_to do |format|
- format.js do
- render :update do |page|
- page.replace :foo, :partial => 'partial'
- end
+ def delete_with_js
+ @project_id = 4
+ end
+
+ def update_page
+ render :update do |page|
+ page.replace_html 'balance', '$37,000,000.00'
+ page.visual_effect :highlight, 'balance'
end
end
- end
-
- def render_alternate_default
- # For this test, the method "default_render" is overridden:
- @alternate_default_render = lambda do
+
+ def update_page_with_instance_variables
+ @money = '$37,000,000.00'
+ @div_id = 'balance'
+ render :update do |page|
+ page.replace_html @div_id, @money
+ page.visual_effect :highlight, @div_id
+ end
+ end
+
+ def update_page_with_view_method
+ render :update do |page|
+ page.replace_html 'person', pluralize(2, 'person')
+ end
+ end
+
+ def partial_as_rjs
render :update do |page|
page.replace :foo, :partial => 'partial'
end
end
- end
-
-private
- def default_render
- if @alternate_default_render
- @alternate_default_render.call
- else
- super
+
+ def respond_to_partial_as_rjs
+ respond_to do |format|
+ format.js do
+ render :update do |page|
+ page.replace :foo, :partial => 'partial'
+ end
+ end
+ end
end
- end
- def determine_layout
- case action_name
- when "hello_world", "layout_test", "rendering_without_layout",
- "rendering_nothing_on_layout", "render_text_hello_world",
- "render_text_hello_world_with_layout",
- "hello_world_with_layout_false",
- "partial_only", "partial_only_with_layout",
- "accessing_params_in_template",
- "accessing_params_in_template_with_layout",
- "render_with_explicit_template",
- "render_with_explicit_string_template",
- "update_page", "update_page_with_instance_variables"
-
- "layouts/standard"
- when "action_talk_to_layout", "layout_overriding_layout"
- "layouts/talk_from_action"
- when "render_implicit_html_template_from_xhr_request"
- (request.xhr? ? 'layouts/xhr' : 'layouts/standard')
- end
- end
-end
+ def render_alternate_default
+ # For this test, the method "default_render" is overridden:
+ @alternate_default_render = lambda do
+ render :update do |page|
+ page.replace :foo, :partial => 'partial'
+ end
+ end
+ end
+
+ private
+ def default_render
+ if @alternate_default_render
+ @alternate_default_render.call
+ else
+ super
+ end
+ end
+
+ def determine_layout
+ case action_name
+ when "hello_world", "layout_test", "rendering_without_layout",
+ "rendering_nothing_on_layout", "render_text_hello_world",
+ "render_text_hello_world_with_layout",
+ "hello_world_with_layout_false",
+ "partial_only", "partial_only_with_layout",
+ "accessing_params_in_template",
+ "accessing_params_in_template_with_layout",
+ "render_with_explicit_template",
+ "render_with_explicit_string_template",
+ "update_page", "update_page_with_instance_variables"
+
+ "layouts/standard"
+ when "action_talk_to_layout", "layout_overriding_layout"
+ "layouts/talk_from_action"
+ when "render_implicit_html_template_from_xhr_request"
+ (request.xhr? ? 'layouts/xhr' : 'layouts/standard')
+ end
+ end
+ end
-class RenderTest < ActionController::TestCase
tests TestController
def setup
@@ -144,8 +149,8 @@ def setup
@controller.logger = Logger.new(nil)
@request.host = "www.nextangle.com"
- end
-
+ end
+
def test_enum_rjs_test
ActiveSupport::SecureRandom.stubs(:base64).returns("asdf")
get :enum_rjs_test
@@ -153,13 +158,13 @@ def test_enum_rjs_test
$$(".product").each(function(value, index) {
new Effect.Highlight(element,{});
new Effect.Highlight(value,{});
- Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}});
+ Sortable.create(value, {onUpdate:function(){new Ajax.Request('/render_other_test/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}});
new Draggable(value, {});
});
}.gsub(/^ /, '').strip
assert_equal body, @response.body
end
-
+
def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
[:js, "js"].each do |format|
assert_nothing_raised do
@@ -167,14 +172,14 @@ def test_explicitly_rendering_an_html_template_with_implicit_html_template_rende
assert_equal %(document.write("Hello world\\n");), @response.body
end
end
- end
-
+ end
+
def test_render_custom_code_rjs
get :render_custom_code_rjs
assert_response 404
assert_equal %(Element.replace("foo", "partial html");), @response.body
end
-
+
def test_render_in_an_rjs_template_should_pick_html_templates_when_available
[:js, "js"].each do |format|
assert_nothing_raised do
@@ -183,7 +188,7 @@ def test_render_in_an_rjs_template_should_pick_html_templates_when_available
end
end
end
-
+
def test_render_rjs_template_explicitly
get :render_js_with_explicit_template
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
@@ -193,12 +198,12 @@ def test_rendering_rjs_action_explicitly
get :render_js_with_explicit_action_template
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
end
-
+
def test_render_rjs_with_default
get :delete_with_js
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
end
-
+
def test_update_page
get :update_page
assert_template nil
@@ -219,8 +224,8 @@ def test_update_page_with_view_method
assert_template nil
assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
assert_match /2 people/, @response.body
- end
-
+ end
+
def test_should_render_html_formatted_partial_with_rjs
xhr :get, :partial_as_rjs
assert_equal %(Element.replace("foo", "partial html");), @response.body
@@ -230,9 +235,9 @@ def test_should_render_html_formatted_partial_with_rjs_and_js_format
xhr :get, :respond_to_partial_as_rjs
assert_equal %(Element.replace("foo", "partial html");), @response.body
end
-
+
def test_should_render_with_alternate_default_render
xhr :get, :render_alternate_default
assert_equal %(Element.replace("foo", "partial html");), @response.body
- end
-end
+ end
+end
View
68 actionpack/test/controller/render_xml_test.rb
@@ -2,37 +2,41 @@
require 'controller/fake_models'
require 'pathname'
-class TestController < ActionController::Base
- protect_from_forgery
+class RenderXmlTest < ActionController::TestCase
+ class TestController < ActionController::Base
+ protect_from_forgery
- def render_with_location
- render :xml => "<hello/>", :location => "http://example.com", :status => 201
- end
+ def self.controller_path
+ 'test'
+ end
- def render_with_object_location
- customer = Customer.new("Some guy", 1)
- render :xml => "<customer/>", :location => customer, :status => :created
- end
+ def render_with_location
+ render :xml => "<hello/>", :location => "http://example.com", :status => 201
+ end
- def render_with_to_xml
- to_xmlable = Class.new do
- def to_xml
- "<i-am-xml/>"
- end
- end.new
+ def render_with_object_location
+ customer = Customer.new("Some guy", 1)
+ render :xml => "<customer/>", :location => customer, :status => :created
+ end
- render :xml => to_xmlable
- end
-
- def formatted_xml_erb
+ def render_with_to_xml
+ to_xmlable = Class.new do
+ def to_xml
+ "<i-am-xml/>"
+ end
+ end.new
+
+ render :xml => to_xmlable
+ end
+
+ def formatted_xml_erb
+ end
+
+ def render_xml_with_custom_content_type
+ render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
+ end
end
-
- def render_xml_with_custom_content_type
- render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
- end
-end
-class RenderTest < ActionController::TestCase
tests TestController
def setup
@@ -42,8 +46,8 @@ def setup
@controller.logger = Logger.new(nil)
@request.host = "www.nextangle.com"
- end
-
+ end
+
def test_rendering_with_location_should_set_header
get :render_with_location
assert_equal "http://example.com", @response.headers["Location"]
@@ -53,7 +57,7 @@ def test_rendering_xml_should_call_to_xml_if_possible
get :render_with_to_xml
assert_equal "<i-am-xml/>", @response.body
end
-
+
def test_rendering_with_object_location_should_set_header_with_url_for
with_routing do |set|
set.draw do |map|
@@ -65,19 +69,19 @@ def test_rendering_with_object_location_should_set_header_with_url_for
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
end
end
-
+
def test_should_render_formatted_xml_erb_template
get :formatted_xml_erb, :format => :xml
assert_equal '<test>passed formatted xml erb</test>', @response.body
end
-
+
def test_should_render_xml_but_keep_custom_content_type
get :render_xml_with_custom_content_type
assert_equal "application/atomsvc+xml", @response.content_type
end
-
+
def test_should_use_implicit_content_type
get :implicit_content_type, :format => 'atom'
assert_equal Mime::ATOM, @response.content_type
- end
+ end
end
View
29 actionpack/test/controller/rescue_test.rb
@@ -227,12 +227,6 @@ def test_exception_in_parent_controller
end
end
-class ApplicationController < ActionController::Base
- rescue_from ActionController::RoutingError do
- render :text => 'no way'
- end
-end
-
class RescueControllerTest < ActionController::TestCase
def test_rescue_handler
get :not_authorized
@@ -332,23 +326,20 @@ def show_errors(exception)
end
test 'rescue routing exceptions' do
- assert_equal 1, ApplicationController.rescue_handlers.length
-
- begin
- with_test_routing do
- get '/no_way'
- assert_equal 'no way', response.body
- end
- ensure
- ActionController::Base.rescue_handlers.clear
+ app = ActionDispatch::Rescue.new(ActionController::Routing::Routes) do
+ rescue_from ActionController::RoutingError, lambda { |env| [200, {"Content-Type" => "text/html"}, "Gotcha!"] }
end
+ @integration_session = open_session(app)
+
+ get '/b00m'
+ assert_equal "Gotcha!", response.body
end
test 'unrescued exception' do
- with_test_routing do
- get '/b00m'
- assert_match(/Action Controller: Exception caught/, response.body)
- end
+ app = ActionDispatch::Rescue.new(ActionController::Routing::Routes)
+ @integration_session = open_session(app)
+
+ assert_raise(ActionController::RoutingError) { get '/b00m' }
end
private
View
3  actionpack/test/dispatch/show_exceptions_test.rb
@@ -70,8 +70,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
test "localize public rescue message" do
# Change locale
- old_locale = I18n.locale
- I18n.locale = :da
+ old_locale, I18n.locale = I18n.locale, :da
begin
@integration_session = open_session(ProductionApp)
View
0  ...nder_default_content_types_for_respond_to.xml.erb → ...nder_default_content_types_for_respond_to.xml.erb
File renamed without changes
View
0  ...tures/content_type/render_default_for_rhtml.rhtml → ...s/old_content_type/render_default_for_rhtml.rhtml
File renamed without changes
View
0  .../fixtures/content_type/render_default_for_rjs.rjs → ...tures/old_content_type/render_default_for_rjs.rjs
File renamed without changes
View
0  ...ixtures/content_type/render_default_for_rxml.rxml → ...res/old_content_type/render_default_for_rxml.rxml
File renamed without changes
View
2  actionpack/test/new_base/base_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
# Tests the controller dispatching happy path
module Dispatching
View
2  actionpack/test/new_base/content_negotiation_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ContentNegotiation
View
2  actionpack/test/new_base/content_type_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ContentType
class BaseController < ActionController::Base
View
2  actionpack/test/new_base/etag_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module Etags
class BasicController < ActionController::Base
View
2  actionpack/test/new_base/metal_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module MetalTest
class MetalMiddleware < ActionController::Middleware
View
2  actionpack/test/new_base/middleware_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module MiddlewareTest
class MyMiddleware
View
2  actionpack/test/new_base/render_action_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderAction
# This has no layout and it works
View
2  actionpack/test/new_base/render_file_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderFile
View
2  actionpack/test/new_base/render_implicit_action_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderImplicitAction
class SimpleController < ::ApplicationController
View
2  actionpack/test/new_base/render_layout_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ControllerLayouts
class ImplicitController < ::ApplicationController
View
2  actionpack/test/new_base/render_partial_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderPartial
View
13 actionpack/test/new_base/render_rjs_test.rb
@@ -1,9 +1,7 @@
-require 'abstract_unit2'
+require 'abstract_unit'
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'",
@@ -26,6 +24,14 @@ def index_locale
class TestBasic < SimpleRouteCase
testing BasicController
+ def setup
+ @old_locale = I18n.locale
+ end
+
+ def teardown
+ I18n.locale = @old_locale
+ end
+
test "rendering a partial in an RJS template should pick the JS template over the HTML one" do
get :index, "format" => "js"
assert_response("$(\"customer\").update(\"JS Partial\");")
@@ -40,6 +46,5 @@ class TestBasic < SimpleRouteCase
get :index_locale, "format" => "js"
assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
end
-
end
end
View
2  actionpack/test/new_base/render_template_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderTemplate
class WithoutLayoutController < ActionController::Base
View
2  actionpack/test/new_base/render_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module Render
class BlankRenderController < ActionController::Base
View
2  actionpack/test/new_base/render_text_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderText
class SimpleController < ActionController::Base
View
2  actionpack/test/new_base/render_xml_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderXml
View
14 actionpack/test/template/render_test.rb
@@ -33,18 +33,14 @@ def test_render_file_without_specific_extension
end
def test_render_file_with_localization
- begin
- old_locale = I18n.locale
- I18n.locale = :da
- assert_equal "Hey verden", @view.render(:file => "test/hello_world")
- ensure
- I18n.locale = old_locale
- end
+ old_locale, I18n.locale = I18n.locale, :da
+ assert_equal "Hey verden", @view.render(:file => "test/hello_world")
+ ensure
+ I18n.locale = old_locale
end
def test_render_file_with_dashed_locale
- old_locale = I18n.locale
- I18n.locale = :"pt-BR"
+ old_locale, I18n.locale = I18n.locale, :"pt-BR"
assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
ensure
I18n.locale = old_locale
View
2  activemodel/examples/validations.rb
@@ -1,4 +1,4 @@
-require 'activemodel'
+require 'active_model'
class Person
include ActiveModel::Conversion
View
2  activemodel/lib/active_model/errors.rb
@@ -114,7 +114,7 @@ def full_messages(options = {})
full_messages
end
- # Translates an error message in it's default scope (<tt>activemodel.errrors.messages</tt>).
+ # Translates an error message in its default scope (<tt>activemodel.errors.messages</tt>).
# Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
# it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
# default message (e.g. <tt>activemodel.errors.messages.MESSAGE</tt>). The translated model name,
View
7 activemodel/lib/active_model/lint.rb
@@ -2,7 +2,7 @@
require "test/unit/ui/console/testrunner"
# You can test whether an object is compliant with the ActiveModel API by
-# calling ActiveModel::Compliance.test(object). It will emit a Test::Unit
+# calling ActiveModel::Lint.test(object). It will emit a Test::Unit
# output that tells you whether your object is fully compliant, or if not,
# which aspects of the API are not implemented.
#
@@ -13,7 +13,6 @@
#
# Objects you pass in are expected to return a compliant object from a
# call to to_model. It is perfectly fine for to_model to return self.
-
module ActiveModel
module Lint
def self.test(object, verbosity = 2, output = STDOUT)
@@ -59,7 +58,7 @@ def test_new_record?
end
def test_destroyed?
- assert @object.respond_to?(:new_record?), "The model should respond to destroyed?"
+ assert @object.respond_to?(:destroyed?), "The model should respond to destroyed?"
assert_boolean "destroyed?", @object.destroyed?
end
@@ -93,4 +92,4 @@ def test_errors_full_messages
include Errors
end
end
-end
+end
View
48 activerecord/lib/active_record/base.rb
@@ -1660,36 +1660,10 @@ def find_some(ids, options)
# single-table inheritance model that makes it possible to create
# objects of different types from the same table.
def instantiate(record)
- object =
- if subclass_name = record[inheritance_column]
- # No type given.
- if subclass_name.empty?
- allocate
+ object = find_sti_class(record[inheritance_column]).allocate
- else
- # Ignore type if no column is present since it was probably
- # pulled in from a sloppy join.
- unless columns_hash.include?(inheritance_column)
- allocate
-
- else
- begin
- compute_type(subclass_name).allocate
- rescue NameError
- raise SubclassNotFound,
- "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " +
- "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
- "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
- "or overwrite #{self.to_s}.inheritance_column to use another column for that information."
- end
- end
- end
- else
- allocate
- end
-
- object.instance_variable_set("@attributes", record)
- object.instance_variable_set("@attributes_cache", Hash.new)
+ object.instance_variable_set(:'@attributes', record)
+ object.instance_variable_set(:'@attributes_cache', {})
object.send(:_run_find_callbacks)
object.send(:_run_initialize_callbacks)
@@ -1697,6 +1671,22 @@ def instantiate(record)
object
end
+ def find_sti_class(type_name)
+ if type_name.blank? || !columns_hash.include?(inheritance_column)
+ self
+ else
+ begin
+ compute_type(type_name)
+ rescue NameError
+ raise SubclassNotFound,
+ "The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " +
+ "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
+ "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
+ "or overwrite #{name}.inheritance_column to use another column for that information."
+ end
+ end
+ end
+
# Nest the type name in the same module as this class.
# Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo
def type_name_with_module(type_name)
View
5 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -65,12 +65,15 @@ def self.mysql_connection(config) # :nodoc:
raise
end
end
+
MysqlCompat.define_all_hashes_method!
mysql = Mysql.init
mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslca] || config[:sslkey]
- ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config)
+ default_flags = Mysql.const_defined?(:CLIENT_MULTI_RESULTS) ? Mysql::CLIENT_MULTI_RESULTS : 0
+ options = [host, username, password, database, port, socket, default_flags]
+ ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config)
end
end
View
8 activerecord/test/cases/connection_test_mysql.rb
@@ -41,6 +41,14 @@ def test_successful_reconnection_after_timeout_with_verify
sleep 2
@connection.verify!
assert @connection.active?
+ end
+
+ # Test that MySQL allows multiple results for stored procedures
+ if Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
+ def test_multi_results
+ rows = ActiveRecord::Base.connection.select_rows('CALL ten();')
+ assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
+ end
end
private
View
12 activerecord/test/schema/mysql_specific_schema.rb
@@ -9,4 +9,16 @@
t.text :medium_text, :limit => 16777215
t.text :long_text, :limit => 2147483647
end
+
+ ActiveRecord::Base.connection.execute <<-SQL
+DROP PROCEDURE IF EXISTS ten;
+SQL
+
+ ActiveRecord::Base.connection.execute <<-SQL
+CREATE PROCEDURE ten() SQL SECURITY INVOKER
+BEGIN
+ select 10;
+END
+SQL
+
end
View
4 activeresource/lib/active_resource/validations.rb
@@ -93,9 +93,9 @@ def save_with_validation(perform_validation = true)
# content-type of the error-block received
def load_remote_errors(remote_errors, save_cache = false ) #:nodoc:
case remote_errors.response['Content-Type']
- when 'application/xml'
+ when /xml/
errors.from_xml(remote_errors.response.body, save_cache)
- when 'application/json'
+ when /json/
errors.from_json(remote_errors.response.body, save_cache)
end
end
View
4 activeresource/test/cases/base_errors_test.rb
@@ -4,8 +4,8 @@
class BaseErrorsTest < Test::Unit::TestCase
def setup
ActiveResource::HttpMock.respond_to do |mock|
- mock.post "/people.xml", {}, %q(<?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error></errors>), 422, {'Content-Type' => 'application/xml'}
- mock.post "/people.json", {}, %q({"errors":["Age can't be blank","Name can't be blank","Name must start with a letter","Person quota full for today."]}), 422, {'Content-Type' => 'application/json'}
+ mock.post "/people.xml", {}, %q(<?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error></errors>), 422, {'Content-Type' => 'application/xml; charset=utf-8'}
+ mock.post "/people.json", {}, %q({"errors":["Age can't be blank","Name can't be blank","Name must start with a letter","Person quota full for today."]}), 422, {'Content-Type' => 'application/json; charset=utf-8'}
end
end
View
9 activesupport/lib/active_support/mini.rb
@@ -1,9 +0,0 @@
-$LOAD_PATH.unshift File.dirname(__FILE__)
-
-# whole object.rb pulls up rarely used introspection extensions
-require "core_ext/object/blank"
-require "core_ext/object/metaclass"
-require 'core_ext/array'
-require 'core_ext/hash'
-require 'core_ext/module/attribute_accessors'
-require 'core_ext/string/inflections'
View
34 activesupport/lib/active_support/xml_mini/nokogiri.rb
@@ -18,7 +18,7 @@ def parse(data)
{}
else
data.ungetc(char)
- doc = Nokogiri::XML(data)
+ doc = Nokogiri::XML(data) { |cfg| cfg.noblanks }
raise doc.errors.first if doc.errors.length > 0
doc.to_hash
end
@@ -39,33 +39,25 @@ module Node #:nodoc:
# hash::
# Hash to merge the converted element into.
def to_hash(hash = {})
- hash[name] ||= attributes_as_hash
+ attributes = attributes_as_hash
+ if hash[name]
+ hash[name] = [hash[name]].flatten
+ hash[name] << attributes
+ else
+ hash[name] ||= attributes
+ end
- walker = lambda { |memo, parent, child, callback|
- next if child.blank? && 'file' != parent['type']
+ children.each { |child|
+ next if child.blank? && 'file' != self['type']
- if child.text?
- (memo[CONTENT_ROOT] ||= '') << child.content
+ if child.text? || child.cdata?
+ (attributes[CONTENT_ROOT] ||= '') << child.content
next
end
- name = child.name
-
- child_hash = child.attributes_as_hash
- if memo[name]
- memo[name] = [memo[name]].flatten
- memo[name] << child_hash
- else
- memo[name] = child_hash
- end
-
- # Recursively walk children
- child.children.each { |c|
- callback.call(child_hash, child, c, callback)
- }
+ child.to_hash attributes
}
- children.each { |c| walker.call(hash[name], self, c, walker) }
hash
end
View
11 activesupport/test/xml_mini/nokogiri_engine_test.rb
@@ -159,6 +159,17 @@ def test_parse_from_io
XmlMini.parse(io)
end
+ def test_children_with_cdata
+ assert_equal_rexml(<<-eoxml)
+ <root>
+ <products>
+ hello <![CDATA[everyone]]>
+ morning
+ </products>
+ </root>
+ eoxml
+ end
+