groonga-client-model 1.0.0 → 1.0.1
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 +30 -0
- data/groonga-client-model.gemspec +1 -1
- data/lib/groonga_client_model/log_subscriber.rb +1 -3
- data/lib/groonga_client_model/migration.rb +493 -0
- data/lib/groonga_client_model/migrator.rb +240 -0
- data/lib/groonga_client_model/railtie.rb +4 -2
- data/lib/groonga_client_model/railties/groonga.rake +55 -2
- data/lib/groonga_client_model/record.rb +39 -1
- data/lib/groonga_client_model/schema.rb +8 -0
- data/lib/groonga_client_model/schema_loader.rb +4 -9
- data/lib/groonga_client_model/test/groonga_server_runner.rb +19 -3
- data/lib/groonga_client_model/version.rb +1 -1
- data/lib/rails/generators/groonga_client_model/migration/templates/create_table_migration.rb +14 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/delete_config_migration.rb +9 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/migration.rb +12 -0
- data/lib/rails/generators/groonga_client_model/migration/templates/set_config_migration.rb +10 -0
- data/lib/rails/generators/groonga_client_model/migration_generator.rb +125 -0
- data/lib/rails/generators/groonga_client_model/{model/model_generator.rb → model_generator.rb} +18 -4
- data/test/apps/rails4/Gemfile.lock +2 -2
- data/test/apps/rails4/db/groonga/migrate/20170303120517_create_posts.rb +8 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120527_create_terms.rb +7 -0
- data/test/apps/rails4/db/groonga/migrate/20170303120536_create_ages.rb +6 -0
- data/test/apps/rails4/log/development.log +22 -0
- data/test/apps/rails4/log/test.log +1350 -0
- data/test/apps/rails4/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails4/test/tmp/db/groonga/migrate/20170307045825_set_config_alias_column.rb +10 -0
- data/test/apps/rails5/Gemfile.lock +8 -8
- data/test/apps/rails5/db/groonga/migrate/20170301061420_create_posts.rb +8 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115054_create_terms.rb +7 -0
- data/test/apps/rails5/db/groonga/migrate/20170303115135_create_ages.rb +6 -0
- data/test/apps/rails5/log/development.log +350 -0
- data/test/apps/rails5/log/test.log +3260 -0
- data/test/apps/rails5/test/generators/migration_generator_test.rb +103 -0
- data/test/apps/rails5/test/tmp/db/groonga/migrate/20170307081511_remove_title_from_posts.rb +5 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/5C/5Cws9GLWcOju_f3tIpY01qSaj7zkLAU0a2bQmpf7sS8.cache +1 -0
- data/test/apps/rails5/tmp/cache/assets/sprockets/v3.0/XH/XH9pWZvGgK476BpPGID5z8hjzRmGJjtzV0cHBLXhIKc.cache +1 -0
- data/test/unit/fixtures/migrate/20170301061420_create_posts.rb +8 -0
- data/test/unit/fixtures/migrate/20170303115054_create_terms.rb +7 -0
- data/test/unit/fixtures/migrate/20170303115135_create_ages.rb +6 -0
- data/test/unit/migration/test_config.rb +62 -0
- data/test/unit/migration/test_copy.rb +117 -0
- data/test/unit/migration/test_create_table.rb +528 -0
- data/test/unit/migration/test_exist.rb +47 -0
- data/test/unit/migration/test_load.rb +83 -0
- data/test/unit/record/test_active_model.rb +31 -0
- data/test/unit/record/test_readers.rb +45 -0
- data/test/unit/record/test_timestamps.rb +76 -0
- data/test/unit/record/test_validators.rb +295 -0
- data/test/unit/run-test.rb +1 -2
- data/test/unit/test_helper.rb +109 -0
- data/test/unit/test_load_value_generator.rb +8 -7
- data/test/unit/test_migrator.rb +156 -0
- metadata +64 -11
- data/test/apps/rails4/db/schema.grn +0 -9
- data/test/apps/rails5/db/schema.grn +0 -11
- data/test/unit/test_record.rb +0 -345
@@ -1,9 +0,0 @@
|
|
1
|
-
table_create posts TABLE_NO_KEY
|
2
|
-
|
3
|
-
column_create posts title COLUMN_SCALAR ShortText
|
4
|
-
column_create posts body COLUMN_SCALAR Text
|
5
|
-
|
6
|
-
table_create terms TABLE_PAT_KEY ShortText \
|
7
|
-
--default_tokenizer TokenBigram \
|
8
|
-
--normalizer NormalizerAuto
|
9
|
-
column_create terms posts_body COLUMN_INDEX|WITH_POSITION posts body
|
@@ -1,11 +0,0 @@
|
|
1
|
-
table_create posts TABLE_NO_KEY
|
2
|
-
|
3
|
-
column_create posts title COLUMN_SCALAR ShortText
|
4
|
-
column_create posts body COLUMN_SCALAR Text
|
5
|
-
|
6
|
-
table_create terms TABLE_PAT_KEY ShortText \
|
7
|
-
--default_tokenizer TokenBigram \
|
8
|
-
--normalizer NormalizerAuto
|
9
|
-
column_create terms posts_body COLUMN_INDEX|WITH_POSITION posts body
|
10
|
-
|
11
|
-
table_create ages TABLE_HASH_KEY UInt32
|
data/test/unit/test_record.rb
DELETED
@@ -1,345 +0,0 @@
|
|
1
|
-
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License as published by the Free Software Foundation; either
|
6
|
-
# version 2.1 of the License, or (at your option) any later version.
|
7
|
-
#
|
8
|
-
# This library is distributed in the hope that it will be useful,
|
9
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
-
# Lesser General Public License for more details.
|
12
|
-
#
|
13
|
-
# You should have received a copy of the GNU Lesser General Public
|
14
|
-
# License along with this library; if not, write to the Free Software
|
15
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
-
|
17
|
-
class TestRecord < Test::Unit::TestCase
|
18
|
-
Column = Groonga::Client::Response::Schema::Column
|
19
|
-
|
20
|
-
sub_test_case("ActiveModel") do
|
21
|
-
class EmptyModel < GroongaClientModel::Record
|
22
|
-
class << self
|
23
|
-
def columns
|
24
|
-
raw_columns = {
|
25
|
-
"_id" => Column.new(nil, {}),
|
26
|
-
}
|
27
|
-
GroongaClientModel::Schema::Columns.new(nil, raw_columns)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
include ActiveModel::Lint::Tests
|
33
|
-
|
34
|
-
setup do
|
35
|
-
@model = EmptyModel.new
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
sub_test_case("readers") do
|
40
|
-
class Memo < GroongaClientModel::Record
|
41
|
-
class << self
|
42
|
-
def columns
|
43
|
-
GroongaClientModel::Schema::Columns.new(nil, "_id" => {})
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
setup do
|
49
|
-
@memo = Memo.new
|
50
|
-
end
|
51
|
-
|
52
|
-
test "#id" do
|
53
|
-
@memo._id = 29
|
54
|
-
assert_equal(29, @memo.id)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
sub_test_case("validations") do
|
59
|
-
sub_test_case("_key") do
|
60
|
-
class NoKey < GroongaClientModel::Record
|
61
|
-
class << self
|
62
|
-
def columns
|
63
|
-
raw_columns = {
|
64
|
-
"_id" => Column.new(nil, {}),
|
65
|
-
}
|
66
|
-
GroongaClientModel::Schema::Columns.new(nil, raw_columns)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class Key < GroongaClientModel::Record
|
72
|
-
class << self
|
73
|
-
def columns
|
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"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
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)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
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
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|