normalizy 1.5.0 → 1.6.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -28
  3. data/README.md +22 -16
  4. data/lib/normalizy/filters/money.rb +2 -2
  5. data/lib/normalizy/filters/percent.rb +2 -2
  6. data/lib/normalizy/version.rb +1 -1
  7. metadata +27 -94
  8. data/spec/normalizy/config/add_spec.rb +0 -21
  9. data/spec/normalizy/config/alias_spec.rb +0 -29
  10. data/spec/normalizy/config/default_filters_spec.rb +0 -19
  11. data/spec/normalizy/config/initialize_spec.rb +0 -16
  12. data/spec/normalizy/config/normalizy_aliases_spec.rb +0 -9
  13. data/spec/normalizy/extensions/filters/date_spec.rb +0 -23
  14. data/spec/normalizy/extensions/filters/money_spec.rb +0 -38
  15. data/spec/normalizy/extensions/filters/number_spec.rb +0 -9
  16. data/spec/normalizy/extensions/filters/percent_spec.rb +0 -30
  17. data/spec/normalizy/extensions/filters/slug_spec.rb +0 -14
  18. data/spec/normalizy/extensions/filters/strip_spec.rb +0 -21
  19. data/spec/normalizy/extensions/model_spec.rb +0 -107
  20. data/spec/normalizy/extensions/normalizy_rules_spec.rb +0 -198
  21. data/spec/normalizy/filters/date_spec.rb +0 -72
  22. data/spec/normalizy/filters/money_spec.rb +0 -282
  23. data/spec/normalizy/filters/number_spec.rb +0 -33
  24. data/spec/normalizy/filters/percent_spec.rb +0 -168
  25. data/spec/normalizy/filters/slug_spec.rb +0 -24
  26. data/spec/normalizy/filters/strip_spec.rb +0 -13
  27. data/spec/normalizy/normalizy/configure_spec.rb +0 -11
  28. data/spec/normalizy/rspec/matcher/description_spec.rb +0 -27
  29. data/spec/normalizy/rspec/matcher/failure_message_spec.rb +0 -48
  30. data/spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb +0 -30
  31. data/spec/normalizy/rspec/matcher/from_spec.rb +0 -19
  32. data/spec/normalizy/rspec/matcher/matches_spec.rb +0 -117
  33. data/spec/normalizy/rspec/matcher/to_spec.rb +0 -19
  34. data/spec/rails_helper.rb +0 -9
  35. data/spec/support/common.rb +0 -11
  36. data/spec/support/db/schema.rb +0 -83
  37. data/spec/support/filters/blacklist.rb +0 -11
  38. data/spec/support/filters/block.rb +0 -11
  39. data/spec/support/filters/info.rb +0 -11
  40. data/spec/support/models/alias.rb +0 -7
  41. data/spec/support/models/match.rb +0 -9
  42. data/spec/support/models/model.rb +0 -28
  43. data/spec/support/models/model_date.rb +0 -9
  44. data/spec/support/models/model_money.rb +0 -10
  45. data/spec/support/models/model_number.rb +0 -5
  46. data/spec/support/models/model_percent.rb +0 -10
  47. data/spec/support/models/model_slug.rb +0 -6
  48. data/spec/support/models/model_strip.rb +0 -8
  49. data/spec/support/models/rule.rb +0 -4
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Number do
6
- context 'with no cast' do
7
- it { expect(subject.call('abcdefghijklmnopkrstuvxyz')).to eq nil }
8
- it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ')).to eq nil }
9
- it { expect(subject.call('áéíóúàâêôãõ')).to eq nil }
10
- it { expect(subject.call('0123456789')).to eq '0123456789' }
11
- it { expect(subject.call('012345x6789')).to eq '0123456789' }
12
- it { expect(subject.call("\n")).to eq nil }
13
- it { expect(subject.call(42)).to eq 42 }
14
- it { expect(subject.call(nil)).to eq nil }
15
- it { expect(subject.call('nil')).to eq nil }
16
- it { expect(subject.call('')).to eq nil }
17
- it { expect(subject.call('1 2 3')).to eq '123' }
18
- end
19
-
20
- context 'with :cast' do
21
- it { expect(subject.call('abcdefghijklmnopkrstuvxyz', cast: :to_i)).to eq nil }
22
- it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ', cast: :to_i)).to eq nil }
23
- it { expect(subject.call('áéíóúàâêôãõ', cast: :to_i)).to eq nil }
24
- it { expect(subject.call('0123456789', cast: :to_i)).to eq 123_456_789 }
25
- it { expect(subject.call('012345x6789', cast: :to_i)).to eq 123_456_789 }
26
- it { expect(subject.call("\n", cast: :to_i)).to eq nil }
27
- it { expect(subject.call(42, cast: :to_i)).to eq 42 }
28
- it { expect(subject.call(nil, cast: :to_i)).to eq nil }
29
- it { expect(subject.call('nil', cast: :to_i)).to eq nil }
30
- it { expect(subject.call('', cast: :to_i)).to eq nil }
31
- it { expect(subject.call('1 2 3', cast: :to_i)).to eq 123 }
32
- end
33
- end
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Percent do
6
- describe 'default options' do
7
- it { expect(subject.call('')).to eq nil }
8
-
9
- it { expect(subject.call(1)).to be 1 }
10
- it { expect(subject.call(1.70)).to be 1.70 }
11
- it { expect(subject.call(103.70)).to be 103.70 }
12
- it { expect(subject.call(1030.70)).to be 1030.70 }
13
- it { expect(subject.call(10_300.70)).to be 10_300.70 }
14
-
15
- it { expect(subject.call('0')).to eq '0.00' }
16
- it { expect(subject.call('100')).to eq '100.00' }
17
- it { expect(subject.call('100.0')).to eq '100.00' }
18
- it { expect(subject.call('1.70')).to eq '1.70' }
19
- it { expect(subject.call('103.70')).to eq '103.70' }
20
- it { expect(subject.call('1030.70')).to eq '1030.70' }
21
- it { expect(subject.call('10300.70')).to eq '10300.70' }
22
-
23
- it { expect(subject.call('$ 0.01')).to eq '0.01' }
24
- it { expect(subject.call('$ 1')).to eq '1.00' }
25
- it { expect(subject.call('$ 1.70')).to eq '1.70' }
26
- it { expect(subject.call('$ 103.70')).to eq '103.70' }
27
- it { expect(subject.call('$ 1030.70')).to eq '1030.70' }
28
- it { expect(subject.call('$ 10300.70')).to eq '10300.70' }
29
- end
30
-
31
- describe 'type' do
32
- it { expect(subject.call('', type: :cents)).to eq nil }
33
-
34
- it { expect(subject.call(1 , type: :cents)).to be 1 }
35
- it { expect(subject.call(1.70 , type: :cents)).to be 1.70 }
36
- it { expect(subject.call(103.70 , type: :cents)).to be 103.70 }
37
- it { expect(subject.call(1030.70 , type: :cents)).to be 1030.70 }
38
- it { expect(subject.call(10_300.70, type: :cents)).to be 10_300.70 }
39
-
40
- context 'with different separator' do
41
- it { expect(subject.call('1,7', separator: ',', type: :cents)).to eq '170' }
42
- end
43
-
44
- context 'with no decimal precision' do
45
- it { expect(subject.call('1' , type: :cents)).to eq '1' }
46
- it { expect(subject.call('10' , type: :cents)).to eq '10' }
47
- it { expect(subject.call('100', type: :cents)).to eq '100' }
48
-
49
- context 'with float :cast' do
50
- it { expect(subject.call('1' , cast: :to_f, type: :cents)).to eq 1.0 }
51
- it { expect(subject.call('10' , cast: :to_f, type: :cents)).to eq 10.0 }
52
- it { expect(subject.call('100', cast: :to_f, type: :cents)).to eq 100.0 }
53
- end
54
- end
55
-
56
- context 'with one decimal precision' do
57
- it { expect(subject.call('1.7' , type: :cents)).to eq '170' }
58
- it { expect(subject.call('103.7' , type: :cents)).to eq '10370' }
59
- it { expect(subject.call('1030.7' , type: :cents)).to eq '103070' }
60
- it { expect(subject.call('10300.7', type: :cents)).to eq '1030070' }
61
-
62
- it { expect(subject.call('$ 1.7' , type: :cents)).to eq '170' }
63
- it { expect(subject.call('$ 103.7' , type: :cents)).to eq '10370' }
64
- it { expect(subject.call('$ 1030.7' , type: :cents)).to eq '103070' }
65
- it { expect(subject.call('$ 10300.7', type: :cents)).to eq '1030070' }
66
-
67
- context 'with float :cast' do
68
- it { expect(subject.call('1.7' , cast: :to_f, type: :cents)).to be 170.0 }
69
- it { expect(subject.call('103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
70
- it { expect(subject.call('1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
71
- it { expect(subject.call('10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
72
-
73
- it { expect(subject.call('$ 1.7' , cast: :to_f, type: :cents)).to be 170.0 }
74
- it { expect(subject.call('$ 103.7' , cast: :to_f, type: :cents)).to be 10_370.0 }
75
- it { expect(subject.call('$ 1030.7' , cast: :to_f, type: :cents)).to be 103_070.0 }
76
- it { expect(subject.call('$ 10300.7', cast: :to_f, type: :cents)).to be 1_030_070.0 }
77
- end
78
- end
79
-
80
- context 'with two decimal precision' do
81
- it { expect(subject.call('1.70' , type: :cents)).to eq '170' }
82
- it { expect(subject.call('103.70' , type: :cents)).to eq '10370' }
83
- it { expect(subject.call('1030.70' , type: :cents)).to eq '103070' }
84
- it { expect(subject.call('10300.70', type: :cents)).to eq '1030070' }
85
-
86
- it { expect(subject.call('$ 1.70' , type: :cents)).to eq '170' }
87
- it { expect(subject.call('$ 103.70' , type: :cents)).to eq '10370' }
88
- it { expect(subject.call('$ 1030.70' , type: :cents)).to eq '103070' }
89
- it { expect(subject.call('$ 10300.70', type: :cents)).to eq '1030070' }
90
-
91
- context 'with float :cast' do
92
- it { expect(subject.call('1.70' , cast: :to_f, type: :cents)).to be 170.0 }
93
- it { expect(subject.call('103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
94
- it { expect(subject.call('1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
95
- it { expect(subject.call('10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
96
-
97
- it { expect(subject.call('$ 1.70' , cast: :to_f, type: :cents)).to be 170.0 }
98
- it { expect(subject.call('$ 103.70' , cast: :to_f, type: :cents)).to be 10_370.0 }
99
- it { expect(subject.call('$ 1030.70' , cast: :to_f, type: :cents)).to be 103_070.0 }
100
- it { expect(subject.call('$ 10300.70', cast: :to_f, type: :cents)).to be 1_030_070.0 }
101
- end
102
- end
103
- end
104
-
105
- describe 'separator' do
106
- context 'when provided inline' do
107
- it { expect(subject.call('R$ 0,01', separator: ',')).to eq '0.01' }
108
- end
109
-
110
- context 'when provided I18n' do
111
- before do
112
- allow(I18n).to receive(:t).with('percentage.format.separator', default: '.').and_return 'x'
113
- allow(I18n).to receive(:t).with('percentage.format.precision', default: 2).and_return 2
114
- end
115
-
116
- it { expect(subject.call('1x2')).to eq '1.20' }
117
- end
118
-
119
- context 'when not provided' do
120
- it { expect(subject.call('1.2')).to eq '1.20' }
121
- end
122
- end
123
-
124
- describe 'cast' do
125
- context 'with no decimal precision' do
126
- it { expect(subject.call('1' , cast: :to_f)).to eq 1.0 }
127
- it { expect(subject.call('10' , cast: :to_f)).to eq 10.0 }
128
- it { expect(subject.call('100', cast: :to_f)).to eq 100.0 }
129
- end
130
-
131
- context 'when value has one decimal precision' do
132
- it { expect(subject.call('1.7' , cast: :to_f)).to eq 1.7 }
133
- it { expect(subject.call('103.7' , cast: :to_f)).to eq 103.7 }
134
- it { expect(subject.call('1030.7' , cast: :to_f)).to eq 1030.7 }
135
- it { expect(subject.call('10300.7', cast: :to_f)).to eq 10_300.7 }
136
-
137
- it { expect(subject.call('$ 1.7' , cast: :to_f)).to eq 1.7 }
138
- it { expect(subject.call('$ 103.7' , cast: :to_f)).to eq 103.7 }
139
- it { expect(subject.call('$ 1030.7' , cast: :to_f)).to eq 1030.7 }
140
- it { expect(subject.call('$ 10300.7', cast: :to_f)).to eq 10_300.7 }
141
-
142
- context 'with calls cast' do
143
- it { expect(subject.call('1.7' , cast: :to_f)).to be 1.7 }
144
- it { expect(subject.call('103.7' , cast: :to_f)).to be 103.7 }
145
- it { expect(subject.call('1030.7' , cast: :to_f)).to be 1030.7 }
146
- it { expect(subject.call('10300.7', cast: :to_f)).to be 10_300.7 }
147
-
148
- it { expect(subject.call('$ 1.7' , cast: :to_f)).to be 1.7 }
149
- it { expect(subject.call('$ 103.7' , cast: :to_f)).to be 103.7 }
150
- it { expect(subject.call('$ 1030.7' , cast: :to_f)).to be 1030.7 }
151
- it { expect(subject.call('$ 10300.7', cast: :to_f)).to be 10_300.7 }
152
- end
153
- end
154
-
155
- context 'when value has two decimal precision' do
156
- it { expect(subject.call('1.70' , cast: :to_f)).to be 1.7 }
157
- it { expect(subject.call('103.70' , cast: :to_f)).to be 103.7 }
158
- it { expect(subject.call('1030.70' , cast: :to_f)).to be 1030.7 }
159
- it { expect(subject.call('10300.70', cast: :to_f)).to be 10_300.7 }
160
-
161
- it { expect(subject.call('$ 1' , cast: :to_f)).to be 1.0 }
162
- it { expect(subject.call('$ 1.70' , cast: :to_f)).to be 1.7 }
163
- it { expect(subject.call('$ 103.70' , cast: :to_f)).to be 103.7 }
164
- it { expect(subject.call('$ 1030.70' , cast: :to_f)).to be 1030.7 }
165
- it { expect(subject.call('$ 10300.70', cast: :to_f)).to be 10_300.7 }
166
- end
167
- end
168
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Slug do
6
- describe 'default options' do
7
- it { expect(subject.call(nil)).to eq nil }
8
- it { expect(subject.call('')).to eq '' }
9
-
10
- it { expect(subject.call('The Title')).to eq 'the-title' }
11
- end
12
-
13
- describe 'to' do
14
- it { expect(subject.call(nil , to: :slug)).to eq nil }
15
- it { expect(subject.call('' , to: :slug)).to eq '' }
16
- it { expect(subject.call('The Title', to: :slug)).to eq 'the-title' }
17
-
18
- context 'when is not :to key' do
19
- it { expect(subject.call(nil , from: :slug)).to eq nil }
20
- it { expect(subject.call('' , from: :slug)).to eq '' }
21
- it { expect(subject.call('The Title', from: :slug)).to eq 'the-title' }
22
- end
23
- end
24
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::Filters::Strip do
6
- it { expect(subject.call(' Some Text ')).to eq 'Some Text' }
7
- it { expect(subject.call(' Some Text ', side: :left)).to eq 'Some Text ' }
8
- it { expect(subject.call(' Some Text ', side: :right)).to eq ' Some Text' }
9
- it { expect(subject.call(' Some Text ', side: :both)).to eq 'Some Text' }
10
- it { expect(subject.call("\n")).to eq '' }
11
- it { expect(subject.call(42)).to eq 42 }
12
- it { expect(subject.call(nil)).to eq nil }
13
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy, '#configure' do
6
- it 'yields the default config' do
7
- described_class.configure do |conf|
8
- expect(conf).to be_a_instance_of Normalizy::Config
9
- end
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.description' do
6
- let!(:matcher) { described_class.new :name }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher.from :from
11
- matcher.to :to
12
-
13
- expect(matcher.description).to eq 'normalizy name from "from" to "to"'
14
- end
15
- end
16
-
17
- context 'with :with expectation' do
18
- it do
19
- matcher.with :blank
20
-
21
- matcher.from :from
22
- matcher.to :to
23
-
24
- expect(matcher.description).to eq 'normalizy name with blank'
25
- end
26
- end
27
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.failure_message' do
6
- let!(:model) { Match }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher = described_class.new(:downcase_field)
11
-
12
- matcher.from :from
13
- matcher.to :to
14
- matcher.matches? model.new
15
-
16
- expect(matcher.failure_message).to eq %(expected: "to"\n got: "from")
17
- end
18
- end
19
-
20
- context 'with :with expectation' do
21
- it do
22
- matcher = described_class.new(:alone)
23
-
24
- matcher.with :missing
25
- matcher.matches? model.new
26
-
27
- expect(matcher.failure_message).to eq %(expected: missing\n got: nil)
28
- end
29
-
30
- it do
31
- matcher = described_class.new(:downcase_field_array)
32
-
33
- matcher.with :missing
34
- matcher.matches? model.new
35
-
36
- expect(matcher.failure_message).to eq %(expected: missing\n got: downcase)
37
- end
38
-
39
- it do
40
- matcher = described_class.new(:trim_side_left)
41
-
42
- matcher.with :missing
43
- matcher.matches? model.new
44
-
45
- expect(matcher.failure_message).to eq %(expected: missing\n got: {:trim=>{:side=>:left}})
46
- end
47
- end
48
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.failure_message_when_negated' do
6
- let!(:model) { Match }
7
-
8
- context 'with no :with expectation' do
9
- it do
10
- matcher = described_class.new(:downcase_field)
11
-
12
- matcher.from 'from'
13
- matcher.to 'from'
14
- matcher.matches? model.new
15
-
16
- expect(matcher.failure_message_when_negated).to eq %(expected: value != "from"\n got: "from")
17
- end
18
- end
19
-
20
- context 'with :with expectation' do
21
- it do
22
- matcher = described_class.new(:downcase_field)
23
-
24
- matcher.with :downcase
25
- matcher.matches? model.new
26
-
27
- expect(matcher.failure_message_when_negated).to eq %(expected: value != downcase\n got: downcase)
28
- end
29
- end
30
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.from' do
6
- it 'caches the value' do
7
- matcher = described_class.new(:downcase_field)
8
-
9
- matcher.from :from
10
-
11
- expect(matcher.instance_variable_get(:@from)).to eq :from
12
- end
13
-
14
- it 'returns it self' do
15
- matcher = described_class.new(:downcase_field)
16
-
17
- expect(matcher.from(:from)).to be matcher
18
- end
19
- end
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.matches?' do
6
- let!(:object) { Match.new }
7
-
8
- it do
9
- matcher = described_class.new(:alone)
10
-
11
- matcher.matches?(object)
12
-
13
- expect(matcher.instance_variable_get(:@subject)).to eq object
14
- end
15
-
16
- context 'when .with is called' do
17
- it do
18
- matcher = described_class.new(:alone)
19
-
20
- matcher.with :missing
21
-
22
- expect(matcher.matches?(object)).to eq false
23
- end
24
-
25
- it do
26
- matcher = described_class.new(:downcase_field)
27
-
28
- matcher.with :downcase
29
-
30
- expect(matcher.matches?(object)).to eq true
31
- end
32
-
33
- it do
34
- matcher = described_class.new(:trim_side_left)
35
-
36
- matcher.with trim: { side: :left }
37
-
38
- expect(matcher.matches?(object)).to eq true
39
- end
40
-
41
- it do
42
- matcher = described_class.new(:trim_side_left_array)
43
-
44
- matcher.with trim: { side: :left }
45
-
46
- expect(matcher.matches?(object)).to eq true
47
- end
48
-
49
- it do
50
- Normalizy.configure do |config|
51
- config.default_filters = :squish
52
- end
53
-
54
- matcher = described_class.new(:alone)
55
-
56
- matcher.with :squish
57
-
58
- expect(matcher.matches?(object)).to eq true
59
- end
60
-
61
- it do
62
- Normalizy.configure do |config|
63
- config.default_filters = [:squish]
64
- end
65
-
66
- matcher = described_class.new(:alone)
67
-
68
- matcher.with :squish
69
-
70
- expect(matcher.matches?(object)).to eq true
71
- end
72
-
73
- it do
74
- Normalizy.configure do |config|
75
- config.default_filters = [{ strip: { side: :left } }]
76
- end
77
-
78
- matcher = described_class.new(:alone)
79
-
80
- matcher.with(strip: { side: :left })
81
-
82
- expect(matcher.matches?(object)).to eq true
83
- end
84
-
85
- it 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
96
- end
97
-
98
- context 'when .with is not called' do
99
- it do
100
- matcher = described_class.new(:alone)
101
-
102
- matcher.from '1'
103
- matcher.to '2'
104
-
105
- expect(matcher.matches?(object)).to eq false
106
- end
107
-
108
- it do
109
- matcher = described_class.new(:downcase_field)
110
-
111
- matcher.from 'BOTELHO'
112
- matcher.to 'botelho'
113
-
114
- expect(matcher.matches?(object)).to eq true
115
- end
116
- end
117
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Normalizy::RSpec::Matcher, '.to' do
6
- it 'caches the value' do
7
- matcher = described_class.new(:downcase)
8
-
9
- matcher.to :to
10
-
11
- expect(matcher.instance_variable_get(:@to)).to eq :to
12
- end
13
-
14
- it 'returns it self' do
15
- matcher = described_class.new(:downcase)
16
-
17
- expect(matcher.to(:to)).to be matcher
18
- end
19
- end
data/spec/rails_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ENV['RAILS_ENV'] ||= 'test'
4
-
5
- require 'active_record/railtie'
6
- require 'normalizy'
7
- require 'pry-byebug'
8
-
9
- Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rspec/rails'
4
-
5
- RSpec.configure do |config|
6
- config.filter_run_when_matching :focus
7
-
8
- config.disable_monkey_patching!
9
-
10
- config.order = :random
11
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
4
-
5
- ActiveRecord::Schema.define(version: 0) do
6
- create_table :aliases do |t|
7
- t.string :email
8
- t.string :with_arg_field
9
- t.string :with_inline_arg_field
10
- end
11
-
12
- create_table :matches do |t|
13
- t.string :alone
14
- t.string :downcase_field
15
- t.string :trim_side_left
16
- t.string :downcase_field_array
17
- end
18
-
19
- create_table :models do |t|
20
- t.string :none
21
- t.string :default
22
- t.string :block
23
- t.string :symbol
24
- t.string :array_symbol
25
- t.string :array_symbols
26
- t.string :hash_no_args
27
- t.string :hash_with_args
28
- t.string :module_one_arg
29
- t.string :module_two_args
30
- t.string :module_and_block
31
- t.string :method_with_no_options_field
32
- t.string :method_with_options_field
33
- t.string :native
34
- t.string :multiple
35
- end
36
-
37
- create_table :model_dates do |t|
38
- t.datetime :date
39
- t.datetime :date_format
40
- t.datetime :date_time_begin
41
- t.datetime :date_time_end
42
- t.datetime :date_time_zone
43
- end
44
-
45
- create_table :model_moneys do |t|
46
- t.string :text
47
- t.string :cents_type
48
- t.integer :cast_to_i
49
- t.decimal :cast_to_d
50
- t.float :cents_type_and_cast_to_f
51
- t.integer :cents_type_and_cast_to_i
52
- end
53
-
54
- create_table :model_numbers do |t|
55
- t.string :number
56
- end
57
-
58
- create_table :model_percents do |t|
59
- t.string :text
60
- t.string :cents_type
61
- t.integer :cast_to_i
62
- t.decimal :cast_to_d
63
- t.float :cents_type_and_cast_to_f
64
- t.integer :cents_type_and_cast_to_i
65
- end
66
-
67
- create_table :model_slugs do |t|
68
- t.string :permalink
69
- t.string :slug
70
- t.string :title
71
- end
72
-
73
- create_table :model_strips do |t|
74
- t.string :strip
75
- t.string :strip_side_both
76
- t.string :strip_side_left
77
- t.string :strip_side_right
78
- end
79
-
80
- create_table :rules do |t|
81
- t.string :name
82
- end
83
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Blacklist
6
- def self.call(input)
7
- input.gsub 'Fuck', 'filtered'
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Block
6
- def self.call(input)
7
- yield input
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Normalizy
4
- module Filters
5
- module Info
6
- def self.call(input, options = {})
7
- [options[:attribute], input, options[:object].class].join ', '
8
- end
9
- end
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Alias < ActiveRecord::Base
4
- normalizy :email , with: :email
5
- normalizy :with_arg_field , with: :with_arg
6
- normalizy :with_inline_arg_field, with: { with_inline_arg: { side: :left } }
7
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Match < ActiveRecord::Base
4
- normalizy :alone
5
- normalizy :downcase_field , with: :downcase
6
- normalizy :trim_side_left , with: { trim: { side: :left } }
7
- normalizy :trim_side_left_array, with: [{ trim: { side: :left } }]
8
- normalizy :downcase_field_array, with: [:downcase]
9
- end