2014-10-27 00:51:42 +00:00
|
|
|
require 'unit_spec_helper'
|
2010-12-13 22:28:59 +00:00
|
|
|
|
2014-12-24 21:37:04 +00:00
|
|
|
describe Shoulda::Matchers::ActionController::FilterParamMatcher, type: :controller do
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'accepts filtering a filtered parameter' do
|
|
|
|
filter(:secret)
|
2010-12-13 22:28:59 +00:00
|
|
|
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(nil).to filter_param(:secret)
|
2012-12-20 05:04:27 +00:00
|
|
|
end
|
|
|
|
|
2014-08-07 22:06:29 +00:00
|
|
|
it 'accepts filtering a parameter matching a filtered regex' do
|
|
|
|
filter(/(?!tip)pin(?!g)/)
|
|
|
|
|
|
|
|
expect(nil).to filter_param(:pin)
|
|
|
|
end
|
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
it 'rejects filtering an unfiltered parameter' do
|
|
|
|
filter(:secret)
|
|
|
|
matcher = filter_param(:other)
|
|
|
|
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(matcher.matches?(nil)).to eq false
|
2012-12-20 05:04:27 +00:00
|
|
|
|
2014-01-17 22:01:43 +00:00
|
|
|
expect(matcher.failure_message).to match(/Expected other to be filtered.*secret/)
|
2012-12-20 05:04:27 +00:00
|
|
|
end
|
2010-12-13 22:28:59 +00:00
|
|
|
|
2012-12-20 05:04:27 +00:00
|
|
|
def filter(param)
|
|
|
|
Rails.application.config.filter_parameters = [param]
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
end
|