kintone_rb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/rspec.yml +28 -0
  4. data/.gitignore +20 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +47 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +4 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +361 -0
  12. data/Rakefile +6 -0
  13. data/kintone.gemspec +30 -0
  14. data/lib/kintone/api/guest.rb +44 -0
  15. data/lib/kintone/api.rb +121 -0
  16. data/lib/kintone/command/accessor.rb +109 -0
  17. data/lib/kintone/command/apis.rb +22 -0
  18. data/lib/kintone/command/app.rb +11 -0
  19. data/lib/kintone/command/app_acl.rb +11 -0
  20. data/lib/kintone/command/apps.rb +12 -0
  21. data/lib/kintone/command/bulk_request.rb +12 -0
  22. data/lib/kintone/command/field_acl.rb +11 -0
  23. data/lib/kintone/command/file.rb +15 -0
  24. data/lib/kintone/command/form.rb +11 -0
  25. data/lib/kintone/command/guests.rb +17 -0
  26. data/lib/kintone/command/preview_form.rb +11 -0
  27. data/lib/kintone/command/record.rb +23 -0
  28. data/lib/kintone/command/record_acl.rb +11 -0
  29. data/lib/kintone/command/records.rb +29 -0
  30. data/lib/kintone/command/space.rb +15 -0
  31. data/lib/kintone/command/space_body.rb +11 -0
  32. data/lib/kintone/command/space_guests.rb +11 -0
  33. data/lib/kintone/command/space_members.rb +16 -0
  34. data/lib/kintone/command/space_thread.rb +14 -0
  35. data/lib/kintone/command/template_space.rb +12 -0
  36. data/lib/kintone/command.rb +12 -0
  37. data/lib/kintone/kintone_error.rb +12 -0
  38. data/lib/kintone/query/extension.rb +23 -0
  39. data/lib/kintone/query.rb +152 -0
  40. data/lib/kintone/type/extension/enumerable.rb +5 -0
  41. data/lib/kintone/type/extension/hash.rb +5 -0
  42. data/lib/kintone/type/extension/object.rb +5 -0
  43. data/lib/kintone/type/record.rb +11 -0
  44. data/lib/kintone/type.rb +6 -0
  45. data/lib/kintone/version.rb +3 -0
  46. data/lib/kintone_rb.rb +7 -0
  47. data/spec/kintone/api/guest_spec.rb +289 -0
  48. data/spec/kintone/api_spec.rb +566 -0
  49. data/spec/kintone/command/apis_spec.rb +179 -0
  50. data/spec/kintone/command/app_acl_spec.rb +43 -0
  51. data/spec/kintone/command/app_spec.rb +54 -0
  52. data/spec/kintone/command/apps_spec.rb +90 -0
  53. data/spec/kintone/command/bulk_request_spec.rb +92 -0
  54. data/spec/kintone/command/field_acl_spec.rb +47 -0
  55. data/spec/kintone/command/file_spec.rb +65 -0
  56. data/spec/kintone/command/form_spec.rb +47 -0
  57. data/spec/kintone/command/guests_spec.rb +107 -0
  58. data/spec/kintone/command/preview_form_spec.rb +30 -0
  59. data/spec/kintone/command/record_acl_spec.rb +48 -0
  60. data/spec/kintone/command/record_spec.rb +210 -0
  61. data/spec/kintone/command/records_spec.rb +463 -0
  62. data/spec/kintone/command/space_body_spec.rb +47 -0
  63. data/spec/kintone/command/space_guests_spec.rb +55 -0
  64. data/spec/kintone/command/space_members_spec.rb +117 -0
  65. data/spec/kintone/command/space_spec.rb +86 -0
  66. data/spec/kintone/command/space_thread_spec.rb +77 -0
  67. data/spec/kintone/command/template_space_spec.rb +59 -0
  68. data/spec/kintone/kintone_error_spec.rb +93 -0
  69. data/spec/kintone/query_spec.rb +506 -0
  70. data/spec/kintone/type/record_spec.rb +38 -0
  71. data/spec/spec_helper.rb +4 -0
  72. metadata +250 -0
@@ -0,0 +1,506 @@
1
+ require 'spec_helper'
2
+ require 'kintone/query'
3
+
4
+ describe Kintone::Query do
5
+ describe '#to_s' do
6
+ subject { target.to_s }
7
+
8
+ context '==', 'with field' do
9
+ where(:target, :result) do
10
+ [
11
+ [Kintone::Query.new { field(:text) == '"Hello, world."' }, 'text = "Hello, world."'],
12
+ [Kintone::Query.new { field(:text) == 'Hello, world.' }, 'text = "Hello, world."'],
13
+ [Kintone::Query.new { field('作成日時') == now }, '作成日時 = NOW()'],
14
+ [Kintone::Query.new { field('作成日時') == today }, '作成日時 = TODAY()'],
15
+ [Kintone::Query.new { field('作成日時') == this_month }, '作成日時 = THIS_MONTH()'],
16
+ [Kintone::Query.new { field('作成日時') == last_month }, '作成日時 = LAST_MONTH()'],
17
+ [Kintone::Query.new { field('作成日時') == this_year }, '作成日時 = THIS_YEAR()'],
18
+ [Kintone::Query.new { field(:number) == 100 }, 'number = 100']
19
+ ]
20
+ end
21
+
22
+ with_them do
23
+ it { expect(subject).to eq result }
24
+ end
25
+ end
26
+
27
+ context '==', 'with f' do
28
+ where(:target, :result) do
29
+ [
30
+ [Kintone::Query.new { f(:text) == '"Hello, world."' }, 'text = "Hello, world."'],
31
+ [Kintone::Query.new { f(:text) == 'Hello, world.' }, 'text = "Hello, world."'],
32
+ [Kintone::Query.new { f('作成日時') == now }, '作成日時 = NOW()'],
33
+ [Kintone::Query.new { f('作成日時') == today }, '作成日時 = TODAY()'],
34
+ [Kintone::Query.new { f('作成日時') == this_month }, '作成日時 = THIS_MONTH()'],
35
+ [Kintone::Query.new { f('作成日時') == last_month }, '作成日時 = LAST_MONTH()'],
36
+ [Kintone::Query.new { f('作成日時') == this_year }, '作成日時 = THIS_YEAR()'],
37
+ [Kintone::Query.new { f(:number) == 100 }, 'number = 100']
38
+ ]
39
+ end
40
+
41
+ with_them do
42
+ it { expect(subject).to eq result }
43
+ end
44
+ end
45
+
46
+ context '!=', 'with field' do
47
+ where(:target, :result) do
48
+ [
49
+ [Kintone::Query.new { field(:text) != '"Hello, world."' }, 'text != "Hello, world."'],
50
+ [Kintone::Query.new { field(:text) != 'Hello, world.' }, 'text != "Hello, world."'],
51
+ [Kintone::Query.new { field('作成日時') != now }, '作成日時 != NOW()'],
52
+ [Kintone::Query.new { field('作成日時') != today }, '作成日時 != TODAY()'],
53
+ [Kintone::Query.new { field('作成日時') != this_month }, '作成日時 != THIS_MONTH()'],
54
+ [Kintone::Query.new { field('作成日時') != last_month }, '作成日時 != LAST_MONTH()'],
55
+ [Kintone::Query.new { field('作成日時') != this_year }, '作成日時 != THIS_YEAR()'],
56
+ [Kintone::Query.new { field(:number) != 100 }, 'number != 100']
57
+ ]
58
+ end
59
+
60
+ with_them do
61
+ it { expect(subject).to eq result }
62
+ end
63
+ end
64
+
65
+ context '!=', 'with f' do
66
+ where(:target, :result) do
67
+ [
68
+ [Kintone::Query.new { f(:text) != '"Hello, world."' }, 'text != "Hello, world."'],
69
+ [Kintone::Query.new { f(:text) != 'Hello, world.' }, 'text != "Hello, world."'],
70
+ [Kintone::Query.new { f('作成日時') != now }, '作成日時 != NOW()'],
71
+ [Kintone::Query.new { f('作成日時') != today }, '作成日時 != TODAY()'],
72
+ [Kintone::Query.new { f('作成日時') != this_month }, '作成日時 != THIS_MONTH()'],
73
+ [Kintone::Query.new { f('作成日時') != last_month }, '作成日時 != LAST_MONTH()'],
74
+ [Kintone::Query.new { f('作成日時') != this_year }, '作成日時 != THIS_YEAR()'],
75
+ [Kintone::Query.new { f(:number) != 100 }, 'number != 100']
76
+ ]
77
+ end
78
+
79
+ with_them do
80
+ it { expect(subject).to eq result }
81
+ end
82
+ end
83
+
84
+ context '>', 'with field' do
85
+ where(:target, :result) do
86
+ [
87
+ [Kintone::Query.new { field(:text) > '"Hello, world."' }, 'text > "Hello, world."'],
88
+ [Kintone::Query.new { field(:text) > 'Hello, world.' }, 'text > "Hello, world."'],
89
+ [Kintone::Query.new { field('作成日時') > now }, '作成日時 > NOW()'],
90
+ [Kintone::Query.new { field('作成日時') > today }, '作成日時 > TODAY()'],
91
+ [Kintone::Query.new { field('作成日時') > this_month }, '作成日時 > THIS_MONTH()'],
92
+ [Kintone::Query.new { field('作成日時') > last_month }, '作成日時 > LAST_MONTH()'],
93
+ [Kintone::Query.new { field('作成日時') > this_year }, '作成日時 > THIS_YEAR()'],
94
+ [Kintone::Query.new { field(:number) > 100 }, 'number > 100']
95
+ ]
96
+ end
97
+
98
+ with_them do
99
+ it { expect(subject).to eq result }
100
+ end
101
+ end
102
+
103
+ context '>', 'with f' do
104
+ where(:target, :result) do
105
+ [
106
+ [Kintone::Query.new { f(:text) > '"Hello, world."' }, 'text > "Hello, world."'],
107
+ [Kintone::Query.new { f(:text) > 'Hello, world.' }, 'text > "Hello, world."'],
108
+ [Kintone::Query.new { f('作成日時') > now }, '作成日時 > NOW()'],
109
+ [Kintone::Query.new { f('作成日時') > today }, '作成日時 > TODAY()'],
110
+ [Kintone::Query.new { f('作成日時') > this_month }, '作成日時 > THIS_MONTH()'],
111
+ [Kintone::Query.new { f('作成日時') > last_month }, '作成日時 > LAST_MONTH()'],
112
+ [Kintone::Query.new { f('作成日時') > this_year }, '作成日時 > THIS_YEAR()'],
113
+ [Kintone::Query.new { f(:number) > 100 }, 'number > 100']
114
+ ]
115
+ end
116
+
117
+ with_them do
118
+ it { expect(subject).to eq result }
119
+ end
120
+ end
121
+
122
+ context '<', 'with field' do
123
+ where(:target, :result) do
124
+ [
125
+ [Kintone::Query.new { field(:text) < '"Hello, world."' }, 'text < "Hello, world."'],
126
+ [Kintone::Query.new { field(:text) < 'Hello, world.' }, 'text < "Hello, world."'],
127
+ [Kintone::Query.new { field('作成日時') < now }, '作成日時 < NOW()'],
128
+ [Kintone::Query.new { field('作成日時') < today }, '作成日時 < TODAY()'],
129
+ [Kintone::Query.new { field('作成日時') < this_month }, '作成日時 < THIS_MONTH()'],
130
+ [Kintone::Query.new { field('作成日時') < last_month }, '作成日時 < LAST_MONTH()'],
131
+ [Kintone::Query.new { field('作成日時') < this_year }, '作成日時 < THIS_YEAR()'],
132
+ [Kintone::Query.new { field(:number) < 100 }, 'number < 100']
133
+ ]
134
+ end
135
+
136
+ with_them do
137
+ it { expect(subject).to eq result }
138
+ end
139
+ end
140
+
141
+ context '<', 'with f' do
142
+ where(:target, :result) do
143
+ [
144
+ [Kintone::Query.new { f(:text) < '"Hello, world."' }, 'text < "Hello, world."'],
145
+ [Kintone::Query.new { f(:text) < 'Hello, world.' }, 'text < "Hello, world."'],
146
+ [Kintone::Query.new { f('作成日時') < now }, '作成日時 < NOW()'],
147
+ [Kintone::Query.new { f('作成日時') < today }, '作成日時 < TODAY()'],
148
+ [Kintone::Query.new { f('作成日時') < this_month }, '作成日時 < THIS_MONTH()'],
149
+ [Kintone::Query.new { f('作成日時') < last_month }, '作成日時 < LAST_MONTH()'],
150
+ [Kintone::Query.new { f('作成日時') < this_year }, '作成日時 < THIS_YEAR()'],
151
+ [Kintone::Query.new { f(:number) < 100 }, 'number < 100']
152
+ ]
153
+ end
154
+
155
+ with_them do
156
+ it { expect(subject).to eq result }
157
+ end
158
+ end
159
+
160
+ context '>=', 'with field' do
161
+ where(:target, :result) do
162
+ [
163
+ [Kintone::Query.new { field(:text) >= '"Hello, world."' }, 'text >= "Hello, world."'],
164
+ [Kintone::Query.new { field(:text) >= 'Hello, world.' }, 'text >= "Hello, world."'],
165
+ [Kintone::Query.new { field('作成日時') >= now }, '作成日時 >= NOW()'],
166
+ [Kintone::Query.new { field('作成日時') >= today }, '作成日時 >= TODAY()'],
167
+ [Kintone::Query.new { field('作成日時') >= this_month }, '作成日時 >= THIS_MONTH()'],
168
+ [Kintone::Query.new { field('作成日時') >= last_month }, '作成日時 >= LAST_MONTH()'],
169
+ [Kintone::Query.new { field('作成日時') >= this_year }, '作成日時 >= THIS_YEAR()'],
170
+ [Kintone::Query.new { field(:number) >= 100 }, 'number >= 100']
171
+ ]
172
+ end
173
+
174
+ with_them do
175
+ it { expect(subject).to eq result }
176
+ end
177
+ end
178
+
179
+ context '>=', 'with f' do
180
+ where(:target, :result) do
181
+ [
182
+ [Kintone::Query.new { f(:text) >= '"Hello, world."' }, 'text >= "Hello, world."'],
183
+ [Kintone::Query.new { f(:text) >= 'Hello, world.' }, 'text >= "Hello, world."'],
184
+ [Kintone::Query.new { f('作成日時') >= now }, '作成日時 >= NOW()'],
185
+ [Kintone::Query.new { f('作成日時') >= today }, '作成日時 >= TODAY()'],
186
+ [Kintone::Query.new { f('作成日時') >= this_month }, '作成日時 >= THIS_MONTH()'],
187
+ [Kintone::Query.new { f('作成日時') >= last_month }, '作成日時 >= LAST_MONTH()'],
188
+ [Kintone::Query.new { f('作成日時') >= this_year }, '作成日時 >= THIS_YEAR()'],
189
+ [Kintone::Query.new { f(:number) >= 100 }, 'number >= 100']
190
+ ]
191
+ end
192
+
193
+ with_them do
194
+ it { expect(subject).to eq result }
195
+ end
196
+ end
197
+
198
+ context '<=', 'with field' do
199
+ where(:target, :result) do
200
+ [
201
+ [Kintone::Query.new { field(:text) <= '"Hello, world."' }, 'text <= "Hello, world."'],
202
+ [Kintone::Query.new { field(:text) <= 'Hello, world.' }, 'text <= "Hello, world."'],
203
+ [Kintone::Query.new { field('作成日時') <= now }, '作成日時 <= NOW()'],
204
+ [Kintone::Query.new { field('作成日時') <= today }, '作成日時 <= TODAY()'],
205
+ [Kintone::Query.new { field('作成日時') <= this_month }, '作成日時 <= THIS_MONTH()'],
206
+ [Kintone::Query.new { field('作成日時') <= last_month }, '作成日時 <= LAST_MONTH()'],
207
+ [Kintone::Query.new { field('作成日時') <= this_year }, '作成日時 <= THIS_YEAR()'],
208
+ [Kintone::Query.new { field(:number) <= 100 }, 'number <= 100']
209
+ ]
210
+ end
211
+
212
+ with_them do
213
+ it { expect(subject).to eq result }
214
+ end
215
+ end
216
+
217
+ context '<=', 'with f' do
218
+ where(:target, :result) do
219
+ [
220
+ [Kintone::Query.new { f(:text) <= '"Hello, world."' }, 'text <= "Hello, world."'],
221
+ [Kintone::Query.new { f(:text) <= 'Hello, world.' }, 'text <= "Hello, world."'],
222
+ [Kintone::Query.new { f('作成日時') <= now }, '作成日時 <= NOW()'],
223
+ [Kintone::Query.new { f('作成日時') <= today }, '作成日時 <= TODAY()'],
224
+ [Kintone::Query.new { f('作成日時') <= this_month }, '作成日時 <= THIS_MONTH()'],
225
+ [Kintone::Query.new { f('作成日時') <= last_month }, '作成日時 <= LAST_MONTH()'],
226
+ [Kintone::Query.new { f('作成日時') <= this_year }, '作成日時 <= THIS_YEAR()'],
227
+ [Kintone::Query.new { f(:number) <= 100 }, 'number <= 100']
228
+ ]
229
+ end
230
+
231
+ with_them do
232
+ it { expect(subject).to eq result }
233
+ end
234
+ end
235
+
236
+ context 'in', 'with field' do
237
+ where(:target, :result) do
238
+ [
239
+ [Kintone::Query.new { field(:dropdown).in(['"A"', '"B"']) }, 'dropdown in ("A", "B")'],
240
+ [Kintone::Query.new { field(:dropdown).in(%w(A B)) }, 'dropdown in ("A", "B")'],
241
+ [Kintone::Query.new { field(:dropdown).in([:A, :B]) }, 'dropdown in ("A", "B")'],
242
+ [Kintone::Query.new { field(:dropdown).in([100, 200]) }, 'dropdown in (100, 200)'],
243
+ [Kintone::Query.new { field('作成者').in([login_user]) }, '作成者 in (LOGINUSER())']
244
+ ]
245
+ end
246
+
247
+ with_them do
248
+ it { expect(subject).to eq result }
249
+ end
250
+ end
251
+
252
+ context 'in', 'with f' do
253
+ where(:target, :result) do
254
+ [
255
+ [
256
+ Kintone::Query.new { f(:dropdown).in(['"A"', '"B"']) },
257
+ 'dropdown in ("A", "B")'
258
+ ],
259
+ [
260
+ Kintone::Query.new { f(:dropdown).in(%w(A B)) },
261
+ 'dropdown in ("A", "B")'
262
+ ],
263
+ [
264
+ Kintone::Query.new { f(:dropdown).in([:A, :B]) },
265
+ 'dropdown in ("A", "B")'
266
+ ],
267
+ [
268
+ Kintone::Query.new { f(:dropdown).in([100, 200]) },
269
+ 'dropdown in (100, 200)'
270
+ ],
271
+ [
272
+ Kintone::Query.new { f('作成者').in([login_user]) },
273
+ '作成者 in (LOGINUSER())'
274
+ ],
275
+ [
276
+ Kintone::Query.new { field('組織').in([primary_organization]) },
277
+ '組織 in (PRIMARY_ORGANIZATION())'
278
+ ]
279
+ ]
280
+ end
281
+
282
+ with_them do
283
+ it { expect(subject).to eq result }
284
+ end
285
+ end
286
+
287
+ context 'not in', 'with field' do
288
+ where(:target, :result) do
289
+ [
290
+ [
291
+ Kintone::Query.new { field(:dropdown).not_in(['"A"', '"B"']) },
292
+ 'dropdown not in ("A", "B")'
293
+ ],
294
+ [
295
+ Kintone::Query.new { field(:dropdown).not_in(%w(A B)) },
296
+ 'dropdown not in ("A", "B")'
297
+ ],
298
+ [
299
+ Kintone::Query.new { field(:dropdown).not_in([:A, :B]) },
300
+ 'dropdown not in ("A", "B")'
301
+ ],
302
+ [
303
+ Kintone::Query.new { field(:dropdown).not_in([100, 200]) },
304
+ 'dropdown not in (100, 200)'
305
+ ],
306
+ [
307
+ Kintone::Query.new { field('作成者').not_in([login_user]) },
308
+ '作成者 not in (LOGINUSER())'
309
+ ],
310
+ [
311
+ Kintone::Query.new { field('組織').not_in([primary_organization]) },
312
+ '組織 not in (PRIMARY_ORGANIZATION())'
313
+ ]
314
+ ]
315
+ end
316
+
317
+ with_them do
318
+ it { expect(subject).to eq result }
319
+ end
320
+ end
321
+
322
+ context 'not in', 'with field' do
323
+ where(:target, :result) do
324
+ [
325
+ [
326
+ Kintone::Query.new { f(:dropdown).not_in(['"A"', '"B"']) },
327
+ 'dropdown not in ("A", "B")'
328
+ ],
329
+ [
330
+ Kintone::Query.new { f(:dropdown).not_in(%w(A B)) },
331
+ 'dropdown not in ("A", "B")'
332
+ ],
333
+ [
334
+ Kintone::Query.new { f(:dropdown).not_in([:A, :B]) },
335
+ 'dropdown not in ("A", "B")'
336
+ ],
337
+ [
338
+ Kintone::Query.new { f(:dropdown).not_in([100, 200]) },
339
+ 'dropdown not in (100, 200)'
340
+ ],
341
+ [
342
+ Kintone::Query.new { f('作成者').not_in([login_user]) },
343
+ '作成者 not in (LOGINUSER())'
344
+ ]
345
+ ]
346
+ end
347
+
348
+ with_them do
349
+ it { expect(subject).to eq result }
350
+ end
351
+ end
352
+
353
+ context 'like', 'with field' do
354
+ where(:target, :result) do
355
+ [
356
+ [Kintone::Query.new { field(:text).like('Hello') }, 'text like "Hello"'],
357
+ [Kintone::Query.new { field(:text).like('"Hello"') }, 'text like "Hello"'],
358
+ [Kintone::Query.new { field(:text).like(:Hello) }, 'text like "Hello"']
359
+ ]
360
+ end
361
+
362
+ with_them do
363
+ it { expect(subject).to eq result }
364
+ end
365
+ end
366
+
367
+ context 'like', 'with f' do
368
+ where(:target, :result) do
369
+ [
370
+ [Kintone::Query.new { f(:text).like('Hello') }, 'text like "Hello"'],
371
+ [Kintone::Query.new { f(:text).like('"Hello"') }, 'text like "Hello"'],
372
+ [Kintone::Query.new { f(:text).like(:Hello) }, 'text like "Hello"']
373
+ ]
374
+ end
375
+
376
+ with_them do
377
+ it { expect(subject).to eq result }
378
+ end
379
+ end
380
+
381
+ context 'not like', 'with field' do
382
+ where(:target, :result) do
383
+ [
384
+ [Kintone::Query.new { field(:text).not_like('Hello') }, 'text not like "Hello"'],
385
+ [Kintone::Query.new { field(:text).not_like('"Hello"') }, 'text not like "Hello"'],
386
+ [Kintone::Query.new { field(:text).not_like(:Hello) }, 'text not like "Hello"']
387
+ ]
388
+ end
389
+
390
+ with_them do
391
+ it { expect(subject).to eq result }
392
+ end
393
+ end
394
+
395
+ context 'not like', 'with f' do
396
+ where(:target, :result) do
397
+ [
398
+ [Kintone::Query.new { f(:text).not_like('Hello') }, 'text not like "Hello"'],
399
+ [Kintone::Query.new { f(:text).not_like('"Hello"') }, 'text not like "Hello"'],
400
+ [Kintone::Query.new { f(:text).not_like(:Hello) }, 'text not like "Hello"']
401
+ ]
402
+ end
403
+
404
+ with_them do
405
+ it { expect(subject).to eq result }
406
+ end
407
+ end
408
+
409
+ context 'and!' do
410
+ let(:target) do
411
+ Kintone::Query.new do
412
+ field(:text).like 'Hello'
413
+ and!
414
+ field(:number) > 100
415
+ end
416
+ end
417
+
418
+ def result
419
+ 'text like "Hello" and number > 100'
420
+ end
421
+
422
+ it { expect(subject).to eq result }
423
+ end
424
+
425
+ context 'or!' do
426
+ let(:target) do
427
+ Kintone::Query.new do
428
+ field(:text).like 'Hello'
429
+ or!
430
+ field(:number) > 100
431
+ end
432
+ end
433
+
434
+ def result
435
+ 'text like "Hello" or number > 100'
436
+ end
437
+
438
+ it { expect(subject).to eq result }
439
+ end
440
+
441
+ context 'precede' do
442
+ let(:target) do
443
+ Kintone::Query.new do
444
+ precede do
445
+ field(:text).like 'Hello'
446
+ or!
447
+ field(:number) > 100
448
+ end
449
+ and!
450
+ precede do
451
+ field(:text2).not_like 'Hello'
452
+ and!
453
+ field(:number2) <= 100
454
+ end
455
+ end
456
+ end
457
+
458
+ def result
459
+ '(text like "Hello" or number > 100) and (text2 not like "Hello" and number2 <= 100)'
460
+ end
461
+
462
+ it { expect(subject).to eq result }
463
+ end
464
+
465
+ context 'order by' do
466
+ where(:target, :result) do
467
+ [
468
+ [Kintone::Query.new { order_by(:record_id, :asc) }, 'order by record_id asc'],
469
+ [Kintone::Query.new { order_by(:record_id, :desc) }, 'order by record_id desc'],
470
+ [Kintone::Query.new { order_by(:record_id) }, 'order by record_id asc'],
471
+ [Kintone::Query.new { order_by('作成日時', :desc) }, 'order by 作成日時 desc']
472
+ ]
473
+ end
474
+
475
+ with_them do
476
+ it { expect(subject).to eq result }
477
+ end
478
+ end
479
+
480
+ context 'limit' do
481
+ where(:target, :result) do
482
+ [
483
+ [Kintone::Query.new { limit(20) }, 'limit 20'],
484
+ [Kintone::Query.new { limit('20') }, 'limit 20']
485
+ ]
486
+ end
487
+
488
+ with_them do
489
+ it { expect(subject).to eq result }
490
+ end
491
+ end
492
+
493
+ context 'offset' do
494
+ where(:target, :result) do
495
+ [
496
+ [Kintone::Query.new { offset(30) }, 'offset 30'],
497
+ [Kintone::Query.new { offset('30') }, 'offset 30']
498
+ ]
499
+ end
500
+
501
+ with_them do
502
+ it { expect(subject).to eq result }
503
+ end
504
+ end
505
+ end
506
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'kintone/type/record'
3
+
4
+ describe Kintone::Type::Record do
5
+ let(:target) { Kintone::Type::Record.new }
6
+
7
+ describe '#to_kitnone' do
8
+ subject { target.to_kintone }
9
+
10
+ context 'データが登録されているとき' do
11
+ before(:each) do
12
+ target[:a] = 1
13
+ target[:b] = 2
14
+ end
15
+
16
+ it { expect(subject).to match a: { value: 1 }, b: { value: 2 } }
17
+ end
18
+
19
+ context 'データが登録されてないとき' do
20
+ it { expect(subject).to be_empty }
21
+ end
22
+
23
+ context 'initializeで初期値を指定したとき' do
24
+ let(:target) { Kintone::Type::Record.new(default) }
25
+
26
+ where(:default, :result) do
27
+ [
28
+ [{ a: 1, b: 2 }, { a: { value: 1 }, b: { value: 2 } }],
29
+ [[[:a, 1], [:b, 2]], {}]
30
+ ]
31
+ end
32
+
33
+ with_them do
34
+ it { expect(subject).to match result }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'kintone_rb'
3
+ require 'webmock/rspec'
4
+ require 'rspec-parameterized'