Sha256: 510e0b1fd5a74014809b9a4d4506a34ae12d25b44d87c7f933a1937c50d001b2

Contents?: true

Size: 1.7 KB

Versions: 91

Compression:

Stored size: 1.7 KB

Contents

module Shoulda # :nodoc:
  module ActionController # :nodoc:
    module Matchers

      # Ensures that filter_parameter_logging is set for the specified key.
      #
      # Example:
      #
      #   it { should filter_param(:password) }
      def filter_param(key)
        FilterParamMatcher.new(key)
      end

      class FilterParamMatcher # :nodoc:

        def initialize(key)
          @key = key.to_s
        end

        def matches?(controller)
          @controller = controller
          filters_params? && filters_key?
        end

        def failure_message
          "Expected #{@key} to be filtered"
        end

        def negative_failure_message
          "Did not expect #{@key} to be filtered"
        end

        def description
          "filter #{@key}"
        end

        private

        def filters_params?
          @controller.respond_to?(:filter_parameters) ||
            request.respond_to?(:filtered_parameters)
        end

        def filters_key?
          filtered_value == '[FILTERED]'
        end

        def filtered_value
          if request.respond_to?(:filtered_parameters)
            filtered_request_value
          else
            filtered_controller_value
          end
        end

        def filtered_controller_value
          filtered = @controller.send(:filter_parameters,
                                      @key.to_s => @key.to_s)
          filtered[@key.to_s]
        end

        def filtered_request_value
          request.env['action_dispatch.request.parameters'] = { @key.to_s => 'value' }
          request.filtered_parameters[@key.to_s]
        end

        def request
          @request ||= ::ActionController::TestRequest.new
        end
      end

    end
  end
end

Version data entries

91 entries across 61 versions & 10 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/filter_param_matcher.rb