groonga-client-model 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +13 -0
- data/groonga-client-model.gemspec +3 -3
- data/lib/groonga-client-model.rb +9 -2
- data/lib/groonga_client_model/locale/en.yml +23 -0
- data/lib/groonga_client_model/locale/ja.yml +23 -0
- data/lib/groonga_client_model/record.rb +15 -3
- data/lib/groonga_client_model/schema.rb +14 -7
- data/lib/groonga_client_model/validations/type_validator.rb +143 -0
- data/lib/groonga_client_model/version.rb +1 -1
- data/test/apps/rails4/Gemfile.lock +7 -7
- data/test/apps/rails4/log/test.log +56 -0
- data/test/apps/rails5/Gemfile.lock +2 -2
- data/test/apps/rails5/app/models/age.rb +2 -0
- data/test/apps/rails5/db/schema.grn +2 -0
- data/test/apps/rails5/log/test.log +5313 -0
- data/test/apps/rails5/test/factories/ages.rb +5 -0
- data/test/apps/rails5/test/models/age_test.rb +19 -0
- data/test/unit/test_record.rb +272 -20
- metadata +13 -4
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AgeTest < ActiveSupport::TestCase
|
4
|
+
include GroongaClientModel::TestHelper
|
5
|
+
|
6
|
+
test "validate: _key: invalid: string" do
|
7
|
+
key = "Hello"
|
8
|
+
age = Age.new(_key: key)
|
9
|
+
assert(age.invalid?)
|
10
|
+
assert_equal({
|
11
|
+
_key: [
|
12
|
+
age.errors.generate_message(:_key,
|
13
|
+
:not_a_positive_integer,
|
14
|
+
inspected_value: key.inspect)
|
15
|
+
],
|
16
|
+
},
|
17
|
+
age.errors.messages)
|
18
|
+
end
|
19
|
+
end
|
data/test/unit/test_record.rb
CHANGED
@@ -15,11 +15,16 @@
|
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
17
|
class TestRecord < Test::Unit::TestCase
|
18
|
+
Column = Groonga::Client::Response::Schema::Column
|
19
|
+
|
18
20
|
sub_test_case("ActiveModel") do
|
19
21
|
class EmptyModel < GroongaClientModel::Record
|
20
22
|
class << self
|
21
23
|
def columns
|
22
|
-
|
24
|
+
raw_columns = {
|
25
|
+
"_id" => Column.new(nil, {}),
|
26
|
+
}
|
27
|
+
GroongaClientModel::Schema::Columns.new(nil, raw_columns)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
@@ -51,42 +56,289 @@ class TestRecord < Test::Unit::TestCase
|
|
51
56
|
end
|
52
57
|
|
53
58
|
sub_test_case("validations") do
|
54
|
-
sub_test_case("_key
|
59
|
+
sub_test_case("_key") do
|
55
60
|
class NoKey < GroongaClientModel::Record
|
56
61
|
class << self
|
57
62
|
def columns
|
58
|
-
|
63
|
+
raw_columns = {
|
64
|
+
"_id" => Column.new(nil, {}),
|
65
|
+
}
|
66
|
+
GroongaClientModel::Schema::Columns.new(nil, raw_columns)
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
63
|
-
class
|
71
|
+
class Key < GroongaClientModel::Record
|
64
72
|
class << self
|
65
73
|
def columns
|
66
|
-
|
67
|
-
|
68
|
-
|
74
|
+
raw_columns = {
|
75
|
+
"_id" => Column.new(nil, {}),
|
76
|
+
"_key" => Column.new(nil, {
|
77
|
+
"name" => "_key",
|
78
|
+
"value_type" => {
|
79
|
+
"name" => key_type,
|
80
|
+
},
|
81
|
+
}),
|
82
|
+
}
|
83
|
+
GroongaClientModel::Schema::Columns.new(nil, raw_columns)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class ShortTextKey < Key
|
89
|
+
class << self
|
90
|
+
def key_type
|
91
|
+
"ShortText"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class UInt8Key < Key
|
97
|
+
class << self
|
98
|
+
def key_type
|
99
|
+
"UInt8"
|
69
100
|
end
|
70
101
|
end
|
71
102
|
end
|
72
103
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
104
|
+
class UInt16Key < Key
|
105
|
+
class << self
|
106
|
+
def key_type
|
107
|
+
"UInt16"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class UInt32Key < Key
|
113
|
+
class << self
|
114
|
+
def key_type
|
115
|
+
"UInt32"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class UInt64Key < Key
|
121
|
+
class << self
|
122
|
+
def key_type
|
123
|
+
"UInt64"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class Int8Key < Key
|
129
|
+
class << self
|
130
|
+
def key_type
|
131
|
+
"Int8"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class Int16Key < Key
|
137
|
+
class << self
|
138
|
+
def key_type
|
139
|
+
"Int16"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class Int32Key < Key
|
145
|
+
class << self
|
146
|
+
def key_type
|
147
|
+
"Int32"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class Int64Key < Key
|
153
|
+
class << self
|
154
|
+
def key_type
|
155
|
+
"Int64"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class FloatKey < Key
|
161
|
+
class << self
|
162
|
+
def key_type
|
163
|
+
"Float"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class TimeKey < Key
|
169
|
+
class << self
|
170
|
+
def key_type
|
171
|
+
"Time"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
sub_test_case("presence") do
|
177
|
+
test "no key" do
|
178
|
+
record = NoKey.new
|
179
|
+
assert do
|
180
|
+
record.valid?
|
181
|
+
end
|
182
|
+
assert_equal({}, record.errors.messages)
|
183
|
+
end
|
184
|
+
|
185
|
+
test "missing key" do
|
186
|
+
record = ShortTextKey.new
|
187
|
+
assert do
|
188
|
+
not record.valid?
|
189
|
+
end
|
190
|
+
message = record.errors.generate_message(:_key, :blank)
|
191
|
+
assert_equal({
|
192
|
+
:_key => [message],
|
193
|
+
},
|
194
|
+
record.errors.messages)
|
195
|
+
end
|
196
|
+
|
197
|
+
test "blank key" do
|
198
|
+
record = UInt32Key.new(_key: "")
|
199
|
+
assert do
|
200
|
+
not record.valid?
|
201
|
+
end
|
202
|
+
message = record.errors.generate_message(:_key, :blank)
|
203
|
+
assert_equal({
|
204
|
+
:_key => [message],
|
205
|
+
},
|
206
|
+
record.errors.messages)
|
207
|
+
end
|
208
|
+
|
209
|
+
test "have key" do
|
210
|
+
record = ShortTextKey.new(_key: "String")
|
211
|
+
assert do
|
212
|
+
record.valid?
|
213
|
+
end
|
214
|
+
assert_equal({},
|
215
|
+
record.errors.messages)
|
77
216
|
end
|
78
|
-
assert_equal({}, record.errors.messages)
|
79
217
|
end
|
80
218
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
219
|
+
sub_test_case("type") do
|
220
|
+
def assert_invalid(klass, key, message_key)
|
221
|
+
record = klass.new(_key: key)
|
222
|
+
assert do
|
223
|
+
not record.valid?
|
224
|
+
end
|
225
|
+
options = {
|
226
|
+
inspected_value: key.inspect
|
227
|
+
}
|
228
|
+
message = record.errors.generate_message(:_key, message_key, options)
|
229
|
+
assert_equal({
|
230
|
+
:_key => [message],
|
231
|
+
},
|
232
|
+
record.errors.messages)
|
233
|
+
end
|
234
|
+
|
235
|
+
sub_test_case("UInt8") do
|
236
|
+
test("invalid") do
|
237
|
+
assert_invalid(UInt8Key, "String", :not_a_positive_integer)
|
238
|
+
end
|
239
|
+
|
240
|
+
test("too large") do
|
241
|
+
assert_invalid(UInt8Key, 2 ** 8, :invalid_uint8)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
sub_test_case("UInt16") do
|
246
|
+
test("invalid") do
|
247
|
+
assert_invalid(UInt16Key, "String", :not_a_positive_integer)
|
248
|
+
end
|
249
|
+
|
250
|
+
test("too large") do
|
251
|
+
assert_invalid(UInt16Key, 2 ** 16, :invalid_uint16)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
sub_test_case("UInt32") do
|
256
|
+
test("invalid") do
|
257
|
+
assert_invalid(UInt32Key, "String", :not_a_positive_integer)
|
258
|
+
end
|
259
|
+
|
260
|
+
test("too large") do
|
261
|
+
assert_invalid(UInt32Key, 2 ** 32, :invalid_uint32)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
sub_test_case("UInt64") do
|
266
|
+
test("invalid") do
|
267
|
+
assert_invalid(UInt64Key, "String", :not_a_positive_integer)
|
268
|
+
end
|
269
|
+
|
270
|
+
test("too large") do
|
271
|
+
assert_invalid(UInt64Key, 2 ** 64, :invalid_uint64)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
sub_test_case("Int8") do
|
276
|
+
test("invalid") do
|
277
|
+
assert_invalid(Int8Key, "String", :not_an_integer)
|
278
|
+
end
|
279
|
+
|
280
|
+
test("too small") do
|
281
|
+
assert_invalid(Int8Key, -(2 ** 7) - 1, :invalid_int8)
|
282
|
+
end
|
283
|
+
|
284
|
+
test("too large") do
|
285
|
+
assert_invalid(Int8Key, 2 ** 7, :invalid_int8)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
sub_test_case("Int16") do
|
290
|
+
test("invalid") do
|
291
|
+
assert_invalid(Int16Key, "String", :not_an_integer)
|
292
|
+
end
|
293
|
+
|
294
|
+
test("too small") do
|
295
|
+
assert_invalid(Int16Key, -(2 ** 15) - 1, :invalid_int16)
|
296
|
+
end
|
297
|
+
|
298
|
+
test("too large") do
|
299
|
+
assert_invalid(Int16Key, 2 ** 15, :invalid_int16)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
sub_test_case("Int32") do
|
304
|
+
test("invalid") do
|
305
|
+
assert_invalid(Int32Key, "String", :not_an_integer)
|
306
|
+
end
|
307
|
+
|
308
|
+
test("too small") do
|
309
|
+
assert_invalid(Int32Key, -(2 ** 31) - 1, :invalid_int32)
|
310
|
+
end
|
311
|
+
|
312
|
+
test("too large") do
|
313
|
+
assert_invalid(Int32Key, 2 ** 31, :invalid_int32)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
sub_test_case("Int64") do
|
318
|
+
test("invalid") do
|
319
|
+
assert_invalid(Int64Key, "String", :not_an_integer)
|
320
|
+
end
|
321
|
+
|
322
|
+
test("too small") do
|
323
|
+
assert_invalid(Int64Key, -(2 ** 63) - 1, :invalid_int64)
|
324
|
+
end
|
325
|
+
|
326
|
+
test("too large") do
|
327
|
+
assert_invalid(Int64Key, 2 ** 63, :invalid_int64)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
sub_test_case("Float") do
|
332
|
+
test("invalid") do
|
333
|
+
assert_invalid(FloatKey, "String", :not_a_number)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
sub_test_case("Time") do
|
338
|
+
test("invalid") do
|
339
|
+
assert_invalid(TimeKey, "String", :not_a_time)
|
340
|
+
end
|
85
341
|
end
|
86
|
-
assert_equal({
|
87
|
-
:_key => [record.errors.generate_message(:_key, :blank)],
|
88
|
-
},
|
89
|
-
record.errors.messages)
|
90
342
|
end
|
91
343
|
end
|
92
344
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.4.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.4.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: groonga-command-parser
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +142,8 @@ files:
|
|
142
142
|
- lib/groonga_client_model/client_opener.rb
|
143
143
|
- lib/groonga_client_model/error.rb
|
144
144
|
- lib/groonga_client_model/load_value_generator.rb
|
145
|
+
- lib/groonga_client_model/locale/en.yml
|
146
|
+
- lib/groonga_client_model/locale/ja.yml
|
145
147
|
- lib/groonga_client_model/log_subscriber.rb
|
146
148
|
- lib/groonga_client_model/modelizable.rb
|
147
149
|
- lib/groonga_client_model/modelize.rb
|
@@ -155,6 +157,7 @@ files:
|
|
155
157
|
- lib/groonga_client_model/test/fixture.rb
|
156
158
|
- lib/groonga_client_model/test/groonga_server_runner.rb
|
157
159
|
- lib/groonga_client_model/test_helper.rb
|
160
|
+
- lib/groonga_client_model/validations/type_validator.rb
|
158
161
|
- lib/groonga_client_model/version.rb
|
159
162
|
- lib/rails/generators/groonga_client_model/model/model_generator.rb
|
160
163
|
- lib/rails/generators/groonga_client_model/model/templates/application_groonga_record.rb
|
@@ -313,6 +316,7 @@ files:
|
|
313
316
|
- test/apps/rails5/app/helpers/posts_helper.rb
|
314
317
|
- test/apps/rails5/app/jobs/application_job.rb
|
315
318
|
- test/apps/rails5/app/mailers/application_mailer.rb
|
319
|
+
- test/apps/rails5/app/models/age.rb
|
316
320
|
- test/apps/rails5/app/models/application_groonga_record.rb
|
317
321
|
- test/apps/rails5/app/models/post.rb
|
318
322
|
- test/apps/rails5/app/views/layouts/application.html.erb
|
@@ -368,7 +372,9 @@ files:
|
|
368
372
|
- test/apps/rails5/public/favicon.ico
|
369
373
|
- test/apps/rails5/public/robots.txt
|
370
374
|
- test/apps/rails5/test/controllers/posts_controller_test.rb
|
375
|
+
- test/apps/rails5/test/factories/ages.rb
|
371
376
|
- test/apps/rails5/test/factories/posts.rb
|
377
|
+
- test/apps/rails5/test/models/age_test.rb
|
372
378
|
- test/apps/rails5/test/models/post_test.rb
|
373
379
|
- test/apps/rails5/test/test_helper.rb
|
374
380
|
- test/apps/rails5/tmp/cache/assets/sprockets/v3.0/-X/-XSAop9IIcSTUV_xiFS6IsrwsKgzfBrhLSIgb3alOgI.cache
|
@@ -736,6 +742,7 @@ test_files:
|
|
736
742
|
- test/apps/rails5/app/views/posts/index.json.jbuilder
|
737
743
|
- test/apps/rails5/app/views/posts/_post.json.jbuilder
|
738
744
|
- test/apps/rails5/app/views/posts/edit.html.erb
|
745
|
+
- test/apps/rails5/app/models/age.rb
|
739
746
|
- test/apps/rails5/app/models/application_groonga_record.rb
|
740
747
|
- test/apps/rails5/app/models/post.rb
|
741
748
|
- test/apps/rails5/app/helpers/posts_helper.rb
|
@@ -770,8 +777,10 @@ test_files:
|
|
770
777
|
- test/apps/rails5/Gemfile
|
771
778
|
- test/apps/rails5/Gemfile.lock
|
772
779
|
- test/apps/rails5/Rakefile
|
780
|
+
- test/apps/rails5/test/factories/ages.rb
|
773
781
|
- test/apps/rails5/test/factories/posts.rb
|
774
782
|
- test/apps/rails5/test/models/post_test.rb
|
783
|
+
- test/apps/rails5/test/models/age_test.rb
|
775
784
|
- test/apps/rails5/test/controllers/posts_controller_test.rb
|
776
785
|
- test/apps/rails5/test/test_helper.rb
|
777
786
|
- test/apps/rails5/config/secrets.yml
|