normalizy 1.4.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -24
- data/README.md +33 -16
- data/lib/normalizy/config.rb +2 -1
- data/lib/normalizy/filters/date.rb +2 -4
- data/lib/normalizy/filters/money.rb +2 -2
- data/lib/normalizy/filters/percent.rb +2 -2
- data/lib/normalizy/filters/slug.rb +1 -1
- data/lib/normalizy/filters/strip.rb +1 -1
- data/lib/normalizy/filters/truncate.rb +16 -0
- data/lib/normalizy/version.rb +1 -1
- metadata +31 -96
- data/spec/normalizy/config/add_spec.rb +0 -21
- data/spec/normalizy/config/alias_spec.rb +0 -29
- data/spec/normalizy/config/default_filters_spec.rb +0 -19
- data/spec/normalizy/config/initialize_spec.rb +0 -16
- data/spec/normalizy/config/normalizy_aliases_spec.rb +0 -9
- data/spec/normalizy/extensions/filters/date_spec.rb +0 -23
- data/spec/normalizy/extensions/filters/money_spec.rb +0 -38
- data/spec/normalizy/extensions/filters/number_spec.rb +0 -9
- data/spec/normalizy/extensions/filters/percent_spec.rb +0 -30
- data/spec/normalizy/extensions/filters/slug_spec.rb +0 -14
- data/spec/normalizy/extensions/filters/strip_spec.rb +0 -21
- data/spec/normalizy/extensions/model_spec.rb +0 -107
- data/spec/normalizy/extensions/normalizy_rules_spec.rb +0 -198
- data/spec/normalizy/filters/date_spec.rb +0 -69
- data/spec/normalizy/filters/money_spec.rb +0 -282
- data/spec/normalizy/filters/number_spec.rb +0 -33
- data/spec/normalizy/filters/percent_spec.rb +0 -168
- data/spec/normalizy/filters/slug_spec.rb +0 -24
- data/spec/normalizy/filters/strip_spec.rb +0 -13
- data/spec/normalizy/normalizy/configure_spec.rb +0 -11
- data/spec/normalizy/rspec/matcher/description_spec.rb +0 -27
- data/spec/normalizy/rspec/matcher/failure_message_spec.rb +0 -48
- data/spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb +0 -30
- data/spec/normalizy/rspec/matcher/from_spec.rb +0 -19
- data/spec/normalizy/rspec/matcher/matches_spec.rb +0 -117
- data/spec/normalizy/rspec/matcher/to_spec.rb +0 -19
- data/spec/rails_helper.rb +0 -9
- data/spec/support/common.rb +0 -11
- data/spec/support/db/schema.rb +0 -83
- data/spec/support/filters/blacklist.rb +0 -11
- data/spec/support/filters/block.rb +0 -11
- data/spec/support/filters/info.rb +0 -11
- data/spec/support/models/alias.rb +0 -7
- data/spec/support/models/match.rb +0 -9
- data/spec/support/models/model.rb +0 -28
- data/spec/support/models/model_date.rb +0 -9
- data/spec/support/models/model_money.rb +0 -10
- data/spec/support/models/model_number.rb +0 -5
- data/spec/support/models/model_percent.rb +0 -10
- data/spec/support/models/model_slug.rb +0 -6
- data/spec/support/models/model_strip.rb +0 -8
- data/spec/support/models/rule.rb +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee7f65965cec5c289729431b01fcf23be051784ec7b18bf9b71ae00c698d9d93
|
|
4
|
+
data.tar.gz: ad9ce5473030dec2eae92783feecf6895e8e5e841bee48b5af46f4b6579dcc12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2c043c42e3627fb56b02defc6a0081311da5b72dfb1da0ecda255abca81a734b4a47c4c25054f24d5c4dec75059862fa250482e54d84f79a6905ecde4e5a7cc
|
|
7
|
+
data.tar.gz: eec956c476590a3a521f33ed58e657add31f52d391cb29362856d9dce14968f8d55df4f38b7d030071283da2d236ee1ec87654c5b6598a181ea45c227ef32216
|
data/CHANGELOG.md
CHANGED
|
@@ -1,54 +1,95 @@
|
|
|
1
|
+
## v1.7.0
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- Adds `truncate` filter; [#3](https://github.com/wbotelhos/normalizy/pull/3) by [rafaeldev](https://github.com/rafaeldev)
|
|
6
|
+
|
|
7
|
+
### Updates
|
|
8
|
+
|
|
9
|
+
- Adds RuboCop task on the CI;
|
|
10
|
+
|
|
11
|
+
## v1.6.0
|
|
12
|
+
|
|
13
|
+
### Fixes
|
|
14
|
+
|
|
15
|
+
- Fix Money Filter to use the correct default Rails path for Currency and Percentage;
|
|
16
|
+
|
|
17
|
+
### Updates
|
|
18
|
+
|
|
19
|
+
- Adds Code Quality;
|
|
20
|
+
- Adds Test Coverage;
|
|
21
|
+
- Migrates the build to Github Actions;
|
|
22
|
+
- Removes Git dependency for the build;
|
|
23
|
+
|
|
24
|
+
## v1.5.0
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
- Filter `date` now supports call object that responds to `beginning_of_day` or `end_of_day`;
|
|
29
|
+
|
|
1
30
|
## v1.4.0
|
|
2
31
|
|
|
32
|
+
### Features
|
|
33
|
+
|
|
3
34
|
- Adds `date` support for `Date` class.
|
|
4
35
|
|
|
5
36
|
## v1.3.0
|
|
6
37
|
|
|
7
|
-
|
|
8
|
-
|
|
38
|
+
### Updates
|
|
39
|
+
|
|
40
|
+
- Support Rails 6.
|
|
9
41
|
|
|
10
42
|
## v1.2.0
|
|
11
43
|
|
|
12
|
-
|
|
13
|
-
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
- `money` filter now allows negative numbers.
|
|
14
47
|
|
|
15
48
|
## v1.1.1
|
|
16
49
|
|
|
17
|
-
|
|
18
|
-
|
|
50
|
+
### Fixes
|
|
51
|
+
|
|
52
|
+
- When using `slug` filter the original values were not saved.
|
|
19
53
|
|
|
20
54
|
## v1.1.0
|
|
21
55
|
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
### Features
|
|
57
|
+
|
|
58
|
+
- Added `slug` filter with the option to apply the value on other fields.
|
|
24
59
|
|
|
25
60
|
## v1.0.1
|
|
26
61
|
|
|
27
|
-
|
|
28
|
-
|
|
62
|
+
### Fixes
|
|
63
|
+
|
|
64
|
+
- When `type` options were `cents` and had no decimal on the number, extra decimals were added.
|
|
29
65
|
|
|
30
66
|
## v1.0.0
|
|
31
67
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
68
|
+
### Updates
|
|
69
|
+
|
|
70
|
+
- `raw` options was dropped since `prepend` already works before type cast;
|
|
71
|
+
- Multiple lines of `normalizy` will be evaluated from the bottom to top.
|
|
72
|
+
|
|
73
|
+
### Features
|
|
35
74
|
|
|
36
|
-
-
|
|
37
|
-
- `alias` configuration now accepts options;
|
|
75
|
+
- `alias` configuration now accepts options;
|
|
38
76
|
|
|
39
|
-
|
|
40
|
-
|
|
77
|
+
### Fixes
|
|
78
|
+
|
|
79
|
+
- Multiple filters were not running together.
|
|
41
80
|
|
|
42
81
|
## v0.2.0
|
|
43
82
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
83
|
+
### Updates
|
|
84
|
+
|
|
85
|
+
- `number` filter no more make cast automatically.
|
|
86
|
+
- `number` now accept `cast` options with a method to be used on cast type;
|
|
87
|
+
|
|
88
|
+
### Features
|
|
47
89
|
|
|
48
|
-
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- add `percent` filter with `cast`, `type` and I18n support.
|
|
90
|
+
- add `date` filter with `format`, `time_zone` and I18n error message support;
|
|
91
|
+
- add `money` filter with `cast`, `type` and I18n support;
|
|
92
|
+
- add `percent` filter with `cast`, `type` and I18n support.
|
|
52
93
|
|
|
53
94
|
## v0.1.0
|
|
54
95
|
|
data/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# Normalizy
|
|
2
2
|
|
|
3
|
-
[](https://github.com/wbotelhos/normalizy/actions)
|
|
4
4
|
[](https://badge.fury.io/rb/normalizy)
|
|
5
|
-
[](https://codeclimate.com/github/wbotelhos/normalizy/maintainability)
|
|
6
|
+
[](https://codecov.io/gh/wbotelhos/normalizy)
|
|
7
|
+
[](https://www.patreon.com/wbotelhos)
|
|
6
8
|
|
|
7
|
-
Attribute normalizer for
|
|
9
|
+
Attribute normalizer for Rails.
|
|
8
10
|
|
|
9
11
|
## Description
|
|
10
12
|
|
|
@@ -140,9 +142,10 @@ If you do not want pass it as options, Normalizy will fetch your I18n config:
|
|
|
140
142
|
|
|
141
143
|
```yaml
|
|
142
144
|
en:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
number:
|
|
146
|
+
currency:
|
|
147
|
+
format:
|
|
148
|
+
separator: '.'
|
|
146
149
|
```
|
|
147
150
|
|
|
148
151
|
And if it does not exists, `.` will be used as default.
|
|
@@ -190,9 +193,10 @@ If you do not want pass it as options, Normalizy will fetch your I18n config:
|
|
|
190
193
|
|
|
191
194
|
```yaml
|
|
192
195
|
en:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
number:
|
|
197
|
+
currency:
|
|
198
|
+
format:
|
|
199
|
+
precision: 2
|
|
196
200
|
```
|
|
197
201
|
|
|
198
202
|
And if it does not exists, `2` will be used as default.
|
|
@@ -265,9 +269,10 @@ If you do not want pass it as options, Normalizy will fetch your I18n config:
|
|
|
265
269
|
|
|
266
270
|
```yaml
|
|
267
271
|
en:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
number:
|
|
273
|
+
percentage:
|
|
274
|
+
format:
|
|
275
|
+
separator: '.'
|
|
271
276
|
```
|
|
272
277
|
|
|
273
278
|
And if it does not exists, `.` will be used as default.
|
|
@@ -315,9 +320,10 @@ If you do not want pass it as options, Normalizy will fetch your I18n config:
|
|
|
315
320
|
|
|
316
321
|
```yaml
|
|
317
322
|
en:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
323
|
+
number:
|
|
324
|
+
percentage:
|
|
325
|
+
format:
|
|
326
|
+
separator: 2
|
|
321
327
|
```
|
|
322
328
|
|
|
323
329
|
And if it does not exists, `2` will be used as default.
|
|
@@ -400,6 +406,17 @@ normalizy :name, with: { strip: { side: :both } }
|
|
|
400
406
|
|
|
401
407
|
As you can see, the rules can be passed as Symbol/String or as Hash if it has options.
|
|
402
408
|
|
|
409
|
+
### Truncate
|
|
410
|
+
|
|
411
|
+
Remove excedent string part from a gived limit.
|
|
412
|
+
|
|
413
|
+
```ruby
|
|
414
|
+
normalizy :description, with: { truncate: { limit: 10 } }
|
|
415
|
+
|
|
416
|
+
'Once upon a time in a world far far away'
|
|
417
|
+
# 'Once upon '
|
|
418
|
+
```
|
|
419
|
+
|
|
403
420
|
## Multiple Filters
|
|
404
421
|
|
|
405
422
|
You can normalize with a couple of filters at once:
|
|
@@ -449,7 +466,7 @@ Now, all normalization will include `squish`, even when no rule is declared.
|
|
|
449
466
|
|
|
450
467
|
```ruby
|
|
451
468
|
normalizy :name
|
|
452
|
-
|
|
469
|
+
" Washington \n Botelho "
|
|
453
470
|
# 'Washington Botelho'
|
|
454
471
|
```
|
|
455
472
|
|
data/lib/normalizy/config.rb
CHANGED
|
@@ -29,7 +29,8 @@ module Normalizy
|
|
|
29
29
|
number: Normalizy::Filters::Number,
|
|
30
30
|
percent: Normalizy::Filters::Percent,
|
|
31
31
|
slug: Normalizy::Filters::Slug,
|
|
32
|
-
strip: Normalizy::Filters::Strip
|
|
32
|
+
strip: Normalizy::Filters::Strip,
|
|
33
|
+
truncate: Normalizy::Filters::Truncate,
|
|
33
34
|
}
|
|
34
35
|
end
|
|
35
36
|
end
|
|
@@ -13,10 +13,8 @@ module Normalizy
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
if [
|
|
17
|
-
|
|
18
|
-
input = input.end_of_day if options[:adjust] == :end
|
|
19
|
-
end
|
|
16
|
+
input = input.beginning_of_day if options[:adjust] == :begin && input.respond_to?(:beginning_of_day)
|
|
17
|
+
input = input.end_of_day if options[:adjust] == :end && input.respond_to?(:end_of_day)
|
|
20
18
|
|
|
21
19
|
input
|
|
22
20
|
rescue ArgumentError
|
|
@@ -29,7 +29,7 @@ module Normalizy
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def precision(options)
|
|
32
|
-
options.fetch
|
|
32
|
+
options.fetch(:precision, I18n.t('number.currency.format.precision', default: 2))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def precisioned(value, options)
|
|
@@ -37,7 +37,7 @@ module Normalizy
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def separator(options)
|
|
40
|
-
options.fetch
|
|
40
|
+
options.fetch(:separator, I18n.t('number.currency.format.separator', default: '.'))
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -29,7 +29,7 @@ module Normalizy
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def precision(options)
|
|
32
|
-
options.fetch
|
|
32
|
+
options.fetch(:precision, I18n.t('number.percentage.format.precision', default: 2))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def precisioned(value, options)
|
|
@@ -37,7 +37,7 @@ module Normalizy
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def separator(options)
|
|
40
|
-
options.fetch
|
|
40
|
+
options.fetch(:separator, I18n.t('number.percentage.format.separator', default: '.'))
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Normalizy
|
|
4
|
+
module Filters
|
|
5
|
+
module Truncate
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def call(input, options = {})
|
|
9
|
+
return input unless options[:limit].is_a?(Integer)
|
|
10
|
+
return input unless input.is_a?(String)
|
|
11
|
+
|
|
12
|
+
input[0, options[:limit]]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/normalizy/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: normalizy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Washington Botelho
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -25,7 +25,21 @@ dependencies:
|
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '4.1'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: codecov
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: debug
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
30
44
|
requirements:
|
|
31
45
|
- - ">="
|
|
@@ -108,11 +122,14 @@ dependencies:
|
|
|
108
122
|
- - ">="
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
124
|
version: '0'
|
|
111
|
-
description: Attribute normalizer for
|
|
125
|
+
description: Attribute normalizer for Rails.
|
|
112
126
|
email: wbotelhos@gmail.com
|
|
113
127
|
executables: []
|
|
114
128
|
extensions: []
|
|
115
|
-
extra_rdoc_files:
|
|
129
|
+
extra_rdoc_files:
|
|
130
|
+
- CHANGELOG.md
|
|
131
|
+
- LICENSE
|
|
132
|
+
- README.md
|
|
116
133
|
files:
|
|
117
134
|
- CHANGELOG.md
|
|
118
135
|
- LICENSE
|
|
@@ -129,55 +146,15 @@ files:
|
|
|
129
146
|
- lib/normalizy/filters/percent.rb
|
|
130
147
|
- lib/normalizy/filters/slug.rb
|
|
131
148
|
- lib/normalizy/filters/strip.rb
|
|
149
|
+
- lib/normalizy/filters/truncate.rb
|
|
132
150
|
- lib/normalizy/rspec/matcher.rb
|
|
133
151
|
- lib/normalizy/version.rb
|
|
134
|
-
- spec/normalizy/config/add_spec.rb
|
|
135
|
-
- spec/normalizy/config/alias_spec.rb
|
|
136
|
-
- spec/normalizy/config/default_filters_spec.rb
|
|
137
|
-
- spec/normalizy/config/initialize_spec.rb
|
|
138
|
-
- spec/normalizy/config/normalizy_aliases_spec.rb
|
|
139
|
-
- spec/normalizy/extensions/filters/date_spec.rb
|
|
140
|
-
- spec/normalizy/extensions/filters/money_spec.rb
|
|
141
|
-
- spec/normalizy/extensions/filters/number_spec.rb
|
|
142
|
-
- spec/normalizy/extensions/filters/percent_spec.rb
|
|
143
|
-
- spec/normalizy/extensions/filters/slug_spec.rb
|
|
144
|
-
- spec/normalizy/extensions/filters/strip_spec.rb
|
|
145
|
-
- spec/normalizy/extensions/model_spec.rb
|
|
146
|
-
- spec/normalizy/extensions/normalizy_rules_spec.rb
|
|
147
|
-
- spec/normalizy/filters/date_spec.rb
|
|
148
|
-
- spec/normalizy/filters/money_spec.rb
|
|
149
|
-
- spec/normalizy/filters/number_spec.rb
|
|
150
|
-
- spec/normalizy/filters/percent_spec.rb
|
|
151
|
-
- spec/normalizy/filters/slug_spec.rb
|
|
152
|
-
- spec/normalizy/filters/strip_spec.rb
|
|
153
|
-
- spec/normalizy/normalizy/configure_spec.rb
|
|
154
|
-
- spec/normalizy/rspec/matcher/description_spec.rb
|
|
155
|
-
- spec/normalizy/rspec/matcher/failure_message_spec.rb
|
|
156
|
-
- spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb
|
|
157
|
-
- spec/normalizy/rspec/matcher/from_spec.rb
|
|
158
|
-
- spec/normalizy/rspec/matcher/matches_spec.rb
|
|
159
|
-
- spec/normalizy/rspec/matcher/to_spec.rb
|
|
160
|
-
- spec/rails_helper.rb
|
|
161
|
-
- spec/support/common.rb
|
|
162
|
-
- spec/support/db/schema.rb
|
|
163
|
-
- spec/support/filters/blacklist.rb
|
|
164
|
-
- spec/support/filters/block.rb
|
|
165
|
-
- spec/support/filters/info.rb
|
|
166
|
-
- spec/support/models/alias.rb
|
|
167
|
-
- spec/support/models/match.rb
|
|
168
|
-
- spec/support/models/model.rb
|
|
169
|
-
- spec/support/models/model_date.rb
|
|
170
|
-
- spec/support/models/model_money.rb
|
|
171
|
-
- spec/support/models/model_number.rb
|
|
172
|
-
- spec/support/models/model_percent.rb
|
|
173
|
-
- spec/support/models/model_slug.rb
|
|
174
|
-
- spec/support/models/model_strip.rb
|
|
175
|
-
- spec/support/models/rule.rb
|
|
176
152
|
homepage: https://github.com/wbotelhos/normalizy
|
|
177
153
|
licenses:
|
|
178
154
|
- MIT
|
|
179
|
-
metadata:
|
|
180
|
-
|
|
155
|
+
metadata:
|
|
156
|
+
rubygems_mfa_required: 'true'
|
|
157
|
+
post_install_message:
|
|
181
158
|
rdoc_options: []
|
|
182
159
|
require_paths:
|
|
183
160
|
- lib
|
|
@@ -192,50 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
192
169
|
- !ruby/object:Gem::Version
|
|
193
170
|
version: '0'
|
|
194
171
|
requirements: []
|
|
195
|
-
rubygems_version: 3.1.
|
|
196
|
-
signing_key:
|
|
172
|
+
rubygems_version: 3.1.6
|
|
173
|
+
signing_key:
|
|
197
174
|
specification_version: 4
|
|
198
|
-
summary: Attribute normalizer for
|
|
199
|
-
test_files:
|
|
200
|
-
- spec/normalizy/filters/date_spec.rb
|
|
201
|
-
- spec/normalizy/filters/number_spec.rb
|
|
202
|
-
- spec/normalizy/filters/money_spec.rb
|
|
203
|
-
- spec/normalizy/filters/percent_spec.rb
|
|
204
|
-
- spec/normalizy/filters/slug_spec.rb
|
|
205
|
-
- spec/normalizy/filters/strip_spec.rb
|
|
206
|
-
- spec/normalizy/config/initialize_spec.rb
|
|
207
|
-
- spec/normalizy/config/normalizy_aliases_spec.rb
|
|
208
|
-
- spec/normalizy/config/alias_spec.rb
|
|
209
|
-
- spec/normalizy/config/add_spec.rb
|
|
210
|
-
- spec/normalizy/config/default_filters_spec.rb
|
|
211
|
-
- spec/normalizy/extensions/filters/date_spec.rb
|
|
212
|
-
- spec/normalizy/extensions/filters/number_spec.rb
|
|
213
|
-
- spec/normalizy/extensions/filters/money_spec.rb
|
|
214
|
-
- spec/normalizy/extensions/filters/percent_spec.rb
|
|
215
|
-
- spec/normalizy/extensions/filters/slug_spec.rb
|
|
216
|
-
- spec/normalizy/extensions/filters/strip_spec.rb
|
|
217
|
-
- spec/normalizy/extensions/normalizy_rules_spec.rb
|
|
218
|
-
- spec/normalizy/extensions/model_spec.rb
|
|
219
|
-
- spec/normalizy/normalizy/configure_spec.rb
|
|
220
|
-
- spec/normalizy/rspec/matcher/matches_spec.rb
|
|
221
|
-
- spec/normalizy/rspec/matcher/failure_message_spec.rb
|
|
222
|
-
- spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb
|
|
223
|
-
- spec/normalizy/rspec/matcher/to_spec.rb
|
|
224
|
-
- spec/normalizy/rspec/matcher/from_spec.rb
|
|
225
|
-
- spec/normalizy/rspec/matcher/description_spec.rb
|
|
226
|
-
- spec/support/filters/block.rb
|
|
227
|
-
- spec/support/filters/blacklist.rb
|
|
228
|
-
- spec/support/filters/info.rb
|
|
229
|
-
- spec/support/models/model_money.rb
|
|
230
|
-
- spec/support/models/match.rb
|
|
231
|
-
- spec/support/models/model_date.rb
|
|
232
|
-
- spec/support/models/model.rb
|
|
233
|
-
- spec/support/models/model_slug.rb
|
|
234
|
-
- spec/support/models/rule.rb
|
|
235
|
-
- spec/support/models/model_percent.rb
|
|
236
|
-
- spec/support/models/model_number.rb
|
|
237
|
-
- spec/support/models/model_strip.rb
|
|
238
|
-
- spec/support/models/alias.rb
|
|
239
|
-
- spec/support/common.rb
|
|
240
|
-
- spec/support/db/schema.rb
|
|
241
|
-
- spec/rails_helper.rb
|
|
175
|
+
summary: Attribute normalizer for Rails.
|
|
176
|
+
test_files: []
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Normalizy::Config, '#add' do
|
|
6
|
-
it 'adds filters to the built-in filters' do
|
|
7
|
-
Normalizy.configure do |config|
|
|
8
|
-
config.add :blacklist, :blacklist_filter
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
expect(Normalizy.config.filters).to eq(
|
|
12
|
-
blacklist: :blacklist_filter,
|
|
13
|
-
date: Normalizy::Filters::Date,
|
|
14
|
-
money: Normalizy::Filters::Money,
|
|
15
|
-
number: Normalizy::Filters::Number,
|
|
16
|
-
percent: Normalizy::Filters::Percent,
|
|
17
|
-
slug: Normalizy::Filters::Slug,
|
|
18
|
-
strip: Normalizy::Filters::Strip
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Normalizy::Config, '#alias' do
|
|
6
|
-
it 'accepts alias' do
|
|
7
|
-
Normalizy.configure do |config|
|
|
8
|
-
config.alias :email, :downcase
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
expect(Alias.create(email: 'Botelho').email).to eq 'botelho'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'accepts alias with options' do
|
|
15
|
-
Normalizy.configure do |config|
|
|
16
|
-
config.alias :with_arg, strip: { side: :left }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
expect(Alias.create(with_arg_field: ' trim').with_arg_field).to eq 'trim'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'accepts late options' do
|
|
23
|
-
Normalizy.configure do |config|
|
|
24
|
-
config.alias :with_inline_arg, :strip
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
expect(Alias.create(with_inline_arg_field: ' trim').with_inline_arg_field).to eq 'trim'
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Normalizy::Config, 'default_filters' do
|
|
6
|
-
context 'when get' do
|
|
7
|
-
it 'returns the default filters' do
|
|
8
|
-
expect(subject.default_filters).to eq({})
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context 'when set' do
|
|
13
|
-
before { subject.default_filters = :blank }
|
|
14
|
-
|
|
15
|
-
it 'keeps the original' do
|
|
16
|
-
expect(subject.default_filters).to eq :blank
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe Normalizy::Config, 'filters' do
|
|
6
|
-
it 'loads some filters' do
|
|
7
|
-
expect(subject.filters).to eq(
|
|
8
|
-
date: Normalizy::Filters::Date,
|
|
9
|
-
money: Normalizy::Filters::Money,
|
|
10
|
-
number: Normalizy::Filters::Number,
|
|
11
|
-
percent: Normalizy::Filters::Percent,
|
|
12
|
-
slug: Normalizy::Filters::Slug,
|
|
13
|
-
strip: Normalizy::Filters::Strip
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe ModelDate, 'filters:date' do
|
|
6
|
-
it { expect(described_class.create(date: '1984-10-23').date).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) }
|
|
7
|
-
it { expect(described_class.create(date_format: '84/10/23').date_format).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) }
|
|
8
|
-
|
|
9
|
-
it do
|
|
10
|
-
hours = ActiveSupport::TimeZone['Brasilia'].utc_offset / 3600.0
|
|
11
|
-
expected = Time.new(1984, 10, 23, 0, 0, 0, 0) + (hours.hours * -1)
|
|
12
|
-
|
|
13
|
-
expect(described_class.create(date_time_zone: '1984-10-23').date_time_zone).to eq expected
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'normalizys end date' do
|
|
17
|
-
expect(described_class.new(date_time_end: Date.new(1984)).date_time_end).to eq(Time.new(1984).end_of_day)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'normalizys begin date' do
|
|
21
|
-
expect(described_class.new(date_time_begin: Date.new(1984, 10, 23)).date_time_begin).to eq(Time.new(1984, 10, 23))
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
|
|
5
|
-
RSpec.describe ModelMoney, 'filters:money' do
|
|
6
|
-
it do
|
|
7
|
-
expect(described_class.create(text: '$ 42.00').text).to eq '42.00'
|
|
8
|
-
expect(described_class.create(text: '$ 42.10').text).to eq '42.10'
|
|
9
|
-
|
|
10
|
-
expect(described_class.create(text: '$ -42.00').text).to eq '-42.00'
|
|
11
|
-
expect(described_class.create(text: '$ -42.10').text).to eq '-42.10'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it do
|
|
15
|
-
expect(described_class.create(cents_type: '$ 42.33').cents_type).to eq '4233'
|
|
16
|
-
expect(described_class.create(cents_type: '$ -42.33').cents_type).to eq '-4233'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it do
|
|
20
|
-
expect(described_class.create(cast_to_i: '$ 42.00').cast_to_i).to be 42
|
|
21
|
-
expect(described_class.create(cast_to_i: '$ -42.00').cast_to_i).to be -42
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it do
|
|
25
|
-
expect(described_class.create(cast_to_d: '$ 1.23').cast_to_d).to eq 1.23
|
|
26
|
-
expect(described_class.create(cast_to_d: '$ -1.23').cast_to_d).to eq -1.23
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it do
|
|
30
|
-
expect(described_class.create(cents_type_and_cast_to_f: '$ 42.00').cents_type_and_cast_to_f).to eq 4200.0
|
|
31
|
-
expect(described_class.create(cents_type_and_cast_to_f: '$ -42.00').cents_type_and_cast_to_f).to eq -4200.0
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it do
|
|
35
|
-
expect(described_class.create(cents_type_and_cast_to_i: '$ 42.00').cents_type_and_cast_to_i).to eq 4200
|
|
36
|
-
expect(described_class.create(cents_type_and_cast_to_i: '$ -42.00').cents_type_and_cast_to_i).to eq -4200
|
|
37
|
-
end
|
|
38
|
-
end
|