From af68eb99c144e723d4c9d418e09dad516ba61973 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 12:47:31 -0700 Subject: Uses extlib_inheritable_accessor --- actionpack/lib/action_controller/metal.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack') 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. # -- cgit v1.2.3 From b8e914709c06fceac51384f7484c002fcb715196 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 13:01:44 -0700 Subject: Require active_support after autoload setup --- actionpack/lib/action_dispatch.rb | 8 ++++---- actionpack/lib/action_view.rb | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack') 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_view.rb b/actionpack/lib/action_view.rb index d90afb1913..e888c6808e 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 @@ -59,3 +54,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' -- cgit v1.2.3 From 90d7ae23c6f5a7e914d8b9fd74481ac61b6c4fb9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Sep 2009 10:05:46 -0500 Subject: Remove global exception catching from ApplicationController. It was severely broken since it was ported to NewBase and is causing problems with normal exception catching. A replacement is coming soon. --- .../lib/action_controller/dispatch/middlewares.rb | 10 ++--- .../lib/action_controller/metal/rescuable.rb | 45 ++-------------------- actionpack/test/controller/rescue_test.rb | 24 ++++++------ 3 files changed, 19 insertions(+), 60 deletions(-) (limited to 'actionpack') 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/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 - # local_request? method in your own controller. Custom rescue - # behavior is achieved by overriding the rescue_action_in_public - # and rescue_action_locally 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/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 23408712e9..e8ca1ad0ee 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -331,18 +331,18 @@ class RescueTest < ActionController::IntegrationTest end 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 - end - 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 + # end + # end test 'unrescued exception' do with_test_routing do -- cgit v1.2.3 From 52aeb8d2e72223f9b40b0193c151c252a3f4fb09 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Sep 2009 16:33:15 -0500 Subject: Beef up AD::Rescue to replace global exception handling lost in ApplicationController --- .../lib/action_dispatch/middleware/rescue.rb | 20 ++++++++++--- actionpack/test/controller/rescue_test.rb | 35 ++++++++-------------- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'actionpack') 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/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index e8ca1ad0ee..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 @@ -331,24 +325,21 @@ class RescueTest < ActionController::IntegrationTest end 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 - # end - # end + test 'rescue routing exceptions' do + 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 -- cgit v1.2.3 From befec8a0d83bc61238680b584688470069efb23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 15 Sep 2009 20:13:47 -0300 Subject: Remove unused code in ActionView. Signed-off-by: Yehuda Katz --- actionpack/lib/action_view.rb | 3 - actionpack/lib/action_view/template/inline.rb | 19 ----- actionpack/lib/action_view/template/partial.rb | 18 ----- actionpack/lib/action_view/template/renderable.rb | 93 ----------------------- 4 files changed, 133 deletions(-) delete mode 100644 actionpack/lib/action_view/template/inline.rb delete mode 100644 actionpack/lib/action_view/template/partial.rb delete mode 100644 actionpack/lib/action_view/template/renderable.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index e888c6808e..3df4f2d6a3 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -31,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' 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 -- cgit v1.2.3 From 23e72d4cc8d879e4d3facac31f96643da48a8a27 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 16 Sep 2009 22:34:44 -0500 Subject: Forward all methods to delayed log --- actionpack/lib/abstract_controller/logger.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'actionpack') 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 -- cgit v1.2.3 From 81c421386c3989e96f1fd3b0370b75155eeda2e1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 18 Sep 2009 10:35:42 -0700 Subject: 1.9 fix for changes to #to_s. By Sam Ruby. [#3228 state:resolved] --- .../lib/action_dispatch/middleware/templates/rescues/_trace.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') 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';"} %> - <%= name %> <%= '|' unless names.last == name %> + <%= name %> <%= '|' unless names.last == name %> <% end %> <% traces.each do |name, trace| %>
;"> -
<%= trace.join "\n" %>
+
<%=h trace.join "\n" %>
<% end %> -- cgit v1.2.3 From 5bc47a93b7c700f246e9469880af82ad4844717b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 11:56:11 -0500 Subject: Make sure caching test is using a generatable url --- actionpack/test/controller/caching_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') 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 -- cgit v1.2.3 From a6f19a155a0c9accb31ae12a24ff9145cce271b0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 11:57:56 -0500 Subject: There is only one base now --- actionpack/test/abstract_unit.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 7776bd0704..78f326e341 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -12,7 +12,6 @@ ensure_requirable %w( rack rack/test sqlite3 ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') ENV['new_base'] = "true" -$stderr.puts "Running old tests on new_base" require 'test/unit' require 'active_support' -- cgit v1.2.3 From f05b1e5eb1829be47bf9581ca6666229e01d597c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:10:41 -0500 Subject: All on one abstract_unit --- .../abstract_controller_test.rb | 2 +- .../test/abstract_controller/callbacks_test.rb | 2 +- actionpack/test/abstract_controller/helper_test.rb | 2 +- .../test/abstract_controller/layouts_test.rb | 2 +- actionpack/test/abstract_unit.rb | 76 ++++++++++++- actionpack/test/abstract_unit2.rb | 119 --------------------- actionpack/test/new_base/base_test.rb | 2 +- .../test/new_base/content_negotiation_test.rb | 2 +- actionpack/test/new_base/content_type_test.rb | 2 +- actionpack/test/new_base/etag_test.rb | 2 +- actionpack/test/new_base/metal_test.rb | 2 +- actionpack/test/new_base/middleware_test.rb | 2 +- actionpack/test/new_base/render_action_test.rb | 2 +- actionpack/test/new_base/render_file_test.rb | 2 +- .../test/new_base/render_implicit_action_test.rb | 2 +- actionpack/test/new_base/render_layout_test.rb | 2 +- actionpack/test/new_base/render_partial_test.rb | 2 +- actionpack/test/new_base/render_rjs_test.rb | 2 +- actionpack/test/new_base/render_template_test.rb | 2 +- actionpack/test/new_base/render_test.rb | 2 +- actionpack/test/new_base/render_text_test.rb | 2 +- actionpack/test/new_base/render_xml_test.rb | 2 +- 22 files changed, 92 insertions(+), 143 deletions(-) delete mode 100644 actionpack/test/abstract_unit2.rb (limited to 'actionpack') diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 0e6cfba5b5..524381509d 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/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_controller/callbacks_test.rb index 98656c0c70..0ce1dc506b 100644 --- a/actionpack/test/abstract_controller/callbacks_test.rb +++ b/actionpack/test/abstract_controller/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_controller/helper_test.rb index 4c013137f9..5a363c9aa5 100644 --- a/actionpack/test/abstract_controller/helper_test.rb +++ b/actionpack/test/abstract_controller/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_controller/layouts_test.rb index bee3b5c556..453d31826e 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/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_unit.rb b/actionpack/test/abstract_unit.rb index 78f326e341..1aa4dcb741 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -16,15 +16,17 @@ ENV['new_base'] = "true" 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' @@ -34,6 +36,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. @@ -56,6 +60,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', @@ -132,3 +191,12 @@ 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/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..9c6416bbe0 100644 --- a/actionpack/test/new_base/render_rjs_test.rb +++ b/actionpack/test/new_base/render_rjs_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit2' +require 'abstract_unit' module RenderRjs 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 -- cgit v1.2.3 From 12b3799448119a2cd5732670ad7e3cc9ce5707d0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:50:14 -0500 Subject: Avoid conflicts with another ContentTypeController used in testing --- actionpack/test/controller/content_type_test.rb | 15 +++++++-------- .../render_default_content_types_for_respond_to.xml.erb | 1 - .../fixtures/content_type/render_default_for_rhtml.rhtml | 1 - .../test/fixtures/content_type/render_default_for_rjs.rjs | 1 - .../fixtures/content_type/render_default_for_rxml.rxml | 1 - .../render_default_content_types_for_respond_to.xml.erb | 1 + .../old_content_type/render_default_for_rhtml.rhtml | 1 + .../fixtures/old_content_type/render_default_for_rjs.rjs | 1 + .../old_content_type/render_default_for_rxml.rxml | 1 + 9 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rjs.rjs delete mode 100644 actionpack/test/fixtures/content_type/render_default_for_rxml.rxml create mode 100644 actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs create mode 100644 actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml (limited to 'actionpack') 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/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb b/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb deleted file mode 100644 index 25dc746886..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_content_types_for_respond_to.xml.erb +++ /dev/null @@ -1 +0,0 @@ -world \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml b/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml deleted file mode 100644 index c7926d48bb..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rhtml.rhtml +++ /dev/null @@ -1 +0,0 @@ -<%= 'hello world!' %> \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs deleted file mode 100644 index 8d614d04ad..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rjs.rjs +++ /dev/null @@ -1 +0,0 @@ -page.alert 'hello world!' \ No newline at end of file diff --git a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml b/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml deleted file mode 100644 index 598d62e2fc..0000000000 --- a/actionpack/test/fixtures/content_type/render_default_for_rxml.rxml +++ /dev/null @@ -1 +0,0 @@ -xml.p "Hello world!" \ No newline at end of file diff --git a/actionpack/test/fixtures/old_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 new file mode 100644 index 0000000000..25dc746886 --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb @@ -0,0 +1 @@ +world \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml new file mode 100644 index 0000000000..c7926d48bb --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rhtml.rhtml @@ -0,0 +1 @@ +<%= 'hello world!' %> \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs new file mode 100644 index 0000000000..8d614d04ad --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rjs.rjs @@ -0,0 +1 @@ +page.alert 'hello world!' \ No newline at end of file diff --git a/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml new file mode 100644 index 0000000000..598d62e2fc --- /dev/null +++ b/actionpack/test/fixtures/old_content_type/render_default_for_rxml.rxml @@ -0,0 +1 @@ +xml.p "Hello world!" \ No newline at end of file -- cgit v1.2.3 From 355e2350ca5ce203acfb7f71914339e289b37570 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:51:28 -0500 Subject: All on one base, don't need this --- actionpack/test/abstract_unit.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 1aa4dcb741..3bd08e04f7 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -11,8 +11,6 @@ ensure_requirable %w( rack rack/test sqlite3 ) ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') -ENV['new_base'] = "true" - require 'test/unit' require 'active_support' require 'active_support/test_case' @@ -192,7 +190,6 @@ module ActionController end end - class SimpleRouteCase < Rack::TestCase setup do ActionController::Routing::Routes.draw do |map| -- cgit v1.2.3 From db0af8075d84ceb086ebad2e0b6f839fe588ddc2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 12:52:52 -0500 Subject: Avoid conflict with a "MetalTest" module used in tests --- actionpack/test/controller/integration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') 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/ -- cgit v1.2.3 From 0540781539508e09e5db176edfc72031773b0dc7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:04:12 -0500 Subject: Namespace TestControllers inside their test case class --- actionpack/test/controller/render_js_test.rb | 38 ++-- actionpack/test/controller/render_json_test.rb | 58 +++--- actionpack/test/controller/render_other_test.rb | 251 ++++++++++++------------ actionpack/test/controller/render_xml_test.rb | 68 ++++--- 4 files changed, 216 insertions(+), 199 deletions(-) (limited to 'actionpack') 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 => "", :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 => "", :location => customer, :status => :created - end + def render_with_location + render :xml => "", :location => "http://example.com", :status => 201 + end - def render_with_to_xml - to_xmlable = Class.new do - def to_xml - "" - end - end.new + def render_with_object_location + customer = Customer.new("Some guy", 1) + render :xml => "", :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 + "" + end + end.new + + render :xml => to_xmlable + end + + def formatted_xml_erb + end + + def render_xml_with_custom_content_type + render :xml => "", :content_type => "application/atomsvc+xml" + end end - - def render_xml_with_custom_content_type - render :xml => "", :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 "", @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 'passed formatted xml erb', @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 -- cgit v1.2.3 From 69192bee2da198de1bf59fbc0646e59f68e10751 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:12:54 -0500 Subject: Merge bundler helper into abstract_unit --- actionpack/test/abstract_unit.rb | 10 ++++++++-- actionpack/test/bundler_helper.rb | 10 ---------- 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 actionpack/test/bundler_helper.rb (limited to 'actionpack') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 3bd08e04f7..b9293ffb9f 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -6,8 +6,14 @@ $:.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") + +begin + %w( rack rack/test sqlite3 ).each { |lib| require lib } +rescue LoadError => e + abort e.message +end ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') 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 -- cgit v1.2.3 From f1c8f07be8c055fdcfd5b5a08b5781e21f24e428 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:14:22 -0500 Subject: Follow short name convention for test folder and just call it "abstract" --- actionpack/Rakefile | 2 +- .../test/abstract/abstract_controller_test.rb | 245 +++++++++++++++++++++ actionpack/test/abstract/callbacks_test.rb | 238 ++++++++++++++++++++ actionpack/test/abstract/helper_test.rb | 44 ++++ actionpack/test/abstract/layouts_test.rb | 235 ++++++++++++++++++++ .../testing/me3/formatted.html.erb | 1 + .../abstract_controller/testing/me3/index.erb | 1 + .../abstract_controller/testing/me4/index.erb | 1 + .../abstract_controller/testing/me5/index.erb | 1 + .../test/abstract/views/action_with_ivars.erb | 1 + actionpack/test/abstract/views/helper_test.erb | 1 + actionpack/test/abstract/views/index.erb | 1 + .../layouts/abstract_controller/testing/me4.erb | 1 + .../test/abstract/views/layouts/application.erb | 1 + actionpack/test/abstract/views/naked_render.erb | 1 + .../abstract_controller_test.rb | 245 --------------------- .../test/abstract_controller/callbacks_test.rb | 238 -------------------- actionpack/test/abstract_controller/helper_test.rb | 44 ---- .../test/abstract_controller/layouts_test.rb | 235 -------------------- .../testing/me3/formatted.html.erb | 1 - .../abstract_controller/testing/me3/index.erb | 1 - .../abstract_controller/testing/me4/index.erb | 1 - .../abstract_controller/testing/me5/index.erb | 1 - .../views/action_with_ivars.erb | 1 - .../test/abstract_controller/views/helper_test.erb | 1 - .../test/abstract_controller/views/index.erb | 1 - .../layouts/abstract_controller/testing/me4.erb | 1 - .../views/layouts/application.erb | 1 - .../abstract_controller/views/naked_render.erb | 1 - 29 files changed, 773 insertions(+), 773 deletions(-) create mode 100644 actionpack/test/abstract/abstract_controller_test.rb create mode 100644 actionpack/test/abstract/callbacks_test.rb create mode 100644 actionpack/test/abstract/helper_test.rb create mode 100644 actionpack/test/abstract/layouts_test.rb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb create mode 100644 actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb create mode 100644 actionpack/test/abstract/views/action_with_ivars.erb create mode 100644 actionpack/test/abstract/views/helper_test.erb create mode 100644 actionpack/test/abstract/views/index.erb create mode 100644 actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb create mode 100644 actionpack/test/abstract/views/layouts/application.erb create mode 100644 actionpack/test/abstract/views/naked_render.erb delete mode 100644 actionpack/test/abstract_controller/abstract_controller_test.rb delete mode 100644 actionpack/test/abstract_controller/callbacks_test.rb delete mode 100644 actionpack/test/abstract_controller/helper_test.rb delete mode 100644 actionpack/test/abstract_controller/layouts_test.rb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb delete mode 100644 actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb delete mode 100644 actionpack/test/abstract_controller/views/action_with_ivars.erb delete mode 100644 actionpack/test/abstract_controller/views/helper_test.erb delete mode 100644 actionpack/test/abstract_controller/views/index.erb delete mode 100644 actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb delete mode 100644 actionpack/test/abstract_controller/views/layouts/application.erb delete mode 100644 actionpack/test/abstract_controller/views/naked_render.erb (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 0d8362ad0b..aaf1c7f926 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -62,7 +62,7 @@ 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.test_files = Dir.glob("test/{abstract,new_base}/*_test.rb") t.verbose = true end diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb new file mode 100644 index 0000000000..524381509d --- /dev/null +++ b/actionpack/test/abstract/abstract_controller_test.rb @@ -0,0 +1,245 @@ +require 'abstract_unit' + +module AbstractController + module Testing + + # Test basic dispatching. + # ==== + # * Call process + # * Test that the response_body is set correctly + class SimpleController < AbstractController::Base + end + + class Me < SimpleController + def index + self.response_body = "Hello world" + "Something else" + end + end + + class TestBasic < ActiveSupport::TestCase + test "dispatching works" do + controller = Me.new + controller.process(:index) + assert_equal "Hello world", controller.response_body + end + end + + # Test Render mixin + # ==== + class RenderingController < AbstractController::Base + include ::AbstractController::RenderingController + + def _prefix() end + + def render(options = {}) + if options.is_a?(String) + options = {:_template_name => options} + end + + options[:_prefix] = _prefix + super + end + + append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) + end + + class Me2 < RenderingController + def index + render "index.erb" + end + + def action_with_ivars + @my_ivar = "Hello" + render "action_with_ivars.erb" + end + + def naked_render + render + end + + def rendering_to_body + self.response_body = render_to_body :_template_name => "naked_render.erb" + end + + def rendering_to_string + self.response_body = render_to_string :_template_name => "naked_render.erb" + end + end + + class TestRenderingController < ActiveSupport::TestCase + def setup + @controller = Me2.new + end + + test "rendering templates works" do + @controller.process(:index) + assert_equal "Hello from index.erb", @controller.response_body + end + + test "rendering passes ivars to the view" do + @controller.process(:action_with_ivars) + assert_equal "Hello from index_with_ivars.erb", @controller.response_body + end + + test "rendering with no template name" do + @controller.process(:naked_render) + assert_equal "Hello from naked_render.erb", @controller.response_body + end + + test "rendering to a rack body" do + @controller.process(:rendering_to_body) + assert_equal "Hello from naked_render.erb", @controller.response_body + end + + test "rendering to a string" do + @controller.process(:rendering_to_string) + assert_equal "Hello from naked_render.erb", @controller.response_body + end + end + + # Test rendering with prefixes + # ==== + # * self._prefix is used when defined + class PrefixedViews < RenderingController + private + def self.prefix + name.underscore + end + + def _prefix + self.class.prefix + end + end + + class Me3 < PrefixedViews + def index + render + end + + def formatted + self.formats = [:html] + render + end + end + + class TestPrefixedViews < ActiveSupport::TestCase + def setup + @controller = Me3.new + end + + test "templates are located inside their 'prefix' folder" do + @controller.process(:index) + assert_equal "Hello from me3/index.erb", @controller.response_body + end + + test "templates included their format" do + @controller.process(:formatted) + assert_equal "Hello from me3/formatted.html.erb", @controller.response_body + end + end + + # Test rendering with layouts + # ==== + # self._layout is used when defined + class WithLayouts < PrefixedViews + include Layouts + + private + def self.layout(formats) + begin + find_template(name.underscore, {:formats => formats}, :_prefix => "layouts") + rescue ActionView::MissingTemplate + begin + find_template("application", {:formats => formats}, :_prefix => "layouts") + rescue ActionView::MissingTemplate + end + end + end + + def render_to_body(options = {}) + options[:_layout] = options[:layout] || _default_layout({}) + super + end + end + + class Me4 < WithLayouts + def index + render + end + end + + class Me5 < WithLayouts + def index + render + end + end + + class TestLayouts < ActiveSupport::TestCase + test "layouts are included" do + controller = Me4.new + result = controller.process(:index) + assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", controller.response_body + end + end + + # respond_to_action?(action_name) + # ==== + # * A method can be used as an action only if this method + # returns true when passed the method name as an argument + # * Defaults to true in AbstractController + class DefaultRespondToActionController < AbstractController::Base + def index() self.response_body = "success" end + end + + class ActionMissingRespondToActionController < AbstractController::Base + # No actions + private + def action_missing(action_name) + self.response_body = "success" + end + end + + class RespondToActionController < AbstractController::Base; + def index() self.response_body = "success" end + + def fail() self.response_body = "fail" end + + private + + def method_for_action(action_name) + action_name.to_s != "fail" && action_name + end + end + + class TestRespondToAction < ActiveSupport::TestCase + + def assert_dispatch(klass, body = "success", action = :index) + controller = klass.new + controller.process(action) + assert_equal body, controller.response_body + end + + test "an arbitrary method is available as an action by default" do + assert_dispatch DefaultRespondToActionController, "success", :index + end + + test "raises ActionNotFound when method does not exist and action_missing is not defined" do + assert_raise(ActionNotFound) { DefaultRespondToActionController.new.process(:fail) } + end + + test "dispatches to action_missing when method does not exist and action_missing is defined" do + assert_dispatch ActionMissingRespondToActionController, "success", :ohai + end + + test "a method is available as an action if respond_to_action? returns true" do + assert_dispatch RespondToActionController, "success", :index + end + + test "raises ActionNotFound if method is defined but respond_to_action? returns false" do + assert_raise(ActionNotFound) { RespondToActionController.new.process(:fail) } + end + end + + end +end diff --git a/actionpack/test/abstract/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb new file mode 100644 index 0000000000..0ce1dc506b --- /dev/null +++ b/actionpack/test/abstract/callbacks_test.rb @@ -0,0 +1,238 @@ +require 'abstract_unit' + +module AbstractController + module Testing + + class ControllerWithCallbacks < AbstractController::Base + include AbstractController::Callbacks + end + + class Callback1 < ControllerWithCallbacks + set_callback :process_action, :before, :first + + def first + @text = "Hello world" + end + + def index + self.response_body = @text + end + end + + class TestCallbacks1 < ActiveSupport::TestCase + test "basic callbacks work" do + controller = Callback1.new + result = controller.process(:index) + assert_equal "Hello world", controller.response_body + end + end + + class Callback2 < ControllerWithCallbacks + before_filter :first + after_filter :second + around_filter :aroundz + + def first + @text = "Hello world" + end + + def second + @second = "Goodbye" + end + + def aroundz + @aroundz = "FIRST" + yield + @aroundz << "SECOND" + end + + def index + self.response_body = @text + end + end + + class TestCallbacks2 < ActiveSupport::TestCase + def setup + @controller = Callback2.new + end + + test "before_filter works" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "after_filter works" do + @controller.process(:index) + assert_equal "Goodbye", @controller.instance_variable_get("@second") + end + + test "around_filter works" do + @controller.process(:index) + assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz") + end + end + + class Callback3 < ControllerWithCallbacks + before_filter do |c| + c.instance_variable_set("@text", "Hello world") + end + + after_filter do |c| + c.instance_variable_set("@second", "Goodbye") + end + + def index + self.response_body = @text + end + end + + class TestCallbacks3 < ActiveSupport::TestCase + def setup + @controller = Callback3.new + end + + test "before_filter works with procs" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "after_filter works with procs" do + result = @controller.process(:index) + assert_equal "Goodbye", @controller.instance_variable_get("@second") + end + end + + class CallbacksWithConditions < ControllerWithCallbacks + before_filter :list, :only => :index + before_filter :authenticate, :except => :index + + def index + self.response_body = @list.join(", ") + end + + def sekrit_data + self.response_body = (@list + [@authenticated]).join(", ") + end + + private + def list + @list = ["Hello", "World"] + end + + def authenticate + @list = [] + @authenticated = "true" + end + end + + class TestCallbacksWithConditions < ActiveSupport::TestCase + def setup + @controller = CallbacksWithConditions.new + end + + test "when :only is specified, a before filter is triggered on that action" do + @controller.process(:index) + assert_equal "Hello, World", @controller.response_body + end + + test "when :only is specified, a before filter is not triggered on other actions" do + @controller.process(:sekrit_data) + assert_equal "true", @controller.response_body + end + + test "when :except is specified, an after filter is not triggered on that action" do + result = @controller.process(:index) + assert_nil @controller.instance_variable_get("@authenticated") + end + end + + class CallbacksWithArrayConditions < ControllerWithCallbacks + before_filter :list, :only => [:index, :listy] + before_filter :authenticate, :except => [:index, :listy] + + def index + self.response_body = @list.join(", ") + end + + def sekrit_data + self.response_body = (@list + [@authenticated]).join(", ") + end + + private + def list + @list = ["Hello", "World"] + end + + def authenticate + @list = [] + @authenticated = "true" + end + end + + class TestCallbacksWithArrayConditions < ActiveSupport::TestCase + def setup + @controller = CallbacksWithArrayConditions.new + end + + test "when :only is specified with an array, a before filter is triggered on that action" do + result = @controller.process(:index) + assert_equal "Hello, World", @controller.response_body + end + + test "when :only is specified with an array, a before filter is not triggered on other actions" do + result = @controller.process(:sekrit_data) + assert_equal "true", @controller.response_body + end + + test "when :except is specified with an array, an after filter is not triggered on that action" do + result = @controller.process(:index) + assert_nil @controller.instance_variable_get("@authenticated") + end + end + + class ChangedConditions < Callback2 + before_filter :first, :only => :index + + def not_index + self.response_body = @text.to_s + end + end + + class TestCallbacksWithChangedConditions < ActiveSupport::TestCase + def setup + @controller = ChangedConditions.new + end + + test "when a callback is modified in a child with :only, it works for the :only action" do + result = @controller.process(:index) + assert_equal "Hello world", @controller.response_body + end + + test "when a callback is modified in a child with :only, it does not work for other actions" do + result = @controller.process(:not_index) + assert_equal "", @controller.response_body + end + end + + class SetsResponseBody < ControllerWithCallbacks + before_filter :set_body + + def index + self.response_body = "Fail" + end + + def set_body + self.response_body = "Success" + end + end + + class TestHalting < ActiveSupport::TestCase + test "when a callback sets the response body, the action should not be invoked" do + controller = SetsResponseBody.new + controller.process(:index) + assert_equal "Success", controller.response_body + end + end + + end +end diff --git a/actionpack/test/abstract/helper_test.rb b/actionpack/test/abstract/helper_test.rb new file mode 100644 index 0000000000..5a363c9aa5 --- /dev/null +++ b/actionpack/test/abstract/helper_test.rb @@ -0,0 +1,44 @@ +require 'abstract_unit' + +module AbstractController + module Testing + + class ControllerWithHelpers < AbstractController::Base + include AbstractController::RenderingController + include Helpers + + def render(string) + super(:_template_name => string) + end + + append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) + end + + module HelperyTest + def included_method + "Included" + end + end + + class MyHelpers1 < ControllerWithHelpers + helper(HelperyTest) do + def helpery_test + "World" + end + end + + def index + render "helper_test.erb" + end + end + + class TestHelpers < ActiveSupport::TestCase + def test_helpers + controller = MyHelpers1.new + controller.process(:index) + assert_equal "Hello World : Included", controller.response_body + end + end + + end +end diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb new file mode 100644 index 0000000000..453d31826e --- /dev/null +++ b/actionpack/test/abstract/layouts_test.rb @@ -0,0 +1,235 @@ +require 'abstract_unit' +require 'active_support/core_ext/class/removal' + +module AbstractControllerTests + module Layouts + + # Base controller for these tests + class Base < AbstractController::Base + include AbstractController::RenderingController + include AbstractController::Layouts + + self.view_paths = [ActionView::FixtureResolver.new( + "layouts/hello.erb" => "With String <%= yield %>", + "layouts/hello_override.erb" => "With Override <%= yield %>", + "layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" => + "With Implied <%= yield %>", + "layouts/omg.erb" => "OMGHI2U <%= yield %>", + "layouts/with_false_layout.erb" => "False Layout <%= yield %>" + )] + + def self.controller_path + @controller_path ||= self.name.sub(/Controller$/, '').underscore + end + + def controller_path() self.class.controller_path end + + def render_to_body(options) + options[:_layout] = _default_layout({}) + super + end + end + + class Blank < Base + self.view_paths = [] + + def index + render :_template => ActionView::TextTemplate.new("Hello blank!") + end + end + + class WithString < Base + layout "hello" + + def index + render :_template => ActionView::TextTemplate.new("Hello string!") + end + end + + class WithStringChild < WithString + end + + class WithStringOverriddenChild < WithString + layout "hello_override" + end + + class WithNilChild < WithString + layout nil + end + + class WithStringImpliedChild < WithString + end + + class WithChildOfImplied < WithStringImpliedChild + end + + class WithSymbol < Base + layout :hello + + def index + render :_template => ActionView::TextTemplate.new("Hello symbol!") + end + private + def hello + "omg" + end + end + + class WithSymbolReturningString < Base + layout :no_hello + + def index + render :_template => ActionView::TextTemplate.new("Hello missing symbol!") + end + private + def no_hello + nil + end + end + + class WithSymbolReturningNil < Base + layout :nilz + + def index + render :_template => ActionView::TextTemplate.new("Hello nilz!") + end + + def nilz() end + end + + class WithSymbolReturningObj < Base + layout :objekt + + def index + render :_template => ActionView::TextTemplate.new("Hello nilz!") + end + + def objekt + Object.new + end + end + + class WithSymbolAndNoMethod < Base + layout :omg_no_method + + def index + render :_template => ActionView::TextTemplate.new("Hello boom!") + end + end + + class WithMissingLayout < Base + layout "missing" + + def index + render :_template => ActionView::TextTemplate.new("Hello missing!") + end + end + + class WithFalseLayout < Base + layout false + + def index + render :_template => ActionView::TextTemplate.new("Hello false!") + end + end + + class WithNilLayout < Base + layout nil + + def index + render :_template => ActionView::TextTemplate.new("Hello nil!") + end + end + + class TestBase < ActiveSupport::TestCase + test "when no layout is specified, and no default is available, render without a layout" do + controller = Blank.new + controller.process(:index) + assert_equal "Hello blank!", controller.response_body + end + + test "when layout is specified as a string, render with that layout" do + controller = WithString.new + controller.process(:index) + assert_equal "With String Hello string!", controller.response_body + end + + test "when layout is specified as a string, but the layout is missing, raise an exception" do + assert_raises(ActionView::MissingTemplate) { WithMissingLayout.new.process(:index) } + end + + test "when layout is specified as false, do not use a layout" do + controller = WithFalseLayout.new + controller.process(:index) + assert_equal "Hello false!", controller.response_body + end + + test "when layout is specified as nil, do not use a layout" do + controller = WithNilLayout.new + controller.process(:index) + assert_equal "Hello nil!", controller.response_body + end + + test "when layout is specified as a symbol, call the requested method and use the layout returned" do + controller = WithSymbol.new + controller.process(:index) + assert_equal "OMGHI2U Hello symbol!", controller.response_body + end + + test "when layout is specified as a symbol and the method returns nil, don't use a layout" do + controller = WithSymbolReturningNil.new + controller.process(:index) + assert_equal "Hello nilz!", controller.response_body + end + + test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do + assert_raises(NoMethodError, /:nilz/) { WithSymbolAndNoMethod.new.process(:index) } + end + + test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do + assert_raises(ArgumentError) { WithSymbolReturningObj.new.process(:index) } + end + + test "when a child controller does not have a layout, use the parent controller layout" do + controller = WithStringChild.new + controller.process(:index) + assert_equal "With String Hello string!", controller.response_body + end + + test "when a child controller has specified a layout, use that layout and not the parent controller layout" do + controller = WithStringOverriddenChild.new + controller.process(:index) + assert_equal "With Override Hello string!", controller.response_body + end + + test "when a child controller has an implied layout, use that layout and not the parent controller layout" do + controller = WithStringImpliedChild.new + controller.process(:index) + assert_equal "With Implied Hello string!", controller.response_body + end + + test "when a child controller specifies layout nil, do not use the parent layout" do + controller = WithNilChild.new + controller.process(:index) + assert_equal "Hello string!", controller.response_body + end + + test "when a grandchild has no layout specified, the child has an implied layout, and the " \ + "parent has specified a layout, use the child controller layout" do + controller = WithChildOfImplied.new + controller.process(:index) + assert_equal "With Implied Hello string!", controller.response_body + end + + test "raises an exception when specifying layout true" do + assert_raises ArgumentError do + Object.class_eval do + class ::BadOmgFailLolLayout < AbstractControllerTests::Layouts::Base + layout true + end + end + end + end + end + end +end diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb new file mode 100644 index 0000000000..785bf69191 --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/formatted.html.erb @@ -0,0 +1 @@ +Hello from me3/formatted.html.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb new file mode 100644 index 0000000000..f079ad8204 --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me3/index.erb @@ -0,0 +1 @@ +Hello from me3/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb new file mode 100644 index 0000000000..89dce12bdc --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me4/index.erb @@ -0,0 +1 @@ +Hello from me4/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb new file mode 100644 index 0000000000..84d0b7417e --- /dev/null +++ b/actionpack/test/abstract/views/abstract_controller/testing/me5/index.erb @@ -0,0 +1 @@ +Hello from me5/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/action_with_ivars.erb b/actionpack/test/abstract/views/action_with_ivars.erb new file mode 100644 index 0000000000..8d8ae22fd7 --- /dev/null +++ b/actionpack/test/abstract/views/action_with_ivars.erb @@ -0,0 +1 @@ +<%= @my_ivar %> from index_with_ivars.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/helper_test.erb b/actionpack/test/abstract/views/helper_test.erb new file mode 100644 index 0000000000..8ae45cc195 --- /dev/null +++ b/actionpack/test/abstract/views/helper_test.erb @@ -0,0 +1 @@ +Hello <%= helpery_test %> : <%= included_method %> \ No newline at end of file diff --git a/actionpack/test/abstract/views/index.erb b/actionpack/test/abstract/views/index.erb new file mode 100644 index 0000000000..cc1a8b8c85 --- /dev/null +++ b/actionpack/test/abstract/views/index.erb @@ -0,0 +1 @@ +Hello from index.erb \ No newline at end of file diff --git a/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb new file mode 100644 index 0000000000..172dd56569 --- /dev/null +++ b/actionpack/test/abstract/views/layouts/abstract_controller/testing/me4.erb @@ -0,0 +1 @@ +Me4 Enter : <%= yield %> : Exit \ No newline at end of file diff --git a/actionpack/test/abstract/views/layouts/application.erb b/actionpack/test/abstract/views/layouts/application.erb new file mode 100644 index 0000000000..27317140ad --- /dev/null +++ b/actionpack/test/abstract/views/layouts/application.erb @@ -0,0 +1 @@ +Application Enter : <%= yield %> : Exit \ No newline at end of file diff --git a/actionpack/test/abstract/views/naked_render.erb b/actionpack/test/abstract/views/naked_render.erb new file mode 100644 index 0000000000..1b3d03878b --- /dev/null +++ b/actionpack/test/abstract/views/naked_render.erb @@ -0,0 +1 @@ +Hello from naked_render.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb deleted file mode 100644 index 524381509d..0000000000 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ /dev/null @@ -1,245 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - # Test basic dispatching. - # ==== - # * Call process - # * Test that the response_body is set correctly - class SimpleController < AbstractController::Base - end - - class Me < SimpleController - def index - self.response_body = "Hello world" - "Something else" - end - end - - class TestBasic < ActiveSupport::TestCase - test "dispatching works" do - controller = Me.new - controller.process(:index) - assert_equal "Hello world", controller.response_body - end - end - - # Test Render mixin - # ==== - class RenderingController < AbstractController::Base - include ::AbstractController::RenderingController - - def _prefix() end - - def render(options = {}) - if options.is_a?(String) - options = {:_template_name => options} - end - - options[:_prefix] = _prefix - super - end - - append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) - end - - class Me2 < RenderingController - def index - render "index.erb" - end - - def action_with_ivars - @my_ivar = "Hello" - render "action_with_ivars.erb" - end - - def naked_render - render - end - - def rendering_to_body - self.response_body = render_to_body :_template_name => "naked_render.erb" - end - - def rendering_to_string - self.response_body = render_to_string :_template_name => "naked_render.erb" - end - end - - class TestRenderingController < ActiveSupport::TestCase - def setup - @controller = Me2.new - end - - test "rendering templates works" do - @controller.process(:index) - assert_equal "Hello from index.erb", @controller.response_body - end - - test "rendering passes ivars to the view" do - @controller.process(:action_with_ivars) - assert_equal "Hello from index_with_ivars.erb", @controller.response_body - end - - test "rendering with no template name" do - @controller.process(:naked_render) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - - test "rendering to a rack body" do - @controller.process(:rendering_to_body) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - - test "rendering to a string" do - @controller.process(:rendering_to_string) - assert_equal "Hello from naked_render.erb", @controller.response_body - end - end - - # Test rendering with prefixes - # ==== - # * self._prefix is used when defined - class PrefixedViews < RenderingController - private - def self.prefix - name.underscore - end - - def _prefix - self.class.prefix - end - end - - class Me3 < PrefixedViews - def index - render - end - - def formatted - self.formats = [:html] - render - end - end - - class TestPrefixedViews < ActiveSupport::TestCase - def setup - @controller = Me3.new - end - - test "templates are located inside their 'prefix' folder" do - @controller.process(:index) - assert_equal "Hello from me3/index.erb", @controller.response_body - end - - test "templates included their format" do - @controller.process(:formatted) - assert_equal "Hello from me3/formatted.html.erb", @controller.response_body - end - end - - # Test rendering with layouts - # ==== - # self._layout is used when defined - class WithLayouts < PrefixedViews - include Layouts - - private - def self.layout(formats) - begin - find_template(name.underscore, {:formats => formats}, :_prefix => "layouts") - rescue ActionView::MissingTemplate - begin - find_template("application", {:formats => formats}, :_prefix => "layouts") - rescue ActionView::MissingTemplate - end - end - end - - def render_to_body(options = {}) - options[:_layout] = options[:layout] || _default_layout({}) - super - end - end - - class Me4 < WithLayouts - def index - render - end - end - - class Me5 < WithLayouts - def index - render - end - end - - class TestLayouts < ActiveSupport::TestCase - test "layouts are included" do - controller = Me4.new - result = controller.process(:index) - assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", controller.response_body - end - end - - # respond_to_action?(action_name) - # ==== - # * A method can be used as an action only if this method - # returns true when passed the method name as an argument - # * Defaults to true in AbstractController - class DefaultRespondToActionController < AbstractController::Base - def index() self.response_body = "success" end - end - - class ActionMissingRespondToActionController < AbstractController::Base - # No actions - private - def action_missing(action_name) - self.response_body = "success" - end - end - - class RespondToActionController < AbstractController::Base; - def index() self.response_body = "success" end - - def fail() self.response_body = "fail" end - - private - - def method_for_action(action_name) - action_name.to_s != "fail" && action_name - end - end - - class TestRespondToAction < ActiveSupport::TestCase - - def assert_dispatch(klass, body = "success", action = :index) - controller = klass.new - controller.process(action) - assert_equal body, controller.response_body - end - - test "an arbitrary method is available as an action by default" do - assert_dispatch DefaultRespondToActionController, "success", :index - end - - test "raises ActionNotFound when method does not exist and action_missing is not defined" do - assert_raise(ActionNotFound) { DefaultRespondToActionController.new.process(:fail) } - end - - test "dispatches to action_missing when method does not exist and action_missing is defined" do - assert_dispatch ActionMissingRespondToActionController, "success", :ohai - end - - test "a method is available as an action if respond_to_action? returns true" do - assert_dispatch RespondToActionController, "success", :index - end - - test "raises ActionNotFound if method is defined but respond_to_action? returns false" do - assert_raise(ActionNotFound) { RespondToActionController.new.process(:fail) } - end - end - - end -end diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb deleted file mode 100644 index 0ce1dc506b..0000000000 --- a/actionpack/test/abstract_controller/callbacks_test.rb +++ /dev/null @@ -1,238 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - class ControllerWithCallbacks < AbstractController::Base - include AbstractController::Callbacks - end - - class Callback1 < ControllerWithCallbacks - set_callback :process_action, :before, :first - - def first - @text = "Hello world" - end - - def index - self.response_body = @text - end - end - - class TestCallbacks1 < ActiveSupport::TestCase - test "basic callbacks work" do - controller = Callback1.new - result = controller.process(:index) - assert_equal "Hello world", controller.response_body - end - end - - class Callback2 < ControllerWithCallbacks - before_filter :first - after_filter :second - around_filter :aroundz - - def first - @text = "Hello world" - end - - def second - @second = "Goodbye" - end - - def aroundz - @aroundz = "FIRST" - yield - @aroundz << "SECOND" - end - - def index - self.response_body = @text - end - end - - class TestCallbacks2 < ActiveSupport::TestCase - def setup - @controller = Callback2.new - end - - test "before_filter works" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "after_filter works" do - @controller.process(:index) - assert_equal "Goodbye", @controller.instance_variable_get("@second") - end - - test "around_filter works" do - @controller.process(:index) - assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz") - end - end - - class Callback3 < ControllerWithCallbacks - before_filter do |c| - c.instance_variable_set("@text", "Hello world") - end - - after_filter do |c| - c.instance_variable_set("@second", "Goodbye") - end - - def index - self.response_body = @text - end - end - - class TestCallbacks3 < ActiveSupport::TestCase - def setup - @controller = Callback3.new - end - - test "before_filter works with procs" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "after_filter works with procs" do - result = @controller.process(:index) - assert_equal "Goodbye", @controller.instance_variable_get("@second") - end - end - - class CallbacksWithConditions < ControllerWithCallbacks - before_filter :list, :only => :index - before_filter :authenticate, :except => :index - - def index - self.response_body = @list.join(", ") - end - - def sekrit_data - self.response_body = (@list + [@authenticated]).join(", ") - end - - private - def list - @list = ["Hello", "World"] - end - - def authenticate - @list = [] - @authenticated = "true" - end - end - - class TestCallbacksWithConditions < ActiveSupport::TestCase - def setup - @controller = CallbacksWithConditions.new - end - - test "when :only is specified, a before filter is triggered on that action" do - @controller.process(:index) - assert_equal "Hello, World", @controller.response_body - end - - test "when :only is specified, a before filter is not triggered on other actions" do - @controller.process(:sekrit_data) - assert_equal "true", @controller.response_body - end - - test "when :except is specified, an after filter is not triggered on that action" do - result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") - end - end - - class CallbacksWithArrayConditions < ControllerWithCallbacks - before_filter :list, :only => [:index, :listy] - before_filter :authenticate, :except => [:index, :listy] - - def index - self.response_body = @list.join(", ") - end - - def sekrit_data - self.response_body = (@list + [@authenticated]).join(", ") - end - - private - def list - @list = ["Hello", "World"] - end - - def authenticate - @list = [] - @authenticated = "true" - end - end - - class TestCallbacksWithArrayConditions < ActiveSupport::TestCase - def setup - @controller = CallbacksWithArrayConditions.new - end - - test "when :only is specified with an array, a before filter is triggered on that action" do - result = @controller.process(:index) - assert_equal "Hello, World", @controller.response_body - end - - test "when :only is specified with an array, a before filter is not triggered on other actions" do - result = @controller.process(:sekrit_data) - assert_equal "true", @controller.response_body - end - - test "when :except is specified with an array, an after filter is not triggered on that action" do - result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") - end - end - - class ChangedConditions < Callback2 - before_filter :first, :only => :index - - def not_index - self.response_body = @text.to_s - end - end - - class TestCallbacksWithChangedConditions < ActiveSupport::TestCase - def setup - @controller = ChangedConditions.new - end - - test "when a callback is modified in a child with :only, it works for the :only action" do - result = @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "when a callback is modified in a child with :only, it does not work for other actions" do - result = @controller.process(:not_index) - assert_equal "", @controller.response_body - end - end - - class SetsResponseBody < ControllerWithCallbacks - before_filter :set_body - - def index - self.response_body = "Fail" - end - - def set_body - self.response_body = "Success" - end - end - - class TestHalting < ActiveSupport::TestCase - test "when a callback sets the response body, the action should not be invoked" do - controller = SetsResponseBody.new - controller.process(:index) - assert_equal "Success", controller.response_body - end - end - - end -end diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb deleted file mode 100644 index 5a363c9aa5..0000000000 --- a/actionpack/test/abstract_controller/helper_test.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'abstract_unit' - -module AbstractController - module Testing - - class ControllerWithHelpers < AbstractController::Base - include AbstractController::RenderingController - include Helpers - - def render(string) - super(:_template_name => string) - end - - append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) - end - - module HelperyTest - def included_method - "Included" - end - end - - class MyHelpers1 < ControllerWithHelpers - helper(HelperyTest) do - def helpery_test - "World" - end - end - - def index - render "helper_test.erb" - end - end - - class TestHelpers < ActiveSupport::TestCase - def test_helpers - controller = MyHelpers1.new - controller.process(:index) - assert_equal "Hello World : Included", controller.response_body - end - end - - end -end diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb deleted file mode 100644 index 453d31826e..0000000000 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ /dev/null @@ -1,235 +0,0 @@ -require 'abstract_unit' -require 'active_support/core_ext/class/removal' - -module AbstractControllerTests - module Layouts - - # Base controller for these tests - class Base < AbstractController::Base - include AbstractController::RenderingController - include AbstractController::Layouts - - self.view_paths = [ActionView::FixtureResolver.new( - "layouts/hello.erb" => "With String <%= yield %>", - "layouts/hello_override.erb" => "With Override <%= yield %>", - "layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" => - "With Implied <%= yield %>", - "layouts/omg.erb" => "OMGHI2U <%= yield %>", - "layouts/with_false_layout.erb" => "False Layout <%= yield %>" - )] - - def self.controller_path - @controller_path ||= self.name.sub(/Controller$/, '').underscore - end - - def controller_path() self.class.controller_path end - - def render_to_body(options) - options[:_layout] = _default_layout({}) - super - end - end - - class Blank < Base - self.view_paths = [] - - def index - render :_template => ActionView::TextTemplate.new("Hello blank!") - end - end - - class WithString < Base - layout "hello" - - def index - render :_template => ActionView::TextTemplate.new("Hello string!") - end - end - - class WithStringChild < WithString - end - - class WithStringOverriddenChild < WithString - layout "hello_override" - end - - class WithNilChild < WithString - layout nil - end - - class WithStringImpliedChild < WithString - end - - class WithChildOfImplied < WithStringImpliedChild - end - - class WithSymbol < Base - layout :hello - - def index - render :_template => ActionView::TextTemplate.new("Hello symbol!") - end - private - def hello - "omg" - end - end - - class WithSymbolReturningString < Base - layout :no_hello - - def index - render :_template => ActionView::TextTemplate.new("Hello missing symbol!") - end - private - def no_hello - nil - end - end - - class WithSymbolReturningNil < Base - layout :nilz - - def index - render :_template => ActionView::TextTemplate.new("Hello nilz!") - end - - def nilz() end - end - - class WithSymbolReturningObj < Base - layout :objekt - - def index - render :_template => ActionView::TextTemplate.new("Hello nilz!") - end - - def objekt - Object.new - end - end - - class WithSymbolAndNoMethod < Base - layout :omg_no_method - - def index - render :_template => ActionView::TextTemplate.new("Hello boom!") - end - end - - class WithMissingLayout < Base - layout "missing" - - def index - render :_template => ActionView::TextTemplate.new("Hello missing!") - end - end - - class WithFalseLayout < Base - layout false - - def index - render :_template => ActionView::TextTemplate.new("Hello false!") - end - end - - class WithNilLayout < Base - layout nil - - def index - render :_template => ActionView::TextTemplate.new("Hello nil!") - end - end - - class TestBase < ActiveSupport::TestCase - test "when no layout is specified, and no default is available, render without a layout" do - controller = Blank.new - controller.process(:index) - assert_equal "Hello blank!", controller.response_body - end - - test "when layout is specified as a string, render with that layout" do - controller = WithString.new - controller.process(:index) - assert_equal "With String Hello string!", controller.response_body - end - - test "when layout is specified as a string, but the layout is missing, raise an exception" do - assert_raises(ActionView::MissingTemplate) { WithMissingLayout.new.process(:index) } - end - - test "when layout is specified as false, do not use a layout" do - controller = WithFalseLayout.new - controller.process(:index) - assert_equal "Hello false!", controller.response_body - end - - test "when layout is specified as nil, do not use a layout" do - controller = WithNilLayout.new - controller.process(:index) - assert_equal "Hello nil!", controller.response_body - end - - test "when layout is specified as a symbol, call the requested method and use the layout returned" do - controller = WithSymbol.new - controller.process(:index) - assert_equal "OMGHI2U Hello symbol!", controller.response_body - end - - test "when layout is specified as a symbol and the method returns nil, don't use a layout" do - controller = WithSymbolReturningNil.new - controller.process(:index) - assert_equal "Hello nilz!", controller.response_body - end - - test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do - assert_raises(NoMethodError, /:nilz/) { WithSymbolAndNoMethod.new.process(:index) } - end - - test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do - assert_raises(ArgumentError) { WithSymbolReturningObj.new.process(:index) } - end - - test "when a child controller does not have a layout, use the parent controller layout" do - controller = WithStringChild.new - controller.process(:index) - assert_equal "With String Hello string!", controller.response_body - end - - test "when a child controller has specified a layout, use that layout and not the parent controller layout" do - controller = WithStringOverriddenChild.new - controller.process(:index) - assert_equal "With Override Hello string!", controller.response_body - end - - test "when a child controller has an implied layout, use that layout and not the parent controller layout" do - controller = WithStringImpliedChild.new - controller.process(:index) - assert_equal "With Implied Hello string!", controller.response_body - end - - test "when a child controller specifies layout nil, do not use the parent layout" do - controller = WithNilChild.new - controller.process(:index) - assert_equal "Hello string!", controller.response_body - end - - test "when a grandchild has no layout specified, the child has an implied layout, and the " \ - "parent has specified a layout, use the child controller layout" do - controller = WithChildOfImplied.new - controller.process(:index) - assert_equal "With Implied Hello string!", controller.response_body - end - - test "raises an exception when specifying layout true" do - assert_raises ArgumentError do - Object.class_eval do - class ::BadOmgFailLolLayout < AbstractControllerTests::Layouts::Base - layout true - end - end - end - end - end - end -end diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb deleted file mode 100644 index 785bf69191..0000000000 --- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/formatted.html.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me3/formatted.html.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb deleted file mode 100644 index f079ad8204..0000000000 --- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me3/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me3/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb deleted file mode 100644 index 89dce12bdc..0000000000 --- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me4/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me4/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb b/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb deleted file mode 100644 index 84d0b7417e..0000000000 --- a/actionpack/test/abstract_controller/views/abstract_controller/testing/me5/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from me5/index.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/action_with_ivars.erb b/actionpack/test/abstract_controller/views/action_with_ivars.erb deleted file mode 100644 index 8d8ae22fd7..0000000000 --- a/actionpack/test/abstract_controller/views/action_with_ivars.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @my_ivar %> from index_with_ivars.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/helper_test.erb b/actionpack/test/abstract_controller/views/helper_test.erb deleted file mode 100644 index 8ae45cc195..0000000000 --- a/actionpack/test/abstract_controller/views/helper_test.erb +++ /dev/null @@ -1 +0,0 @@ -Hello <%= helpery_test %> : <%= included_method %> \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/index.erb b/actionpack/test/abstract_controller/views/index.erb deleted file mode 100644 index cc1a8b8c85..0000000000 --- a/actionpack/test/abstract_controller/views/index.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from index.erb \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb b/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb deleted file mode 100644 index 172dd56569..0000000000 --- a/actionpack/test/abstract_controller/views/layouts/abstract_controller/testing/me4.erb +++ /dev/null @@ -1 +0,0 @@ -Me4 Enter : <%= yield %> : Exit \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/layouts/application.erb b/actionpack/test/abstract_controller/views/layouts/application.erb deleted file mode 100644 index 27317140ad..0000000000 --- a/actionpack/test/abstract_controller/views/layouts/application.erb +++ /dev/null @@ -1 +0,0 @@ -Application Enter : <%= yield %> : Exit \ No newline at end of file diff --git a/actionpack/test/abstract_controller/views/naked_render.erb b/actionpack/test/abstract_controller/views/naked_render.erb deleted file mode 100644 index 1b3d03878b..0000000000 --- a/actionpack/test/abstract_controller/views/naked_render.erb +++ /dev/null @@ -1 +0,0 @@ -Hello from naked_render.erb \ No newline at end of file -- cgit v1.2.3 From f5ace625fe524938be35ad7d16bc9c29fd08fb96 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:22:09 -0500 Subject: Ensure changes to I18n locale get reset during tests --- actionpack/test/dispatch/show_exceptions_test.rb | 3 +-- actionpack/test/new_base/render_rjs_test.rb | 11 ++++++++--- actionpack/test/template/render_test.rb | 14 +++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'actionpack') 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/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb index 9c6416bbe0..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_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/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 -- cgit v1.2.3 From d5cfc72f55b89615c60a5afc64f5fb8d63524c46 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:22:58 -0500 Subject: Merge "test_new_base" runner into standard "test_action_pack" --- actionpack/Rakefile | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index aaf1c7f926..113118bfc9 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -32,14 +32,14 @@ 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] 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( "test/{abstract,controller,dispatch,new_base,template,html-scanner}/**/*_test.rb" ).sort t.verbose = true #t.warning = true @@ -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,new_base}/*_test.rb") - t.verbose = true -end - # Genereate the RDoc documentation Rake::RDocTask.new { |rdoc| -- cgit v1.2.3 From 762d7616738a5f922d864d60dee89c44320d8786 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 19 Sep 2009 13:26:54 -0500 Subject: All tests should be ran under isolated_test too --- actionpack/Rakefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 113118bfc9..cc7b4b0043 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -34,22 +34,22 @@ end desc "Run all unit tests" 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/{abstract,controller,dispatch,new_base,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' -- cgit v1.2.3