~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/controller/filter_params_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 FilterParamController < ActionController::Base
4
 
end
5
 
 
6
 
class FilterParamTest < Test::Unit::TestCase
7
 
  def setup
8
 
    @controller = FilterParamController.new
9
 
  end
10
 
 
11
 
  def test_filter_parameters
12
 
    assert FilterParamController.respond_to?(:filter_parameter_logging)
13
 
    assert !@controller.respond_to?(:filter_parameters)
14
 
 
15
 
    FilterParamController.filter_parameter_logging
16
 
    assert @controller.respond_to?(:filter_parameters)
17
 
 
18
 
    test_hashes = [[{},{},[]],
19
 
    [{'foo'=>nil},{'foo'=>nil},[]],
20
 
    [{'foo'=>'bar'},{'foo'=>'bar'},[]],
21
 
    [{'foo'=>1},{'foo'=>1},[]],
22
 
    [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
23
 
    [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
24
 
    [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
25
 
    [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
26
 
    [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
27
 
    [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'],
28
 
    [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)],
29
 
    [{'baz'=>[{'foo'=>'baz'}, 1, 2, 3]}, {'baz'=>[{'foo'=>'[FILTERED]'}, 1, 2, 3]}, %w(foo)]]
30
 
 
31
 
    test_hashes.each do |before_filter, after_filter, filter_words|
32
 
      FilterParamController.filter_parameter_logging(*filter_words)
33
 
      assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
34
 
 
35
 
      filter_words.push('blah')
36
 
      FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
37
 
        value.reverse! if key =~ /bargain/
38
 
      end
39
 
 
40
 
      before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
41
 
      after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
42
 
 
43
 
      assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
44
 
    end
45
 
  end
46
 
 
47
 
  def test_filter_parameters_is_protected
48
 
    FilterParamController.filter_parameter_logging(:foo)
49
 
    assert !FilterParamController.action_methods.include?('filter_parameters')
50
 
    assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
51
 
  end
52
 
end