aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorYehuda Katz <wycats@Yehuda-Katz.local>2009-12-27 14:36:59 -0800
committerYehuda Katz <wycats@Yehuda-Katz.local>2009-12-27 14:36:59 -0800
commit12e43494a748e0144195be12dc19161cc3e4d39f (patch)
treec06f88b7ddf6e41205838cc6f4edd2257a801dcb /actionpack/test
parent1c26ba486c23f229a12fea6ccad33e6cb3122b91 (diff)
parent97db79ab3c0af7b6805dcaee99384d96ccb3567d (diff)
downloadrails-12e43494a748e0144195be12dc19161cc3e4d39f.tar.gz
rails-12e43494a748e0144195be12dc19161cc3e4d39f.tar.bz2
rails-12e43494a748e0144195be12dc19161cc3e4d39f.zip
Merge remote branch 'jose/perf'
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_unit.rb23
-rw-r--r--actionpack/test/controller/base_test.rb7
-rw-r--r--actionpack/test/controller/benchmark_test.rb33
-rw-r--r--actionpack/test/controller/caching_test.rb2
-rw-r--r--actionpack/test/controller/filter_params_test.rb2
-rw-r--r--actionpack/test/controller/logging_test.rb66
-rw-r--r--actionpack/test/controller/render_test.rb32
7 files changed, 72 insertions, 93 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index a9341b60df..8c65087898 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -50,6 +50,14 @@ ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
+# Turn on notifications
+require 'active_support/notifications'
+Thread.abort_on_exception = true
+
+ActiveSupport::Notifications.subscribe do |*args|
+ ActionController::Base.log_event(*args) if ActionController::Base.logger
+end
+
module SetupOnce
extend ActiveSupport::Concern
@@ -87,6 +95,21 @@ class ActiveSupport::TestCase
end
end
+class MockLogger
+ attr_reader :logged
+ attr_accessor :level
+
+ def initialize
+ @level = Logger::DEBUG
+ @logged = []
+ end
+
+ def method_missing(method, *args, &blk)
+ @logged << args.first
+ @logged << blk.call if block_given?
+ end
+end
+
class ActionController::IntegrationTest < ActiveSupport::TestCase
def self.build_app(routes = nil)
ActionDispatch::MiddlewareStack.new { |middleware|
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 8f8ada8d8c..65118f9bc9 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -158,13 +158,6 @@ class PerformActionTest < ActionController::TestCase
assert_raise(ActionController::UnknownAction) { get :hidden_action }
assert_raise(ActionController::UnknownAction) { get :another_hidden_action }
end
-
- def test_namespaced_action_should_log_module_name
- use_controller Submodule::ContainedNonEmptyController
- @controller.logger = MockLogger.new
- get :public_action
- assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1]
- end
end
class DefaultUrlOptionsTest < ActionController::TestCase
diff --git a/actionpack/test/controller/benchmark_test.rb b/actionpack/test/controller/benchmark_test.rb
deleted file mode 100644
index 66ebfcf20a..0000000000
--- a/actionpack/test/controller/benchmark_test.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require 'abstract_unit'
-
-# Provide some static controllers.
-class BenchmarkedController < ActionController::Base
- def public_action
- render :nothing => true
- end
-
- def rescue_action(e)
- raise e
- end
-end
-
-class BenchmarkTest < ActionController::TestCase
- tests BenchmarkedController
-
- class MockLogger
- def method_missing(*args)
- end
- end
-
- def setup
- super
- # benchmark doesn't do anything unless a logger is set
- @controller.logger = MockLogger.new
- @request.host = "test.actioncontroller.i"
- end
-
- def test_with_http_1_0_request
- @request.host = nil
- assert_nothing_raised { get :public_action }
- end
-end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 4ea2e57741..679eaf7b38 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -640,7 +640,7 @@ class FragmentCachingTest < ActionController::TestCase
assert fragment_computed
assert_equal 'generated till now -> ', buffer
ActiveSupport::Notifications.notifier.wait
- assert_equal [:fragment_exist?, :write_fragment], events.map(&:first)
+ assert_equal [:exist_fragment?, :write_fragment], events.map(&:first)
end
end
diff --git a/actionpack/test/controller/filter_params_test.rb b/actionpack/test/controller/filter_params_test.rb
index 43bef34885..420ebeacf4 100644
--- a/actionpack/test/controller/filter_params_test.rb
+++ b/actionpack/test/controller/filter_params_test.rb
@@ -70,9 +70,9 @@ class FilterParamTest < ActionController::TestCase
FilterParamController.filter_parameter_logging(:lifo, :amount)
get :payment, :lifo => 'Pratik', :amount => '420', :step => '1'
+ ActiveSupport::Notifications.notifier.wait
filtered_params_logs = logs.detect {|l| l =~ /\AParameters/ }
-
assert filtered_params_logs.index('"amount"=>"[FILTERED]"')
assert filtered_params_logs.index('"lifo"=>"[FILTERED]"')
assert filtered_params_logs.index('"step"=>"1"')
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 2b5e8d8bde..4206dffa7e 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -1,48 +1,74 @@
require 'abstract_unit'
-class LoggingController < ActionController::Base
- def show
- render :nothing => true
- end
-end
-
-class LoggingTest < ActionController::TestCase
- tests LoggingController
-
- class MockLogger
- attr_reader :logged
- attr_accessor :level
+module Another
+ class LoggingController < ActionController::Base
+ layout "layouts/standard"
- def initialize
- @level = Logger::DEBUG
+ def show
+ render :nothing => true
end
- def method_missing(method, *args, &blk)
- @logged ||= []
- @logged << args.first
- @logged << blk.call if block_given?
+ def with_layout
+ render :template => "test/hello_world", :layout => true
end
end
+end
+
+class LoggingTest < ActionController::TestCase
+ tests Another::LoggingController
def setup
super
set_logger
end
+ def get(*args)
+ super
+ wait
+ end
+
+ def wait
+ ActiveSupport::Notifications.notifier.wait
+ end
+
def test_logging_without_parameters
get :show
- assert_equal 3, logs.size
+ assert_equal 4, logs.size
assert_nil logs.detect {|l| l =~ /Parameters/ }
end
def test_logging_with_parameters
get :show, :id => '10'
- assert_equal 4, logs.size
+ assert_equal 5, logs.size
params = logs.detect {|l| l =~ /Parameters/ }
assert_equal 'Parameters: {"id"=>"10"}', params
end
+ def test_log_controller_with_namespace_and_action
+ get :show
+ assert_match /Processed\sAnother::LoggingController#show/, logs[1]
+ end
+
+ def test_log_view_runtime
+ get :show
+ assert_match /View runtime/, logs[2]
+ end
+
+ def test_log_completed_status_and_request_uri
+ get :show
+ last = logs.last
+ assert_match /Completed/, last
+ assert_match /200/, last
+ assert_match /another\/logging\/show/, last
+ end
+
+ def test_logger_prints_layout_and_template_rendering_info
+ get :with_layout
+ logged = logs.find {|l| l =~ /render/i }
+ assert_match /Rendered (.*)test\/hello_world.erb within (.*)layouts\/standard.html.erb/, logged
+ end
+
private
def set_logger
@controller.logger = MockLogger.new
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 54f2739d38..2c3dc2a72d 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -10,19 +10,6 @@ module Fun
end
end
-class MockLogger
- attr_reader :logged
-
- def initialize
- @logged = []
- end
-
- def method_missing(method, *args, &blk)
- @logged << args.first
- @logged << blk.call if block_given?
- end
-end
-
class TestController < ActionController::Base
protect_from_forgery
@@ -1500,21 +1487,4 @@ class LastModifiedRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :success
end
-end
-
-class RenderingLoggingTest < ActionController::TestCase
- tests TestController
-
- def setup
- super
- @request.host = "www.nextangle.com"
- end
-
- def test_logger_prints_layout_and_template_rendering_info
- @controller.logger = MockLogger.new
- get :layout_test
- logged = @controller.logger.logged.find_all {|l| l =~ /render/i }
- assert logged[0] =~ %r{Rendering.*test/hello_world}
- assert logged[1] =~ %r{Rendering template within.*layouts/standard}
- end
-end
+end \ No newline at end of file