File tree 3 files changed +23
-5
lines changed
3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,12 @@ def matches?(subject)
40
40
41
41
if @with . present?
42
42
options = @subject . class . normalizy_rules [ @attribute ]
43
- options = ( options || [ ] ) + extract_defaults
43
+
44
+ return false if options . blank?
45
+
46
+ if options . map { |option | option [ :rules ] } . compact . blank?
47
+ options = default_rules
48
+ end
44
49
45
50
return false if options . blank?
46
51
@@ -81,7 +86,7 @@ def actual_value
81
86
value . is_a? ( String ) ? %("#{ value } ") : value
82
87
end
83
88
84
- def extract_defaults
89
+ def default_rules
85
90
[ Normalizy . config . default_filters ] . flatten . compact . map do |rule |
86
91
{ rules : rule }
87
92
end
Original file line number Diff line number Diff line change 51
51
config . default_filters = :squish
52
52
end
53
53
54
- matcher = described_class . new ( :downcase_field )
54
+ matcher = described_class . new ( :alone )
55
55
56
56
matcher . with :squish
57
57
63
63
config . default_filters = [ :squish ]
64
64
end
65
65
66
- matcher = described_class . new ( :downcase_field )
66
+ matcher = described_class . new ( :alone )
67
67
68
68
matcher . with :squish
69
69
75
75
config . default_filters = [ { strip : { side : :left } } ]
76
76
end
77
77
78
- matcher = described_class . new ( :downcase_field )
78
+ matcher = described_class . new ( :alone )
79
79
80
80
matcher . with ( strip : { side : :left } )
81
81
82
82
expect ( matcher . matches? ( object ) ) . to eq true
83
83
end
84
+
85
+ specify do
86
+ Normalizy . configure do |config |
87
+ config . default_filters = :squish
88
+ end
89
+
90
+ matcher = described_class . new ( :downcase_field )
91
+
92
+ matcher . with :squish
93
+
94
+ expect ( matcher . matches? ( object ) ) . to eq false
95
+ end
84
96
end
85
97
86
98
context 'when .with is not called' do
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
class Match < ActiveRecord ::Base
4
+ normalizy :alone
4
5
normalizy :downcase_field , with : :downcase
5
6
normalizy :trim_side_left , with : { trim : { side : :left } }
6
7
normalizy :trim_side_left_array , with : [ { trim : { side : :left } } ]
You can’t perform that action at this time.
0 commit comments