2010-12-15 22:34:19 +00:00
|
|
|
module Shoulda # :nodoc:
|
|
|
|
module Matchers
|
|
|
|
module ActionController # :nodoc:
|
|
|
|
# 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)
|
|
|
|
filters_key?
|
|
|
|
end
|
|
|
|
|
2013-12-24 11:24:27 +00:00
|
|
|
def failure_message
|
2010-12-15 22:34:19 +00:00
|
|
|
"Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
|
|
|
|
end
|
2013-12-24 11:24:27 +00:00
|
|
|
alias failure_message_for_should failure_message
|
2010-12-15 22:34:19 +00:00
|
|
|
|
2013-12-24 11:24:27 +00:00
|
|
|
def failure_message_when_negated
|
2010-12-15 22:34:19 +00:00
|
|
|
"Did not expect #{@key} to be filtered"
|
|
|
|
end
|
2013-12-24 11:24:27 +00:00
|
|
|
alias failure_message_for_should_not failure_message_when_negated
|
2010-12-15 22:34:19 +00:00
|
|
|
|
|
|
|
def description
|
|
|
|
"filter #{@key}"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def filters_key?
|
|
|
|
filtered_keys.include?(@key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_keys
|
2012-03-30 15:22:31 +00:00
|
|
|
Rails.application.config.filter_parameters.map(&:to_s)
|
2010-12-15 22:34:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|