diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-11-08 18:45:19 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-11-08 18:45:19 +0530 |
commit | 5cc27f2b0302698ef517755df41f3212587bceb9 (patch) | |
tree | bf275362cce3df4e93f3a6a862d5cc7c6977e993 | |
parent | dd77733f2fdb6dde2be7115fc31ad1dcbfccb5a1 (diff) | |
download | rails-5cc27f2b0302698ef517755df41f3212587bceb9.tar.gz rails-5cc27f2b0302698ef517755df41f3212587bceb9.tar.bz2 rails-5cc27f2b0302698ef517755df41f3212587bceb9.zip |
Add some basic controller logging tests
-rw-r--r-- | actionpack/test/controller/logging_test.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb new file mode 100644 index 0000000000..3c936854dd --- /dev/null +++ b/actionpack/test/controller/logging_test.rb @@ -0,0 +1,46 @@ +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 + + def method_missing(method, *args) + @logged ||= [] + @logged << args.first + end + end + + setup :set_logger + + def test_logging_without_parameters + get :show + assert_equal 2, logs.size + assert_nil logs.detect {|l| l =~ /Parameters/ } + end + + def test_logging_with_parameters + get :show, :id => 10 + assert_equal 3, logs.size + + params = logs.detect {|l| l =~ /Parameters/ } + assert_equal 'Parameters: {"id"=>"10"}', params + end + + private + + def set_logger + @controller.logger = MockLogger.new + end + + def logs + @logs ||= @controller.logger.logged.compact.map {|l| l.strip} + end +end |