normatron 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +131 -125
- data/lib/normatron.rb +3 -2
- data/lib/normatron/configuration.rb +24 -3
- data/lib/normatron/extensions/active_record.rb +40 -28
- data/lib/normatron/filters.rb +254 -6
- data/spec/configuration_spec.rb +53 -0
- data/spec/extensions/active_record_spec.rb +114 -0
- data/spec/filters_spec.rb +199 -0
- data/spec/normatron_spec.rb +18 -0
- data/spec/spec_helper.rb +0 -3
- data/spec/support/model_model.rb +3 -0
- data/spec/support/schema.rb +4 -7
- metadata +12 -18
- data/lib/normatron/filters/conversions.rb +0 -29
- data/lib/normatron/filters/string_inflections.rb +0 -155
- data/spec/lib/normatron/configuration_spec.rb +0 -45
- data/spec/lib/normatron/extensions/active_record_spec.rb +0 -147
- data/spec/lib/normatron/filters/conversions_spec.rb +0 -40
- data/spec/lib/normatron/filters/string_inflections_spec.rb +0 -268
- data/spec/lib/normatron/filters_spec.rb +0 -22
- data/spec/lib/normatron_spec.rb +0 -22
- data/spec/support/client_model.rb +0 -3
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Normatron::Filters::Conversions do
|
5
|
-
|
6
|
-
let(:mod) { Normatron::Filters::Conversions }
|
7
|
-
let(:val) { @value }
|
8
|
-
|
9
|
-
describe :blank do
|
10
|
-
it "should return nil for empty strings" do
|
11
|
-
value = ""
|
12
|
-
mod.blank(value).should be_nil
|
13
|
-
mod.blank(value.mb_chars).should be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return nil for blank spaces strings" do
|
17
|
-
value = " "
|
18
|
-
mod.blank(value).should be_nil
|
19
|
-
mod.blank(value.mb_chars).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should return nil for \n \t \r \f strings' do
|
23
|
-
value = "\n \t \r \f"
|
24
|
-
mod.blank(value).should be_nil
|
25
|
-
mod.blank(value.mb_chars).should be_nil
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should not affect filled string" do
|
29
|
-
value = "baCon"
|
30
|
-
expected = "baCon"
|
31
|
-
mod.blank(value).should eq expected
|
32
|
-
mod.blank(value.mb_chars).should eq expected.mb_chars
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should not affect non string objects" do
|
36
|
-
mod.blank(nil).should eq nil
|
37
|
-
mod.blank(1).should eq 1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,268 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Normatron::Filters::StringInflections do
|
5
|
-
|
6
|
-
let(:mod) { Normatron::Filters::StringInflections }
|
7
|
-
let(:val) { @value }
|
8
|
-
|
9
|
-
describe :alphas do
|
10
|
-
it "should remove the number and space" do
|
11
|
-
value = "Doom 3"
|
12
|
-
expected = "Doom"
|
13
|
-
mod.alphas(value).should eq expected
|
14
|
-
mod.alphas(value.mb_chars).should eq expected.mb_chars
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should remove line break" do
|
18
|
-
value = " \n "
|
19
|
-
expected = ""
|
20
|
-
mod.alphas(value).should eq expected
|
21
|
-
mod.alphas(value.mb_chars).should eq expected.mb_chars
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should not affect non string objects" do
|
25
|
-
mod.alphas(nil).should eq nil
|
26
|
-
mod.alphas(1).should eq 1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe :capitalize do
|
31
|
-
it "should upcase first char and downcase others" do
|
32
|
-
value = "mASTER OF PUPPETS"
|
33
|
-
expected = "Master of puppets"
|
34
|
-
mod.capitalize(value).should eq expected
|
35
|
-
mod.capitalize(value.mb_chars).should eq expected.mb_chars
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should downcase all chars in string starting with spaces" do
|
39
|
-
value = " mASTER OF PUPPETS"
|
40
|
-
expected = " master of puppets"
|
41
|
-
mod.capitalize(value).should eq expected
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should affect accented chars" do
|
45
|
-
value = "ILÍADA"
|
46
|
-
expected = "Ilíada"
|
47
|
-
mod.capitalize(value).should eq expected
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should not affect non string objects" do
|
51
|
-
mod.capitalize(nil).should eq nil
|
52
|
-
mod.capitalize(1).should eq 1
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe :dasherize do
|
57
|
-
it "should replaces underscores with dashes" do
|
58
|
-
value = "__ shoot _ to _ thrill __"
|
59
|
-
expected = "-- shoot - to - thrill --"
|
60
|
-
mod.dasherize(value).should eq expected
|
61
|
-
mod.dasherize(value.mb_chars).should eq expected.mb_chars
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not affect non string objects" do
|
65
|
-
mod.dasherize(nil).should eq nil
|
66
|
-
mod.dasherize(1).should eq 1
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe :digits do
|
71
|
-
it "should remove non digit characters" do
|
72
|
-
value = "Quake 3"
|
73
|
-
expected = "3"
|
74
|
-
mod.digits(value).should eq expected
|
75
|
-
mod.digits(value.mb_chars).should eq expected.mb_chars
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not affect non string objects" do
|
79
|
-
mod.digits(nil).should eq nil
|
80
|
-
mod.digits(1).should eq 1
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe :downcase do
|
85
|
-
it "should downcase all characters" do
|
86
|
-
value = "KILL'EM ALL"
|
87
|
-
expected = "kill'em all"
|
88
|
-
mod.downcase(value).should eq expected
|
89
|
-
mod.downcase(value.mb_chars).should eq expected.mb_chars
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should affect accented chars" do
|
93
|
-
value = "ÊXITO"
|
94
|
-
expected = "êxito"
|
95
|
-
mod.downcase(value).should eq expected
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should not affect non string objects" do
|
99
|
-
mod.downcase(nil).should eq nil
|
100
|
-
mod.downcase(1).should eq 1
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe :lstrip do
|
105
|
-
it "should remove trailing spaces" do
|
106
|
-
value = " black "
|
107
|
-
expected = "black "
|
108
|
-
mod.lstrip(value).should eq expected
|
109
|
-
mod.lstrip(value.mb_chars).should eq expected.mb_chars
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should not affect non string objects" do
|
113
|
-
mod.lstrip(nil).should eq nil
|
114
|
-
mod.lstrip(1).should eq 1
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe :rstrip do
|
119
|
-
it "should remove leading spaces" do
|
120
|
-
value = " load "
|
121
|
-
expected = " load"
|
122
|
-
mod.rstrip(value).should eq expected
|
123
|
-
mod.rstrip(value.mb_chars).should eq expected.mb_chars
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should not affect non string objects" do
|
127
|
-
mod.rstrip(nil).should eq nil
|
128
|
-
mod.rstrip(1).should eq 1
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe :squeeze do
|
133
|
-
it "should replace multiple occurrences of a char for a single one" do
|
134
|
-
value = "rock'n roll \n\n ain't noise pollution"
|
135
|
-
expected = "rock'n rol \n ain't noise polution"
|
136
|
-
mod.squeeze(value).should eq expected
|
137
|
-
mod.squeeze(value.mb_chars).should eq expected.mb_chars
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not affect non string objects" do
|
141
|
-
mod.squeeze(nil).should eq nil
|
142
|
-
mod.squeeze(1).should eq 1
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe :squish do
|
147
|
-
it "should remove trailing and leading spaces" do
|
148
|
-
value = " and justice for all... "
|
149
|
-
expected = "and justice for all..."
|
150
|
-
mod.squish(value).should eq expected
|
151
|
-
mod.squish(value.mb_chars).should eq expected.mb_chars
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should remove multiple spaces" do
|
155
|
-
value = "and justice for all..."
|
156
|
-
expected = "and justice for all..."
|
157
|
-
mod.squish(value).should eq expected
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should remove \n \r \f \t' do
|
161
|
-
value = "\tand\njustice\rfor\fall..."
|
162
|
-
expected = "and justice for all..."
|
163
|
-
mod.squish(value).should eq expected
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should not affect non string objects" do
|
167
|
-
mod.squish(nil).should eq nil
|
168
|
-
mod.squish(1).should eq 1
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe :strip do
|
173
|
-
it "should remove trailing and leading spaces" do
|
174
|
-
value = " reload "
|
175
|
-
expected = "reload"
|
176
|
-
mod.strip(value).should eq expected
|
177
|
-
mod.strip(value.mb_chars).should eq expected.mb_chars
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should not affect non string objects" do
|
181
|
-
mod.strip(nil).should eq nil
|
182
|
-
mod.strip(1).should eq 1
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe :title do
|
187
|
-
it "should upcase first char of each word, others downcased" do
|
188
|
-
value = "dirty DEEDS DONE dirt cheap"
|
189
|
-
expected = "Dirty Deeds Done Dirt Cheap"
|
190
|
-
mod.title(value).should eq expected
|
191
|
-
mod.title(value.mb_chars).should eq expected.mb_chars
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should affect accented chars" do
|
195
|
-
value = "isto NÃO é verdade"
|
196
|
-
expected = "Isto Não É Verdade"
|
197
|
-
mod.title(value).should eq expected
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should not affect non string objects" do
|
201
|
-
mod.title(nil).should eq nil
|
202
|
-
mod.title(1).should eq 1
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe :upcase do
|
207
|
-
it "should upcase all characters" do
|
208
|
-
value = "Ride the lightning"
|
209
|
-
expected = "RIDE THE LIGHTNING"
|
210
|
-
mod.upcase(value).should eq expected
|
211
|
-
mod.upcase(value.mb_chars).should eq expected.mb_chars
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should affect accented chars" do
|
215
|
-
value = "ébrio"
|
216
|
-
expected = "ÉBRIO"
|
217
|
-
mod.upcase(value).should eq expected
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should not affect non string objects" do
|
221
|
-
mod.upcase(nil).should eq nil
|
222
|
-
mod.upcase(1).should eq 1
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
pending "chomp with args"
|
227
|
-
pending "squeeze with args"
|
228
|
-
pending :camelize
|
229
|
-
pending :center
|
230
|
-
pending :chomp
|
231
|
-
pending :chop
|
232
|
-
pending :classify
|
233
|
-
pending :clear
|
234
|
-
pending :constantize
|
235
|
-
pending :deconstantize
|
236
|
-
pending :demodulize
|
237
|
-
pending :dump
|
238
|
-
pending :excerpt
|
239
|
-
pending :foreign_key
|
240
|
-
pending :highlight
|
241
|
-
pending :html
|
242
|
-
pending :humanize
|
243
|
-
pending :just
|
244
|
-
pending :ljust
|
245
|
-
pending :md
|
246
|
-
pending :ordinalize
|
247
|
-
pending :parameterize
|
248
|
-
pending :permalink
|
249
|
-
pending :pluralize
|
250
|
-
pending :pluralize
|
251
|
-
pending :reverse
|
252
|
-
pending :rjust
|
253
|
-
pending :safe_constantize
|
254
|
-
pending :simple_format
|
255
|
-
pending :singularize
|
256
|
-
pending "squeeze with args"
|
257
|
-
pending :succ
|
258
|
-
pending :swapcase
|
259
|
-
pending :tableize
|
260
|
-
pending :textile
|
261
|
-
pending :transliterate
|
262
|
-
pending :trim
|
263
|
-
pending :truncate
|
264
|
-
pending :underscore
|
265
|
-
pending :wrap
|
266
|
-
pending "remove accents"
|
267
|
-
pending "move :blank to another module"
|
268
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Normatron::Filters do
|
5
|
-
describe :is_a_string? do
|
6
|
-
it "should be true Multibyte::Chars object" do
|
7
|
-
subject.is_a_string?("".mb_chars).should be_true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should be true String object" do
|
11
|
-
subject.is_a_string?("").should be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should not be true nil object" do
|
15
|
-
subject.is_a_string?(nil).should be_false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should not be true Integer object" do
|
19
|
-
subject.is_a_string?(1).should be_false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/lib/normatron_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Normatron do
|
4
|
-
let(:mod) { Normatron }
|
5
|
-
let(:config) { Normatron.configuration }
|
6
|
-
|
7
|
-
describe "configuration" do
|
8
|
-
it "should respond to aliases" do
|
9
|
-
mod.should respond_to :configuration
|
10
|
-
mod.should respond_to :configure
|
11
|
-
mod.should respond_to :setup
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return configuration object" do
|
15
|
-
config.should be_an_instance_of Normatron::Configuration
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should process given blocks" do
|
19
|
-
expect { |b| Normatron.setup(&b) }.to yield_control
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|