aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-26 20:28:53 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-26 20:28:53 +0100
commit75ba102a80965b2612df0253d1278581a88b8d66 (patch)
tree435658d7914821be2e745bf3468139cf6a753a07 /actionpack/test/controller
parent8a36e907d2a0a28be1fa8334221cc2e195d75168 (diff)
downloadrails-75ba102a80965b2612df0253d1278581a88b8d66.tar.gz
rails-75ba102a80965b2612df0253d1278581a88b8d66.tar.bz2
rails-75ba102a80965b2612df0253d1278581a88b8d66.zip
Remove ActionView inline logging to ActiveSupport::Notifications and create ActionController::Base#log_event, so everything can be logged within one listener. Also expose log_process_action as a hook for different modules to include their own information during the action processing. This allow ActiveRecord to hook and any other ORM. Finally, this commit changes 'Processing' and 'Rendering' in logs to 'Processed' and 'Rendered' because at the point it's logged, everying already happened.
Diffstat (limited to 'actionpack/test/controller')
-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
6 files changed, 49 insertions, 93 deletions
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