~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/controller/logging_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'abstract_unit'
2
 
 
3
 
class LoggingController < ActionController::Base
4
 
  def show
5
 
    render :nothing => true
6
 
  end
7
 
end
8
 
 
9
 
class LoggingTest < ActionController::TestCase
10
 
  tests LoggingController
11
 
 
12
 
  class MockLogger
13
 
    attr_reader :logged
14
 
    
15
 
    def method_missing(method, *args)
16
 
      @logged ||= []
17
 
      @logged << args.first
18
 
    end
19
 
  end
20
 
 
21
 
  setup :set_logger
22
 
 
23
 
  def test_logging_without_parameters
24
 
    get :show
25
 
    assert_equal 2, logs.size
26
 
    assert_nil logs.detect {|l| l =~ /Parameters/ }
27
 
  end
28
 
 
29
 
  def test_logging_with_parameters
30
 
    get :show, :id => 10
31
 
    assert_equal 3, logs.size
32
 
 
33
 
    params = logs.detect {|l| l =~ /Parameters/ }
34
 
    assert_equal 'Parameters: {"id"=>"10"}', params
35
 
  end
36
 
  
37
 
  private
38
 
 
39
 
  def set_logger
40
 
    @controller.logger = MockLogger.new
41
 
  end
42
 
  
43
 
  def logs
44
 
    @logs ||= @controller.logger.logged.compact.map {|l| l.strip}
45
 
  end
46
 
end