anodator 0.0.5 → 1.0.0.pre1
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -13
- data/LICENSE.txt +18 -17
- data/{README.ja.rdoc → README.ja.md} +2 -4
- data/README.md +39 -0
- data/Rakefile +3 -47
- data/anodator.gemspec +21 -103
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/anodator/check_result.rb +1 -1
- data/lib/anodator/input_spec.rb +2 -2
- data/lib/anodator/rule.rb +2 -2
- data/lib/anodator/utils.rb +4 -4
- data/lib/anodator/validator/format_validator.rb +1 -1
- data/lib/anodator/version.rb +3 -0
- data/lib/anodator.rb +1 -2
- metadata +70 -131
- data/Gemfile.lock +0 -29
- data/README.rdoc +0 -41
- data/spec/anodator/check_result_spec.rb +0 -101
- data/spec/anodator/checker_spec.rb +0 -273
- data/spec/anodator/input_spec_item_spec.rb +0 -100
- data/spec/anodator/input_spec_spec.rb +0 -584
- data/spec/anodator/message_spec.rb +0 -112
- data/spec/anodator/output_spec_spec.rb +0 -355
- data/spec/anodator/rule_set_spec.rb +0 -190
- data/spec/anodator/rule_spec.rb +0 -278
- data/spec/anodator/utils_spec.rb +0 -48
- data/spec/anodator/validator/base_spec.rb +0 -214
- data/spec/anodator/validator/blank_validator_spec.rb +0 -52
- data/spec/anodator/validator/complex_validator_spec.rb +0 -268
- data/spec/anodator/validator/date_validator_spec.rb +0 -350
- data/spec/anodator/validator/format_validator_spec.rb +0 -158
- data/spec/anodator/validator/inclusion_validator_spec.rb +0 -77
- data/spec/anodator/validator/length_validator_spec.rb +0 -236
- data/spec/anodator/validator/numeric_validator_spec.rb +0 -538
- data/spec/anodator/validator/presence_validator_spec.rb +0 -52
- data/spec/anodator/validator_spec.rb +0 -16
- data/spec/anodator_spec.rb +0 -2
- data/spec/spec_helper.rb +0 -12
@@ -1,112 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::Message
|
4
|
-
require "anodator/message"
|
5
|
-
require "anodator/input_spec"
|
6
|
-
|
7
|
-
include Anodator
|
8
|
-
|
9
|
-
describe Message, ".new" do
|
10
|
-
context "with no parameters" do
|
11
|
-
it "should raise ArgumentError" do
|
12
|
-
lambda {
|
13
|
-
Message.new
|
14
|
-
}.should raise_error ArgumentError
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with simple template_message" do
|
19
|
-
before(:each) do
|
20
|
-
@new_proc = lambda {
|
21
|
-
Message.new("An error occured!!")
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should not raise error" do
|
26
|
-
@new_proc.should_not raise_error
|
27
|
-
end
|
28
|
-
|
29
|
-
it "#template should be provided string" do
|
30
|
-
@message = @new_proc.call
|
31
|
-
@message.template.should == "An error occured!!"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with template_message include place holder" do
|
36
|
-
before(:each) do
|
37
|
-
@template = "An error occured [[1::name]]([[1::number]]) must not be [[1::value]]"
|
38
|
-
@new_proc = lambda {
|
39
|
-
Message.new(@template)
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should not raise error" do
|
44
|
-
@new_proc.should_not raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it "#template should be provided string" do
|
48
|
-
@message = @new_proc.call
|
49
|
-
@message.template.should == @template
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe Message, "#expand" do
|
55
|
-
before(:each) do
|
56
|
-
# create input spec and data source
|
57
|
-
@input_spec = InputSpec.new([
|
58
|
-
{ :number => "1", :name => "item_1" },
|
59
|
-
{ :number => "2", :name => "item_2" },
|
60
|
-
{ :number => "3", :name => "item_3" },
|
61
|
-
{ :number => "4", :name => "item_4" },
|
62
|
-
{ :number => "5", :name => "item_5" },
|
63
|
-
])
|
64
|
-
@values = %W(1 2 3 4 5)
|
65
|
-
@input_spec.source = @values
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when message is valid" do
|
69
|
-
before(:each) do
|
70
|
-
@template = "An error occured [[1::name]]([[1::number]]) must not be '[[1::value]]'"
|
71
|
-
@message = Message.new(@template)
|
72
|
-
@proc = lambda { @message.expand(@input_spec) }
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not raise error" do
|
76
|
-
@proc.should_not raise_error
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should equal replacement values" do
|
80
|
-
@proc.call.should ==
|
81
|
-
"An error occured item_1(1) must not be '1'"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when message's place holder contain unknown field" do
|
86
|
-
context "include unknown target_expression" do
|
87
|
-
before(:each) do
|
88
|
-
@template = "An error occured [[1::name]]([[1::number]]) must not be [[289::value]]"
|
89
|
-
@message = Message.new(@template)
|
90
|
-
@proc = lambda { @message.expand(@input_spec) }
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should raise UnknownTargetExpressionError" do
|
94
|
-
@proc.should raise_error UnknownTargetExpressionError
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "when message's place holder contain unknown field" do
|
100
|
-
context "include unknown attribute" do
|
101
|
-
before(:each) do
|
102
|
-
@template = "An error occured [[1::name]]([[1::number]]) must not be [[1::values]]"
|
103
|
-
@message = Message.new(@template)
|
104
|
-
@proc = lambda { @message.expand(@input_spec) }
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should raise UnknownMessageAttributeError" do
|
108
|
-
@proc.should raise_error UnknownMessageAttributeError
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,355 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::OutputSpec
|
4
|
-
require "anodator/output_spec"
|
5
|
-
|
6
|
-
include Anodator
|
7
|
-
|
8
|
-
describe OutputSpec, ".new" do
|
9
|
-
context "with no paramerters" do
|
10
|
-
before(:each) do
|
11
|
-
@new_proc = lambda {
|
12
|
-
OutputSpec.new
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should not raise error" do
|
17
|
-
@new_proc.should_not raise_error
|
18
|
-
end
|
19
|
-
|
20
|
-
context "after generated" do
|
21
|
-
before(:each) do
|
22
|
-
@output_spec = @new_proc.call
|
23
|
-
end
|
24
|
-
|
25
|
-
it "#items should be empty" do
|
26
|
-
@output_spec.items.should be_empty
|
27
|
-
end
|
28
|
-
|
29
|
-
it "#target should be OutputSpec::TARGET_ERROR by default" do
|
30
|
-
@output_spec.target.should == OutputSpec::TARGET_ERROR
|
31
|
-
end
|
32
|
-
|
33
|
-
it "#include_no_error should be false by default" do
|
34
|
-
@output_spec.include_no_error.should be_false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with several error items parameter" do
|
40
|
-
before(:each) do
|
41
|
-
@new_proc = lambda {
|
42
|
-
OutputSpec.new([
|
43
|
-
:target_numbers,
|
44
|
-
:target_names,
|
45
|
-
:target_values,
|
46
|
-
:error_message,
|
47
|
-
:error_level,
|
48
|
-
])
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not raise error" do
|
53
|
-
@new_proc.should_not raise_error
|
54
|
-
end
|
55
|
-
|
56
|
-
context "after generated" do
|
57
|
-
before(:each) do
|
58
|
-
@output_spec = @new_proc.call
|
59
|
-
end
|
60
|
-
|
61
|
-
it "#items should not be empty" do
|
62
|
-
@output_spec.items.should_not be_empty
|
63
|
-
end
|
64
|
-
|
65
|
-
it "#target should be OutputSpec::TARGET_ERROR by default" do
|
66
|
-
@output_spec.target.should == OutputSpec::TARGET_ERROR
|
67
|
-
end
|
68
|
-
|
69
|
-
it "#include_no_error should be false by default" do
|
70
|
-
@output_spec.include_no_error.should be_false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with several input items parameter with error items" do
|
76
|
-
before(:each) do
|
77
|
-
@new_proc = lambda {
|
78
|
-
OutputSpec.new([
|
79
|
-
"1",
|
80
|
-
"2",
|
81
|
-
"3",
|
82
|
-
"name",
|
83
|
-
])
|
84
|
-
}
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should not raise error" do
|
88
|
-
@new_proc.should_not raise_error
|
89
|
-
end
|
90
|
-
|
91
|
-
context "after generated" do
|
92
|
-
before(:each) do
|
93
|
-
@output_spec = @new_proc.call
|
94
|
-
end
|
95
|
-
|
96
|
-
it "#items should not be empty" do
|
97
|
-
@output_spec.items.should_not be_empty
|
98
|
-
end
|
99
|
-
|
100
|
-
it "#target should be OutputSpec::TARGET_ERROR by default" do
|
101
|
-
@output_spec.target.should == OutputSpec::TARGET_ERROR
|
102
|
-
end
|
103
|
-
|
104
|
-
it "#include_no_error should be false by default" do
|
105
|
-
@output_spec.include_no_error.should be_false
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "with items and :target option" do
|
111
|
-
before(:each) do
|
112
|
-
@new_proc = lambda {
|
113
|
-
OutputSpec.new([
|
114
|
-
"1",
|
115
|
-
"2",
|
116
|
-
"3",
|
117
|
-
"name",
|
118
|
-
],
|
119
|
-
:target => OutputSpec::TARGET_DATA)
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should not raise error" do
|
124
|
-
@new_proc.should_not raise_error
|
125
|
-
end
|
126
|
-
|
127
|
-
context "after generated" do
|
128
|
-
before(:each) do
|
129
|
-
@output_spec = @new_proc.call
|
130
|
-
end
|
131
|
-
|
132
|
-
it "#items should not be empty" do
|
133
|
-
@output_spec.items.should_not be_empty
|
134
|
-
end
|
135
|
-
|
136
|
-
it "#target should be OutputSpec::TARGET_DATA" do
|
137
|
-
@output_spec.target.should == OutputSpec::TARGET_DATA
|
138
|
-
end
|
139
|
-
|
140
|
-
it "#include_no_error should be false by default" do
|
141
|
-
@output_spec.include_no_error.should be_false
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "with items and :target option and :include_no_error option" do
|
147
|
-
before(:each) do
|
148
|
-
@new_proc = lambda {
|
149
|
-
OutputSpec.new([
|
150
|
-
"1",
|
151
|
-
"2",
|
152
|
-
"3",
|
153
|
-
"name",
|
154
|
-
:target_numbers,
|
155
|
-
:error_message,
|
156
|
-
:error_level,
|
157
|
-
],
|
158
|
-
:target => OutputSpec::TARGET_ERROR,
|
159
|
-
:include_no_error => true)
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should not raise error" do
|
164
|
-
@new_proc.should_not raise_error
|
165
|
-
end
|
166
|
-
|
167
|
-
context "after generated" do
|
168
|
-
before(:each) do
|
169
|
-
@output_spec = @new_proc.call
|
170
|
-
end
|
171
|
-
|
172
|
-
it "#items should not be empty" do
|
173
|
-
@output_spec.items.should_not be_empty
|
174
|
-
end
|
175
|
-
|
176
|
-
it "#target should be OutputSpec::TARGET_ERROR" do
|
177
|
-
@output_spec.target.should == OutputSpec::TARGET_ERROR
|
178
|
-
end
|
179
|
-
|
180
|
-
it "#include_no_error should be true" do
|
181
|
-
@output_spec.include_no_error.should be_true
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe OutputSpec, "#generate" do
|
188
|
-
before(:each) do
|
189
|
-
# preparation
|
190
|
-
@input_spec = InputSpec.new([
|
191
|
-
{ :number => "1", :name => "first name" },
|
192
|
-
{ :number => "2", :name => "family name" },
|
193
|
-
{ :number => "3", :name => "nickname" },
|
194
|
-
{ :number => "4", :name => "sex" },
|
195
|
-
])
|
196
|
-
@rule_set = RuleSet.new
|
197
|
-
@rule_set << Rule.new("1",
|
198
|
-
Message.new("[[1::name]] Cannot be blank"),
|
199
|
-
Validator::PresenceValidator.new("1"))
|
200
|
-
@rule_set << Rule.new("2",
|
201
|
-
Message.new("[[2::name]] Cannot be blank"),
|
202
|
-
Validator::PresenceValidator.new("2"))
|
203
|
-
@rule_set << Rule.new("3",
|
204
|
-
Message.new("[[3::name]] Cannot be blank"),
|
205
|
-
Validator::PresenceValidator.new("3"),
|
206
|
-
nil, Rule::ERROR_LEVELS[:warning])
|
207
|
-
@rule_set << Rule.new(["3", "4"],
|
208
|
-
Message.new("[[4::name]] Must be 'M' or 'F'"),
|
209
|
-
Validator::InclusionValidator.new("4",
|
210
|
-
:in => %W(M F)))
|
211
|
-
Validator::Base.values = @input_spec
|
212
|
-
end
|
213
|
-
|
214
|
-
context "when including errors" do
|
215
|
-
before(:each) do
|
216
|
-
@values = ["", "", "", ""]
|
217
|
-
@input_spec.source = @values
|
218
|
-
@rule_set.check_all
|
219
|
-
end
|
220
|
-
|
221
|
-
context "generate error list" do
|
222
|
-
before(:each) do
|
223
|
-
@output_spec = OutputSpec.new([
|
224
|
-
"1",
|
225
|
-
"2",
|
226
|
-
"nickname",
|
227
|
-
"4",
|
228
|
-
:target_numbers,
|
229
|
-
:target_names,
|
230
|
-
:error_message,
|
231
|
-
:error_level,
|
232
|
-
],
|
233
|
-
:target => OutputSpec::TARGET_ERROR,
|
234
|
-
:include_no_error => true)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should generate error list datas" do
|
238
|
-
@output_spec.generate(@input_spec, @rule_set.results).should ==
|
239
|
-
[
|
240
|
-
["", "", "", "", "1", "first name", "first name Cannot be blank", Rule::ERROR_LEVELS[:error].to_s],
|
241
|
-
["", "", "", "", "2", "family name", "family name Cannot be blank", Rule::ERROR_LEVELS[:error].to_s],
|
242
|
-
["", "", "", "", "3", "nickname", "nickname Cannot be blank", Rule::ERROR_LEVELS[:warning].to_s],
|
243
|
-
["", "", "", "", "3 4", "nickname sex", "sex Must be 'M' or 'F'", Rule::ERROR_LEVELS[:error].to_s],
|
244
|
-
]
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context "generate data list" do
|
249
|
-
before(:each) do
|
250
|
-
@output_spec = OutputSpec.new([
|
251
|
-
"1",
|
252
|
-
"2",
|
253
|
-
"nickname",
|
254
|
-
"4",
|
255
|
-
:target_numbers,
|
256
|
-
:target_names,
|
257
|
-
:error_message,
|
258
|
-
:error_level,
|
259
|
-
:error_count,
|
260
|
-
:warning_count,
|
261
|
-
:error_and_warning_count,
|
262
|
-
],
|
263
|
-
:target => OutputSpec::TARGET_DATA,
|
264
|
-
:include_no_error => true)
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should generate list data" do
|
268
|
-
@output_spec.generate(@input_spec, @rule_set.results).should ==
|
269
|
-
[
|
270
|
-
["", "", "", "", "", "", "", "", "3", "1", "4"],
|
271
|
-
]
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "when including no errors" do
|
277
|
-
before(:each) do
|
278
|
-
@values = ["Tetsuhisa", "MAKINO", "makitetsu", "M"]
|
279
|
-
@input_spec.source = @values
|
280
|
-
@rule_set.check_all
|
281
|
-
end
|
282
|
-
|
283
|
-
context "generate error list include no error" do
|
284
|
-
before(:each) do
|
285
|
-
@output_spec = OutputSpec.new([
|
286
|
-
"1",
|
287
|
-
"2",
|
288
|
-
"nickname",
|
289
|
-
"4",
|
290
|
-
:target_numbers,
|
291
|
-
:target_names,
|
292
|
-
:error_message,
|
293
|
-
:error_level,
|
294
|
-
],
|
295
|
-
:target => OutputSpec::TARGET_ERROR,
|
296
|
-
:include_no_error => true)
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should generate one data" do
|
300
|
-
@output_spec.generate(@input_spec, @rule_set.results).should ==
|
301
|
-
[
|
302
|
-
["Tetsuhisa", "MAKINO", "makitetsu", "M", "", "", "", ""]
|
303
|
-
]
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context "generate error list not include no error" do
|
308
|
-
before(:each) do
|
309
|
-
@output_spec = OutputSpec.new([
|
310
|
-
"1",
|
311
|
-
"2",
|
312
|
-
"nickname",
|
313
|
-
"4",
|
314
|
-
:target_numbers,
|
315
|
-
:target_names,
|
316
|
-
:error_message,
|
317
|
-
:error_level,
|
318
|
-
],
|
319
|
-
:target => OutputSpec::TARGET_ERROR,
|
320
|
-
:include_no_error => false)
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should be empty" do
|
324
|
-
@output_spec.generate(@input_spec, @rule_set.results).should be_empty
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context "generate data list" do
|
329
|
-
before(:each) do
|
330
|
-
@output_spec = OutputSpec.new([
|
331
|
-
"1",
|
332
|
-
"2",
|
333
|
-
"nickname",
|
334
|
-
"4",
|
335
|
-
:target_numbers,
|
336
|
-
:target_names,
|
337
|
-
:error_message,
|
338
|
-
:error_level,
|
339
|
-
:error_count,
|
340
|
-
:warning_count,
|
341
|
-
:error_and_warning_count,
|
342
|
-
],
|
343
|
-
:target => OutputSpec::TARGET_DATA,
|
344
|
-
:include_no_error => true)
|
345
|
-
end
|
346
|
-
|
347
|
-
it "should not raise error" do
|
348
|
-
@output_spec.generate(@input_spec, @rule_set.results).should ==
|
349
|
-
[
|
350
|
-
["Tetsuhisa", "MAKINO", "makitetsu", "M", "", "", "", "", "0", "0", "0"],
|
351
|
-
]
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
@@ -1,190 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
# Anodator::RuleSet
|
4
|
-
require "anodator/rule_set"
|
5
|
-
|
6
|
-
include Anodator
|
7
|
-
|
8
|
-
describe RuleSet, ".new" do
|
9
|
-
context "with no parameters" do
|
10
|
-
it "should not raise error" do
|
11
|
-
lambda {
|
12
|
-
RuleSet.new
|
13
|
-
}.should_not raise_error
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe RuleSet, "after generated" do
|
19
|
-
before(:each) do
|
20
|
-
# preparation
|
21
|
-
@input_spec = InputSpec.new([
|
22
|
-
{ :number => "1", :name => "first name"},
|
23
|
-
{ :number => "2", :name => "family name"},
|
24
|
-
{ :number => "3", :name => "phone"},
|
25
|
-
{ :number => "4", :name => "mail address"},
|
26
|
-
{ :number => "5", :name => "sex"},
|
27
|
-
{ :number => "6", :name => "age"},
|
28
|
-
])
|
29
|
-
@records =
|
30
|
-
[
|
31
|
-
[ "Tetsuhisa" , "" , "0000-0000-0000" , "tim.makino@gmail.com" , "M" , "31" ],
|
32
|
-
[ "Takashi" , "Nakajima" , "0000-00-00-0001" , "nakajima@example@com" , "Male" , "28.4" ],
|
33
|
-
]
|
34
|
-
|
35
|
-
### Rules
|
36
|
-
@rule_set = RuleSet.new
|
37
|
-
|
38
|
-
### set datas
|
39
|
-
Validator::Base.values = @input_spec
|
40
|
-
end
|
41
|
-
|
42
|
-
describe RuleSet, "#add_rule" do
|
43
|
-
before(:each) do
|
44
|
-
# first name
|
45
|
-
@rule_set.add_rule(Rule.new("1",
|
46
|
-
Message.new("[[1::name]] cannot be blank."),
|
47
|
-
Validator::PresenceValidator.new("1")))
|
48
|
-
# family name
|
49
|
-
@rule_set.add_rule(Rule.new("2",
|
50
|
-
Message.new("[[2::name]] cannot be blank."),
|
51
|
-
Validator::PresenceValidator.new("2")))
|
52
|
-
# phone
|
53
|
-
@rule_set.add_rule(Rule.new("phone",
|
54
|
-
Message.new("[[phone::name]] is invalid format."),
|
55
|
-
Validator::FormatValidator.new("phone", :format => /^\d+-\d+-\d+$/),
|
56
|
-
Validator::PresenceValidator.new("phone"), Rule::ERROR_LEVELS[:warning]))
|
57
|
-
# mail address
|
58
|
-
@rule_set.add_rule(Rule.new("4",
|
59
|
-
Message.new("[[4:name]] is invalid format."),
|
60
|
-
Validator::FormatValidator.new("4", :format => /^[^@]+@[^@]+$/, :allow_blank => true)))
|
61
|
-
# sex
|
62
|
-
@rule_set.add_rule(Rule.new("5",
|
63
|
-
Message.new("[[5::name]] must be M/F/Man/Woman."),
|
64
|
-
Validator::InclusionValidator.new("5", :in => %W(M F Man Woman))))
|
65
|
-
# age
|
66
|
-
@rule_set.add_rule(Rule.new("age",
|
67
|
-
Message.new("[[age::name]] must be integer."),
|
68
|
-
Validator::NumericValidator.new("age", :only_integer => true)))
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should have all rules" do
|
72
|
-
@rule_set.instance_eval("@rules.count").should == 6
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe RuleSet, "#<<" do
|
77
|
-
before(:each) do
|
78
|
-
# first name
|
79
|
-
@rule_set << Rule.new("1",
|
80
|
-
Message.new("[[1::name]] cannot be blank."),
|
81
|
-
Validator::PresenceValidator.new("1"))
|
82
|
-
# family name
|
83
|
-
@rule_set << Rule.new("2",
|
84
|
-
Message.new("[[2::name]] cannot be blank."),
|
85
|
-
Validator::PresenceValidator.new("2"))
|
86
|
-
# phone
|
87
|
-
@rule_set << Rule.new("phone",
|
88
|
-
Message.new("[[phone::name]] is invalid format."),
|
89
|
-
Validator::FormatValidator.new("phone", :format => /^\d+-\d+-\d+$/),
|
90
|
-
Validator::PresenceValidator.new("phone"), Rule::ERROR_LEVELS[:warning])
|
91
|
-
# mail address
|
92
|
-
@rule_set << Rule.new("4",
|
93
|
-
Message.new("[[4::name]] is invalid format."),
|
94
|
-
Validator::FormatValidator.new("4", :format => /^[^@]+@[^@]+$/, :allow_blank => true))
|
95
|
-
# sex
|
96
|
-
@rule_set << Rule.new("5",
|
97
|
-
Message.new("[[5::name]] must be M/F/Man/Woman."),
|
98
|
-
Validator::InclusionValidator.new("5", :in => %W(M F Man Woman)))
|
99
|
-
# age
|
100
|
-
@rule_set << Rule.new("age",
|
101
|
-
Message.new("[[age::name]] must be integer."),
|
102
|
-
Validator::NumericValidator.new("age", :only_integer => true))
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should have all rules" do
|
106
|
-
@rule_set.instance_eval("@rules.count").should == 6
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe RuleSet, "#check_all" do
|
111
|
-
before(:each) do
|
112
|
-
# first name
|
113
|
-
@rule_set << Rule.new("1",
|
114
|
-
Message.new("[[1::name]] cannot be blank."),
|
115
|
-
Validator::PresenceValidator.new("1"))
|
116
|
-
# family name
|
117
|
-
@rule_set << Rule.new("2",
|
118
|
-
Message.new("[[2::name]] cannot be blank."),
|
119
|
-
Validator::PresenceValidator.new("2"))
|
120
|
-
# phone
|
121
|
-
@rule_set << Rule.new("phone",
|
122
|
-
Message.new("[[phone::name]] is invalid format."),
|
123
|
-
Validator::FormatValidator.new("phone", :format => /^\d+-\d+-\d+$/),
|
124
|
-
Validator::PresenceValidator.new("phone"), Rule::ERROR_LEVELS[:warning])
|
125
|
-
# mail address
|
126
|
-
@rule_set << Rule.new("4",
|
127
|
-
Message.new("[[4::name]] is invalid format."),
|
128
|
-
Validator::FormatValidator.new("4", :format => /^[^@]+@[^@]+$/, :allow_blank => true))
|
129
|
-
# sex
|
130
|
-
@rule_set << Rule.new("5",
|
131
|
-
Message.new("[[5::name]] must be M/F/Man/Woman."),
|
132
|
-
Validator::InclusionValidator.new("5", :in => %W(M F Man Woman)))
|
133
|
-
# age
|
134
|
-
@rule_set << Rule.new("age",
|
135
|
-
Message.new("[[age::name]] must be integer."),
|
136
|
-
Validator::NumericValidator.new("age", :only_integer => true))
|
137
|
-
|
138
|
-
@proc = lambda {
|
139
|
-
@input_spec.source = @records.first
|
140
|
-
@rule_set.check_all
|
141
|
-
}
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should not raise error" do
|
145
|
-
@proc.should_not raise_error
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should have results" do
|
149
|
-
@proc.call
|
150
|
-
@rule_set.instance_eval("@results.count").should_not be_zero
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe RuleSet, "#results" do
|
155
|
-
before(:each) do
|
156
|
-
# first name
|
157
|
-
@rule_set << Rule.new("1",
|
158
|
-
Message.new("[[1::name]] cannot be blank."),
|
159
|
-
Validator::PresenceValidator.new("1"))
|
160
|
-
# family name
|
161
|
-
@rule_set << Rule.new("2",
|
162
|
-
Message.new("[[2::name]] cannot be blank."),
|
163
|
-
Validator::PresenceValidator.new("2"))
|
164
|
-
# phone
|
165
|
-
@rule_set << Rule.new("phone",
|
166
|
-
Message.new("[[phone::name]] is invalid format.([[phone::value]])"),
|
167
|
-
Validator::FormatValidator.new("phone", :format => /^\d+-\d+-\d+$/),
|
168
|
-
Validator::PresenceValidator.new("phone"), Rule::ERROR_LEVELS[:warning])
|
169
|
-
# mail address
|
170
|
-
@rule_set << Rule.new("4",
|
171
|
-
Message.new("[[4::name]] is invalid format.([[4::value]])"),
|
172
|
-
Validator::FormatValidator.new("4", :format => /^[^@]+@[^@]+$/, :allow_blank => true))
|
173
|
-
# sex
|
174
|
-
@rule_set << Rule.new("5",
|
175
|
-
Message.new("[[5::name]] must be M/F/Man/Woman.([[5::value]])"),
|
176
|
-
Validator::InclusionValidator.new("5", :in => %W(M F Man Woman)))
|
177
|
-
# age
|
178
|
-
@rule_set << Rule.new("age",
|
179
|
-
Message.new("[[age::name]] must be integer.([[age::value]])"),
|
180
|
-
Validator::NumericValidator.new("age", :only_integer => true))
|
181
|
-
|
182
|
-
@input_spec.source = @records.last
|
183
|
-
@rule_set.check_all
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should have results count 4" do
|
187
|
-
@rule_set.results.count.should == 4
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|