dslh 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dslh.rb +14 -1
- data/lib/dslh/version.rb +1 -1
- data/spec/dslh_spec.rb +106 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90335d30a0a8550fac463effc4ae103bbc97ab2b
|
4
|
+
data.tar.gz: a2baa307388a8d6bfdcafd7ef6be5c6b2990b7e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b934b99328c9e461c3483cc24bbdf33e075709565ef87cfd0094c6b2a628fbe618e82623e28cadd5eb7e46e7ce64128a77578e053411e1c7067cc7f79c3098e7
|
7
|
+
data.tar.gz: 0f8755ccfe03468c91243ecfc1c8edca6d8ad8f17e3aea5274579bd6e41faf93c0bebf7df995771fcde52be7322c843f36703f7dade283c1f82a3eb57f1a48ec
|
data/lib/dslh.rb
CHANGED
@@ -134,7 +134,20 @@ class Dslh
|
|
134
134
|
|
135
135
|
schema = Kwalify::Yaml.load(schema)
|
136
136
|
validator = Kwalify::Validator.new(schema)
|
137
|
-
|
137
|
+
|
138
|
+
if @options[:root_identify]
|
139
|
+
new_retval = {}
|
140
|
+
|
141
|
+
retval.each do |k, v|
|
142
|
+
new_retval[k] = v.map {|_id, attrs|
|
143
|
+
attrs.merge('_id' => _id)
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
errors = validator.validate(new_retval)
|
148
|
+
else
|
149
|
+
errors = validator.validate(retval)
|
150
|
+
end
|
138
151
|
|
139
152
|
unless errors.empty?
|
140
153
|
raise ValidationError, errors
|
data/lib/dslh/version.rb
CHANGED
data/spec/dslh_spec.rb
CHANGED
@@ -3087,5 +3087,111 @@ employees2 "bar2" do
|
|
3087
3087
|
end
|
3088
3088
|
EOS
|
3089
3089
|
end
|
3090
|
+
|
3091
|
+
context 'with schema' do
|
3092
|
+
let(:schema) do
|
3093
|
+
<<-EOS
|
3094
|
+
type: map
|
3095
|
+
mapping:
|
3096
|
+
"employees":
|
3097
|
+
type: seq
|
3098
|
+
sequence:
|
3099
|
+
- type: map
|
3100
|
+
mapping:
|
3101
|
+
"_id":
|
3102
|
+
type: str
|
3103
|
+
required: yes
|
3104
|
+
"code":
|
3105
|
+
type: int
|
3106
|
+
required: yes
|
3107
|
+
"email":
|
3108
|
+
type: str
|
3109
|
+
"employees2":
|
3110
|
+
type: seq
|
3111
|
+
sequence:
|
3112
|
+
- type: map
|
3113
|
+
mapping:
|
3114
|
+
"_id":
|
3115
|
+
type: str
|
3116
|
+
required: yes
|
3117
|
+
"code":
|
3118
|
+
type: int
|
3119
|
+
required: yes
|
3120
|
+
"email":
|
3121
|
+
type: str
|
3122
|
+
EOS
|
3123
|
+
end
|
3124
|
+
|
3125
|
+
let(:expected_errmsg) do
|
3126
|
+
<<-EOS.chomp
|
3127
|
+
[/employees/0/_id] '123': not a string.
|
3128
|
+
[/employees/1/email] '100': not a string.
|
3129
|
+
[/employees2/0] key 'code:' is required.
|
3130
|
+
[/employees2/0/code1] key 'code1:' is undefined.
|
3131
|
+
[/employees2/0/email1] key 'email1:' is undefined.
|
3132
|
+
[/employees3] key 'employees3:' is undefined.
|
3133
|
+
EOS
|
3134
|
+
end
|
3135
|
+
|
3136
|
+
it 'has no error' do
|
3137
|
+
h = Dslh.eval(:schema => schema, :root_identify => true) do
|
3138
|
+
employees "foo" do
|
3139
|
+
code 101
|
3140
|
+
email "foo@winebarrel.com"
|
3141
|
+
end
|
3142
|
+
employees "bar" do
|
3143
|
+
code 102
|
3144
|
+
email "bar@winebarrel.com"
|
3145
|
+
end
|
3146
|
+
employees2 "foo2" do
|
3147
|
+
code 201
|
3148
|
+
email "foo@winebarrel.com"
|
3149
|
+
end
|
3150
|
+
employees2 "bar2" do
|
3151
|
+
code 202
|
3152
|
+
email "bar@winebarrel.com"
|
3153
|
+
end
|
3154
|
+
end
|
3155
|
+
|
3156
|
+
expect(h).to eq(
|
3157
|
+
{"employees"=>
|
3158
|
+
{"foo"=>{"code"=>101, "email"=>"foo@winebarrel.com"},
|
3159
|
+
"bar"=>{"code"=>102, "email"=>"bar@winebarrel.com"}},
|
3160
|
+
"employees2"=>
|
3161
|
+
{"foo2"=>{"code"=>201, "email"=>"foo@winebarrel.com"},
|
3162
|
+
"bar2"=>{"code"=>202, "email"=>"bar@winebarrel.com"}}}
|
3163
|
+
)
|
3164
|
+
end
|
3165
|
+
|
3166
|
+
it 'has error' do
|
3167
|
+
block = proc do
|
3168
|
+
employees 123 do
|
3169
|
+
code 101
|
3170
|
+
email "foo@winebarrel.com"
|
3171
|
+
end
|
3172
|
+
employees "bar" do
|
3173
|
+
code 102
|
3174
|
+
email 100
|
3175
|
+
end
|
3176
|
+
employees2 "foo2" do
|
3177
|
+
code1 201
|
3178
|
+
email1 "foo@winebarrel.com"
|
3179
|
+
end
|
3180
|
+
employees3 "bar2" do
|
3181
|
+
code 202
|
3182
|
+
email "bar@winebarrel.com"
|
3183
|
+
end
|
3184
|
+
end
|
3185
|
+
|
3186
|
+
begin
|
3187
|
+
h = Dslh.eval(:schema => schema, :root_identify => true, &block)
|
3188
|
+
fail "must raise validation error"
|
3189
|
+
rescue Dslh::ValidationError => e
|
3190
|
+
errmsg = e.errors.map {|i| i.to_s }.join("\n")
|
3191
|
+
expect(errmsg).to eq expected_errmsg
|
3192
|
+
expect(e.message).to eq expected_errmsg
|
3193
|
+
end
|
3194
|
+
end
|
3195
|
+
end
|
3090
3196
|
end
|
3091
3197
|
end
|