mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
FilterParamMatcher supports Regexps
This commit is contained in:
parent
86fb6b9c1e
commit
1cd4a4cd12
3 changed files with 19 additions and 3 deletions
3
NEWS.md
3
NEWS.md
|
@ -12,6 +12,9 @@
|
|||
session variable in question was set to nil (previously this actually did
|
||||
nothing).
|
||||
|
||||
* Fix `filter_param` so that it works when `config.filter_parameters` contains
|
||||
regexes.
|
||||
|
||||
### Improvements
|
||||
|
||||
* `have_and_belongs_to_many` now checks to make sure that the join table
|
||||
|
|
|
@ -28,7 +28,7 @@ module Shoulda
|
|||
# @private
|
||||
class FilterParamMatcher
|
||||
def initialize(key)
|
||||
@key = key.to_s
|
||||
@key = key
|
||||
end
|
||||
|
||||
def matches?(controller)
|
||||
|
@ -52,11 +52,18 @@ module Shoulda
|
|||
private
|
||||
|
||||
def filters_key?
|
||||
filtered_keys.include?(@key)
|
||||
filtered_keys.any? do |filter|
|
||||
case filter
|
||||
when Regexp
|
||||
filter =~ @key
|
||||
else
|
||||
filter == @key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def filtered_keys
|
||||
Rails.application.config.filter_parameters.map(&:to_s)
|
||||
Rails.application.config.filter_parameters
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,12 @@ describe Shoulda::Matchers::ActionController::FilterParamMatcher do
|
|||
expect(nil).to filter_param(:secret)
|
||||
end
|
||||
|
||||
it 'accepts filtering a parameter matching a filtered regex' do
|
||||
filter(/(?!tip)pin(?!g)/)
|
||||
|
||||
expect(nil).to filter_param(:pin)
|
||||
end
|
||||
|
||||
it 'rejects filtering an unfiltered parameter' do
|
||||
filter(:secret)
|
||||
matcher = filter_param(:other)
|
||||
|
|
Loading…
Add table
Reference in a new issue