aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/Rakefile19
-rw-r--r--actionpack/lib/abstract_controller/logger.rb14
-rw-r--r--actionpack/lib/action_controller/dispatch/middlewares.rb10
-rw-r--r--actionpack/lib/action_controller/metal.rb2
-rw-r--r--actionpack/lib/action_controller/metal/rescuable.rb45
-rw-r--r--actionpack/lib/action_dispatch.rb8
-rw-r--r--actionpack/lib/action_dispatch/middleware/rescue.rb20
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb4
-rw-r--r--actionpack/lib/action_view.rb13
-rw-r--r--actionpack/lib/action_view/template/inline.rb19
-rw-r--r--actionpack/lib/action_view/template/partial.rb18
-rw-r--r--actionpack/lib/action_view/template/renderable.rb93
-rw-r--r--actionpack/test/abstract/abstract_controller_test.rb (renamed from actionpack/test/abstract_controller/abstract_controller_test.rb)2
-rw-r--r--actionpack/test/abstract/callbacks_test.rb (renamed from actionpack/test/abstract_controller/callbacks_test.rb)2
-rw-r--r--actionpack/test/abstract/helper_test.rb (renamed from actionpack/test/abstract_controller/helper_test.rb)2
-rw-r--r--actionpack/test/abstract/layouts_test.rb (renamed from actionpack/test/abstract_controller/layouts_test.rb)2
-rw-r--r--actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb (renamed from actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb)0
-rw-r--r--actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb (renamed from actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb)0
-rw-r--r--actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb (renamed from actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb)0
-rw-r--r--actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb (renamed from actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb)0
-rw-r--r--actionpack/test/abstract/views/action_with_ivars.erb (renamed from actionpack/test/abstract_controller/views/action_with_ivars.erb)0
-rw-r--r--actionpack/test/abstract/views/helper_test.erb (renamed from actionpack/test/abstract_controller/views/helper_test.erb)0
-rw-r--r--actionpack/test/abstract/views/index.erb (renamed from actionpack/test/abstract_controller/views/index.erb)0
-rw-r--r--actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb (renamed from actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb)0
-rw-r--r--actionpack/test/abstract/views/layouts/application.erb (renamed from actionpack/test/abstract_controller/views/layouts/application.erb)0
-rw-r--r--actionpack/test/abstract/views/naked_render.erb (renamed from actionpack/test/abstract_controller/views/naked_render.erb)0
-rw-r--r--actionpack/test/abstract_unit.rb88
-rw-r--r--actionpack/test/abstract_unit2.rb119
-rw-r--r--actionpack/test/bundler_helper.rb10
-rw-r--r--actionpack/test/controller/caching_test.rb4
-rw-r--r--actionpack/test/controller/content_type_test.rb15
-rw-r--r--actionpack/test/controller/integration_test.rb2
-rw-r--r--actionpack/test/controller/render_js_test.rb38
-rw-r--r--actionpack/test/controller/render_json_test.rb58
-rw-r--r--actionpack/test/controller/render_other_test.rb251
-rw-r--r--actionpack/test/controller/render_xml_test.rb68
-rw-r--r--actionpack/test/controller/rescue_test.rb29
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb3
-rw-r--r--actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb (renamed from actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb)0
-rw-r--r--actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml (renamed from actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml)0
-rw-r--r--actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs (renamed from actionpack/test/fixtures/content_type/render_default_for_rjs.rjs)0
-rw-r--r--actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml (renamed from actionpack/test/fixtures/content_type/render_default_for_rxml.rxml)0
-rw-r--r--actionpack/test/new_base/base_test.rb2
-rw-r--r--actionpack/test/new_base/content_negotiation_test.rb2
-rw-r--r--actionpack/test/new_base/content_type_test.rb2
-rw-r--r--actionpack/test/new_base/etag_test.rb2
-rw-r--r--actionpack/test/new_base/metal_test.rb2
-rw-r--r--actionpack/test/new_base/middleware_test.rb2
-rw-r--r--actionpack/test/new_base/render_action_test.rb2
-rw-r--r--actionpack/test/new_base/render_file_test.rb2
-rw-r--r--actionpack/test/new_base/render_implicit_action_test.rb2
-rw-r--r--actionpack/test/new_base/render_layout_test.rb2
-rw-r--r--actionpack/test/new_base/render_partial_test.rb2
-rw-r--r--actionpack/test/new_base/render_rjs_test.rb13
-rw-r--r--actionpack/test/new_base/render_template_test.rb2
-rw-r--r--actionpack/test/new_base/render_test.rb2
-rw-r--r--actionpack/test/new_base/render_text_test.rb2
-rw-r--r--actionpack/test/new_base/render_xml_test.rb2
-rw-r--r--actionpack/test/template/render_test.rb14
59 files changed, 399 insertions, 616 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 0d8362ad0b..cc7b4b0043 100644
--- a/actionpack/Rakefile
+++ b/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|
diff --git a/actionpack/lib/abstract_controller/logger.rb b/actionpack/lib/abstract_controller/logger.rb
index 1b879b963b..06b64d5cb2 100644
--- a/actionpack/lib/abstract_controller/logger.rb
+++ b/actionpack/lib/abstract_controller/logger.rb
@@ -11,15 +11,17 @@ module AbstractController
# 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
diff --git a/actionpack/lib/action_controller/dispatch/middlewares.rb b/actionpack/lib/action_controller/dispatch/middlewares.rb
index b25ed3fd3f..5641b3cb8d 100644
--- a/actionpack/lib/action_controller/dispatch/middlewares.rb
+++ b/actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -4,15 +4,13 @@ use "Rack::Lock", :if => lambda {
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" \ No newline at end of file
+use "Rack::Head"
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 6aa4fe6019..e9007d3631 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/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.
#
diff --git a/actionpack/lib/action_controller/metal/rescuable.rb b/actionpack/lib/action_controller/metal/rescuable.rb
index 029e643d93..bbca1b2179 100644
--- a/actionpack/lib/action_controller/metal/rescuable.rb
+++ b/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
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 849f268a8c..5bcd2143a3 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/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 ActionDispatch
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'
diff --git a/actionpack/lib/action_dispatch/middleware/rescue.rb b/actionpack/lib/action_dispatch/middleware/rescue.rb
index 1456825526..aee672112c 100644
--- a/actionpack/lib/action_dispatch/middleware/rescue.rb
+++ b/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
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
index bb2d8375bd..f8f6b424ca 100644
--- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
+++ b/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>
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index d90afb1913..3df4f2d6a3 100644
--- a/actionpack/lib/action_view.rb
+++ b/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 @@ module ActionView
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'
diff --git a/actionpack/lib/action_view/template/inline.rb b/actionpack/lib/action_view/template/inline.rb
deleted file mode 100644
index 54efa543c8..0000000000
--- a/actionpack/lib/action_view/template/inline.rb
+++ /dev/null
@@ -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
diff --git a/actionpack/lib/action_view/template/partial.rb b/actionpack/lib/action_view/template/partial.rb
deleted file mode 100644
index 30dec1dc5b..0000000000
--- a/actionpack/lib/action_view/template/partial.rb
+++ /dev/null
@@ -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
diff --git a/actionpack/lib/action_view/template/renderable.rb b/actionpack/lib/action_view/template/renderable.rb
deleted file mode 100644
index 7687578165..0000000000
--- a/actionpack/lib/action_view/template/renderable.rb
+++ /dev/null
@@ -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
diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb
index 0e6cfba5b5..524381509d 100644
--- a/actionpack/test/abstract_controller/abstract_controller_test.rb
+++ b/actionpack/test/abstract/abstract_controller_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb
index 98656c0c70..0ce1dc506b 100644
--- a/actionpack/test/abstract_controller/callbacks_test.rb
+++ b/actionpack/test/abstract/callbacks_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract/helper_test.rb
index 4c013137f9..5a363c9aa5 100644
--- a/actionpack/test/abstract_controller/helper_test.rb
+++ b/actionpack/test/abstract/helper_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module AbstractController
module Testing
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb
index bee3b5c556..453d31826e 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/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
diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb
index 785bf69191..785bf69191 100644
--- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb
+++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb
diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb
index f079ad8204..f079ad8204 100644
--- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb
+++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb
diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb
index 89dce12bdc..89dce12bdc 100644
--- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb
+++ b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb
diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb
index 84d0b7417e..84d0b7417e 100644
--- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb
+++ b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb
diff --git a/actionpack/test/abstract_controller/views/action_with_ivars.erb b/actionpack/test/abstract/views/action_with_ivars.erb
index 8d8ae22fd7..8d8ae22fd7 100644
--- a/actionpack/test/abstract_controller/views/action_with_ivars.erb
+++ b/actionpack/test/abstract/views/action_with_ivars.erb
diff --git a/actionpack/test/abstract_controller/views/helper_test.erb b/actionpack/test/abstract/views/helper_test.erb
index 8ae45cc195..8ae45cc195 100644
--- a/actionpack/test/abstract_controller/views/helper_test.erb
+++ b/actionpack/test/abstract/views/helper_test.erb
diff --git a/actionpack/test/abstract_controller/views/index.erb b/actionpack/test/abstract/views/index.erb
index cc1a8b8c85..cc1a8b8c85 100644
--- a/actionpack/test/abstract_controller/views/index.erb
+++ b/actionpack/test/abstract/views/index.erb
diff --git a/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb
index 172dd56569..172dd56569 100644
--- a/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb
+++ b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb
diff --git a/actionpack/test/abstract_controller/views/layouts/application.erb b/actionpack/test/abstract/views/layouts/application.erb
index 27317140ad..27317140ad 100644
--- a/actionpack/test/abstract_controller/views/layouts/application.erb
+++ b/actionpack/test/abstract/views/layouts/application.erb
diff --git a/actionpack/test/abstract_controller/views/naked_render.erb b/actionpack/test/abstract/views/naked_render.erb
index 1b3d03878b..1b3d03878b 100644
--- a/actionpack/test/abstract_controller/views/naked_render.erb
+++ b/actionpack/test/abstract/views/naked_render.erb
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 7776bd0704..b9293ffb9f 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -6,26 +6,31 @@ $:.unshift(File.dirname(__FILE__) + '/lib')
$:.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 @@ rescue LoadError
# 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 @@ module ActionView
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 @@ module ActionController
end
end
end
+
+class SimpleRouteCase < Rack::TestCase
+ setup do
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
+ end
+end
diff --git a/actionpack/test/abstract_unit2.rb b/actionpack/test/abstract_unit2.rb
deleted file mode 100644
index 0a98d8edc2..0000000000
--- a/actionpack/test/abstract_unit2.rb
+++ /dev/null
@@ -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
diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb
deleted file mode 100644
index f7357bdb41..0000000000
--- a/actionpack/test/bundler_helper.rb
+++ /dev/null
@@ -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
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 82c790bc19..25e035cb49 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -441,8 +441,8 @@ class ActionCacheTest < ActionController::TestCase
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
diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb
index c249788c67..e5ffe20ecc 100644
--- a/actionpack/test/controller/content_type_test.rb
+++ b/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 @@ class ContentTypeController < ActionController::Base
end
class ContentTypeTest < ActionController::TestCase
- tests ContentTypeController
+ tests OldContentTypeController
def setup
super
@@ -73,11 +73,11 @@ class ContentTypeTest < ActionController::TestCase
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 @@ class ContentTypeTest < ActionController::TestCase
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 @@ class ContentTypeTest < ActionController::TestCase
end
class AcceptBasedContentTypeTest < ActionController::TestCase
-
- tests ContentTypeController
+ tests OldContentTypeController
def setup
super
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 93f5bfa272..9f56bbfd46 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -377,7 +377,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
end
end
-class MetalTest < ActionController::IntegrationTest
+class MetalIntegrationTest < ActionController::IntegrationTest
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/success/
diff --git a/actionpack/test/controller/render_js_test.rb b/actionpack/test/controller/render_js_test.rb
index bc850de733..491c98a0fd 100644
--- a/actionpack/test/controller/render_js_test.rb
+++ b/actionpack/test/controller/render_js_test.rb
@@ -2,23 +2,27 @@ require 'abstract_unit'
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 @@ class RenderTest < ActionController::TestCase
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 \ No newline at end of file
+end
diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb
index 233b2dfd89..3938fc7061 100644
--- a/actionpack/test/controller/render_json_test.rb
+++ b/actionpack/test/controller/render_json_test.rb
@@ -2,35 +2,39 @@ require 'abstract_unit'
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 @@ class RenderTest < ActionController::TestCase
@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 @@ class RenderTest < ActionController::TestCase
get :render_json_with_render_to_string
assert_equal '{"hello":"partial html"}', @response.body
assert_equal 'application/json', @response.content_type
- end
-end \ No newline at end of file
+ end
+end
diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb
index 05645e47fa..51c3c55545 100644
--- a/actionpack/test/controller/render_other_test.rb
+++ b/actionpack/test/controller/render_other_test.rb
@@ -2,139 +2,144 @@ require 'abstract_unit'
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 @@ class RenderTest < ActionController::TestCase
@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 @@ class RenderTest < ActionController::TestCase
$$(".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 @@ class RenderTest < ActionController::TestCase
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 @@ class RenderTest < ActionController::TestCase
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 @@ class RenderTest < ActionController::TestCase
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 @@ class RenderTest < ActionController::TestCase
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 @@ class RenderTest < ActionController::TestCase
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 \ No newline at end of file
+ end
+end
diff --git a/actionpack/test/controller/render_xml_test.rb b/actionpack/test/controller/render_xml_test.rb
index e96e8a4d57..68a52c3e8c 100644
--- a/actionpack/test/controller/render_xml_test.rb
+++ b/actionpack/test/controller/render_xml_test.rb
@@ -2,37 +2,41 @@ require 'abstract_unit'
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 @@ class RenderTest < ActionController::TestCase
@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 @@ class RenderTest < ActionController::TestCase
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 @@ class RenderTest < ActionController::TestCase
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
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 23408712e9..09eddfe4a7 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -227,12 +227,6 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase
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 @@ class RescueTest < ActionController::IntegrationTest
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
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index ce1973853e..d4800e4edb 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/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)
diff --git a/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb b/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb
index 25dc746886..25dc746886 100644
--- a/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb
+++ b/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb
diff --git a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml
index c7926d48bb..c7926d48bb 100644
--- a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml
+++ b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml
diff --git a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs
index 8d614d04ad..8d614d04ad 100644
--- a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs
+++ b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs
diff --git a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml
index 598d62e2fc..598d62e2fc 100644
--- a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml
+++ b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml
diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb
index 3a559c9cb6..effde324bc 100644
--- a/actionpack/test/new_base/base_test.rb
+++ b/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
diff --git a/actionpack/test/new_base/content_negotiation_test.rb b/actionpack/test/new_base/content_negotiation_test.rb
index a2f9df597f..c43cb677f8 100644
--- a/actionpack/test/new_base/content_negotiation_test.rb
+++ b/actionpack/test/new_base/content_negotiation_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ContentNegotiation
diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb
index 7e95c715a0..898d0bb9f3 100644
--- a/actionpack/test/new_base/content_type_test.rb
+++ b/actionpack/test/new_base/content_type_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ContentType
class BaseController < ActionController::Base
diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb
index 64ae10b7a7..d5b7942ab6 100644
--- a/actionpack/test/new_base/etag_test.rb
+++ b/actionpack/test/new_base/etag_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module Etags
class BasicController < ActionController::Base
diff --git a/actionpack/test/new_base/metal_test.rb b/actionpack/test/new_base/metal_test.rb
index 613d03446c..e1d46b906e 100644
--- a/actionpack/test/new_base/metal_test.rb
+++ b/actionpack/test/new_base/metal_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module MetalTest
class MetalMiddleware < ActionController::Middleware
diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb
index ecca7e51eb..ada0215b1a 100644
--- a/actionpack/test/new_base/middleware_test.rb
+++ b/actionpack/test/new_base/middleware_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module MiddlewareTest
class MyMiddleware
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index 72a16e3b67..d5896c1ebd 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/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
diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb
index 7067baca18..c4098855e6 100644
--- a/actionpack/test/new_base/render_file_test.rb
+++ b/actionpack/test/new_base/render_file_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderFile
diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb
index 03b9ff6eeb..2b78fa7d4f 100644
--- a/actionpack/test/new_base/render_implicit_action_test.rb
+++ b/actionpack/test/new_base/render_implicit_action_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderImplicitAction
class SimpleController < ::ApplicationController
diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb
index 0dfbae4e9d..f840a47ecf 100644
--- a/actionpack/test/new_base/render_layout_test.rb
+++ b/actionpack/test/new_base/render_layout_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module ControllerLayouts
class ImplicitController < ::ApplicationController
diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb
index ff775dbfd7..7c2c20e1c7 100644
--- a/actionpack/test/new_base/render_partial_test.rb
+++ b/actionpack/test/new_base/render_partial_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderPartial
diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb
index eecc275b1e..7b76c54ab9 100644
--- a/actionpack/test/new_base/render_rjs_test.rb
+++ b/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 @@ module RenderRjs
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 @@ module RenderRjs
get :index_locale, "format" => "js"
assert_response("$(\"customer\").update(\"Danish HTML Partial\");")
end
-
end
end
diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb
index 5637565dac..3b24c2d75a 100644
--- a/actionpack/test/new_base/render_template_test.rb
+++ b/actionpack/test/new_base/render_template_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderTemplate
class WithoutLayoutController < ActionController::Base
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
index 94820f1c9c..804be79d17 100644
--- a/actionpack/test/new_base/render_test.rb
+++ b/actionpack/test/new_base/render_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module Render
class BlankRenderController < ActionController::Base
diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb
index 23660ed101..f5839ee16f 100644
--- a/actionpack/test/new_base/render_text_test.rb
+++ b/actionpack/test/new_base/render_text_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderText
class SimpleController < ActionController::Base
diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb
index 86a7d9c8a5..d044738a78 100644
--- a/actionpack/test/new_base/render_xml_test.rb
+++ b/actionpack/test/new_base/render_xml_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit2'
+require 'abstract_unit'
module RenderXml
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index c86d5215cd..3c192906ae 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -33,18 +33,14 @@ module RenderTestCases
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