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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21ed893265981c141c3c0d34d7c2b1f80fa72ac1
4
- data.tar.gz: 41e7a5be1a5d6cc4cf0840c9aef97b1bef0ba0b8
3
+ metadata.gz: 90335d30a0a8550fac463effc4ae103bbc97ab2b
4
+ data.tar.gz: a2baa307388a8d6bfdcafd7ef6be5c6b2990b7e7
5
5
  SHA512:
6
- metadata.gz: c73b4951338446b91966eeb8c0228b72d06dd6d9582acea5abf550d01d648e2b1660ddc1a979686b67bd6fee90bfc32eea0f4a0a472bf679790f89741fb2b233
7
- data.tar.gz: 03b3a3a15244f67d8ef0ed5eb74c00af859185325749fe1f1f0ede1bf91030e7566d135d940a92e478bd9a1d0234202ccf9b887b4684b12bfc8cc2fed4ff028e
6
+ metadata.gz: b934b99328c9e461c3483cc24bbdf33e075709565ef87cfd0094c6b2a628fbe618e82623e28cadd5eb7e46e7ce64128a77578e053411e1c7067cc7f79c3098e7
7
+ data.tar.gz: 0f8755ccfe03468c91243ecfc1c8edca6d8ad8f17e3aea5274579bd6e41faf93c0bebf7df995771fcde52be7322c843f36703f7dade283c1f82a3eb57f1a48ec
@@ -134,7 +134,20 @@ class Dslh
134
134
 
135
135
  schema = Kwalify::Yaml.load(schema)
136
136
  validator = Kwalify::Validator.new(schema)
137
- errors = validator.validate(retval)
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
@@ -1,3 +1,3 @@
1
1
  class Dslh
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara