thoughtbot--shoulda-matchers/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb

29 lines
710 B
Ruby
Raw Normal View History

require 'unit_spec_helper'
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)
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
2012-12-20 05:04:27 +00:00
def filter(param)
Rails.application.config.filter_parameters = [param]
end
end