rails_kvs_driver 0.3.0 → 0.3.1

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: 3c26761a67864a1eec96c0788df35795c30439d7
4
- data.tar.gz: d0aa335dac73aeb03151d00684a9c502189c6006
3
+ metadata.gz: e9cecbdf9fd2d6eae6091172f629c35f64fb205b
4
+ data.tar.gz: b70cb0ae212875e2e9ffd103b9195400f670915b
5
5
  SHA512:
6
- metadata.gz: b0828ce5858f49a0fa9228ffda88f394c06db0e7287c5cf212b9f7dc3ff9e2c3c26468a75d10999d9614630c32f92dff8190b4d4479c72b5b4eb1b355f680a7d
7
- data.tar.gz: cbc5f444e47da2c704760e39f6093440469da71d748c3a38ba1a9e08bc95b8eed9a846b8f39be502bb86cf617fc0f1923a83cd7d0067898438a2b02a59376eb2
6
+ metadata.gz: dbe09a27ccc8dc9b3e25958fb5d204b9b5f037b909b5b68d697f0cd1e8567999dc497c45e7e8e79b206ddd2bdbffe0bb79affe0affbb32e12fb0ea33fe9cdd37
7
+ data.tar.gz: 82b0b5561d01f73e7c4010c03a808b883193335779b85150e6c373cc0492684829477c67d1dcef7dbb700231034eaf65c67de11f849fe712d9897136b85f5d06
@@ -66,7 +66,7 @@ module RailsKvsDriver
66
66
  # @param value [String] value
67
67
  # @return [Boolean] result
68
68
  def include?(value)
69
- each do |list_value|
69
+ each do |index, list_value|
70
70
  return true if list_value == value
71
71
  end
72
72
  return false
@@ -81,7 +81,7 @@ module RailsKvsDriver
81
81
  # when the key doesn't exist, it's made newly list.
82
82
  #
83
83
  # @param value [String] value.
84
- def push_fist(value)
84
+ def push_first(value)
85
85
  @driver_instance.push_list_first(@key, value)
86
86
  end
87
87
 
@@ -1,3 +1,3 @@
1
1
  module RailsKvsDriver
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -40,23 +40,6 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
40
40
  end
41
41
  end
42
42
 
43
- it 'call add_sorted_set' do
44
- driver_class::session(driver_config) do |kvs|
45
- expect{
46
- kvs.add_sorted_set('example', 'element', 1)
47
- }.to change{ kvs.get_sorted_set_keys.length }.by(1)
48
- end
49
- end
50
-
51
- it 'call count_sorted_set_member' do
52
- driver_class::session(driver_config) do |kvs|
53
- kvs.add_sorted_set('example', 'element1', 5)
54
- kvs.add_sorted_set('example', 'element2', 5)
55
- kvs.add_sorted_set('example', 'element3', 5)
56
- expect(kvs.count_sorted_set_member('example')).to eq(3)
57
- end
58
- end
59
-
60
43
  it 'call delete' do
61
44
  driver_class::session(driver_config) do |kvs|
62
45
  kvs['example'] = 'nico-nico'
@@ -78,6 +61,148 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
78
61
  end
79
62
  end
80
63
 
64
+ it 'call has_key?' do
65
+ driver_class::session(driver_config) do |kvs|
66
+ kvs['example'] = 'nico-nico'
67
+
68
+ expect(kvs.has_key?('example')).to be_true
69
+ expect(kvs.has_key?('nothing key')).to be_false
70
+ end
71
+ end
72
+
73
+ it 'call keys' do
74
+ driver_class::session(driver_config) do |kvs|
75
+ kvs['example0'] = 'nico-nico'
76
+ kvs['example1'] = 'nico-nico'
77
+ kvs.add_sorted_set('example_ss', 'element5', 5)
78
+
79
+ expect(kvs.keys.length).to eq(2)
80
+ end
81
+ end
82
+
83
+
84
+ #--------------------
85
+ # list (same as list of redis. refer to redis.)
86
+ #--------------------
87
+
88
+ it 'call count_list_value' do
89
+ driver_class::session(driver_config) do |kvs|
90
+ kvs.push_list_last('anime', 'nyaruko')
91
+ kvs.push_list_last('anime', 'kinmoza')
92
+
93
+ expect(kvs.count_list_value('anime')).to eq(2)
94
+ end
95
+ end
96
+
97
+ it 'call delete_list_value' do
98
+ driver_class::session(driver_config) do |kvs|
99
+ kvs.push_list_last('anime', 'nyaruko')
100
+ kvs.push_list_last('anime', 'kinmoza')
101
+ kvs.push_list_last('anime', 'hoge')
102
+
103
+ expect{
104
+ kvs.delete_list_value('anime', 'hoge')
105
+ }.to change{ kvs.count_list_value('anime') }.by(-1)
106
+ expect(kvs.get_list_values('anime').include?('hoge')).to be_false
107
+ end
108
+ end
109
+
110
+ it 'call delete_list_value_at 0' do
111
+ driver_class::session(driver_config) do |kvs|
112
+ kvs.push_list_last('anime', 'hoge')
113
+ kvs.push_list_last('anime', 'nyaruko')
114
+ kvs.push_list_last('anime', 'kinmoza')
115
+
116
+ expect{
117
+ kvs.delete_list_value_at('anime', 0)
118
+ }.to change{ kvs.count_list_value('anime') }.by(-1)
119
+ expect(kvs.get_list_values('anime').include?('hoge')).to be_false
120
+ end
121
+ end
122
+
123
+ it 'call get_list_keys' do
124
+ driver_class::session(driver_config) do |kvs|
125
+ kvs.push_list_last('anime', 'nyaruko')
126
+ kvs.push_list_last('anime', 'kinmoza')
127
+
128
+ expect(kvs.get_list_keys.length).to eq(1)
129
+ end
130
+ end
131
+
132
+ it 'call get_list_value' do
133
+ driver_class::session(driver_config) do |kvs|
134
+ kvs.push_list_last('anime', 'nyaruko')
135
+ kvs.push_list_last('anime', 'kinmoza')
136
+
137
+ expect(kvs.get_list_value('anime', 0)).to eq('nyaruko')
138
+ end
139
+ end
140
+
141
+ it 'call get_list_values' do
142
+ driver_class::session(driver_config) do |kvs|
143
+ kvs.push_list_last('anime', 'nyaruko')
144
+ kvs.push_list_last('anime', 'kinmoza')
145
+
146
+ expect(kvs.get_list_values('anime').length).to eq(2)
147
+ end
148
+ end
149
+
150
+ it 'call push_list_*' do
151
+ driver_class::session(driver_config) do |kvs|
152
+ kvs.push_list_last('anime', 'nyaruko')
153
+ kvs.push_list_last('anime', 'kinmoza')
154
+ kvs.push_list_first('anime', 'inuhasa')
155
+
156
+ expect(kvs.get_list_value('anime', 2)).to eq('kinmoza')
157
+ expect(kvs.get_list_value('anime', 0)).to eq('inuhasa')
158
+ end
159
+ end
160
+
161
+ it 'call pop_list_*' do
162
+ driver_class::session(driver_config) do |kvs|
163
+ kvs.push_list_last('anime', 'nyaruko')
164
+ kvs.push_list_last('anime', 'kinmoza')
165
+ kvs.push_list_first('anime', 'inuhasa')
166
+
167
+ expect{
168
+ expect(kvs.pop_list_first('anime')).to eq('inuhasa')
169
+ expect(kvs.pop_list_last('anime')).to eq('kinmoza')
170
+ }.to change{ kvs.count_list_value('anime') }.by(-2)
171
+ end
172
+ end
173
+
174
+ it 'call pop_list_*' do
175
+ driver_class::session(driver_config) do |kvs|
176
+ kvs.push_list_last('anime', 'nyaruko')
177
+ kvs.push_list_last('anime', 'kinmoza')
178
+
179
+ kvs.set_list_value('anime', 1, 'inuhasa')
180
+
181
+ expect(kvs.get_list_value('anime', 1)).to eq('inuhasa')
182
+ end
183
+ end
184
+
185
+ #--------------------
186
+ # sorted set (same as sorted set of redis. refer to redis.)
187
+ #--------------------
188
+
189
+ it 'call add_sorted_set' do
190
+ driver_class::session(driver_config) do |kvs|
191
+ expect{
192
+ kvs.add_sorted_set('example', 'element', 1)
193
+ }.to change{ kvs.get_sorted_set_keys.length }.by(1)
194
+ end
195
+ end
196
+
197
+ it 'call count_sorted_set_member' do
198
+ driver_class::session(driver_config) do |kvs|
199
+ kvs.add_sorted_set('example', 'element1', 5)
200
+ kvs.add_sorted_set('example', 'element2', 5)
201
+ kvs.add_sorted_set('example', 'element3', 5)
202
+ expect(kvs.count_sorted_set_member('example')).to eq(3)
203
+ end
204
+ end
205
+
81
206
  it 'call get_sorted_set' do
82
207
  driver_class::session(driver_config) do |kvs|
83
208
  kvs.add_sorted_set('example', 'element1', 1)
@@ -121,25 +246,6 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
121
246
  end
122
247
  end
123
248
 
124
- it 'call has_key?' do
125
- driver_class::session(driver_config) do |kvs|
126
- kvs['example'] = 'nico-nico'
127
-
128
- expect(kvs.has_key?('example')).to be_true
129
- expect(kvs.has_key?('nothing key')).to be_false
130
- end
131
- end
132
-
133
- it 'call keys' do
134
- driver_class::session(driver_config) do |kvs|
135
- kvs['example0'] = 'nico-nico'
136
- kvs['example1'] = 'nico-nico'
137
- kvs.add_sorted_set('example_ss', 'element5', 5)
138
-
139
- expect(kvs.keys.length).to eq(2)
140
- end
141
- end
142
-
143
249
  it 'call remove_sorted_set' do
144
250
  driver_class::session(driver_config) do |kvs|
145
251
  kvs.add_sorted_set('example', 'element', 1)
@@ -190,6 +296,128 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
190
296
  end
191
297
  end
192
298
 
299
+ context 'lists' do
300
+ before(:each) do
301
+ driver_class::session(driver_config) do |kvs|
302
+ kvs.push_list_last('anime', 'nyaruko')
303
+ kvs.push_list_last('anime', 'haganai')
304
+ end
305
+ end
306
+
307
+ it 'call[]' do
308
+ driver_class::session(driver_config) do |kvs|
309
+ expect(kvs.lists['anime'].instance_of?(RailsKvsDriver::Lists::List)).to be_true
310
+ end
311
+ end
312
+
313
+ it 'call []=' do
314
+ driver_class::session(driver_config) do |kvs|
315
+
316
+ expect{
317
+ kvs.lists['fruit'] = [:apple, :orange]
318
+ }.to change{
319
+ kvs.lists.length
320
+ }.by(1)
321
+
322
+ expect(kvs.lists['fruit'].length).to eq(2)
323
+ end
324
+ end
325
+
326
+ it 'call delete' do
327
+ driver_class::session(driver_config) do |kvs|
328
+ expect{kvs.lists.delete('anime')}.to change{kvs.lists.length}.by(-1)
329
+ end
330
+ end
331
+
332
+ it 'call each' do
333
+ driver_class::session(driver_config) do |kvs|
334
+ kvs.lists.each do |key|
335
+ expect(key).to eq('anime')
336
+ end
337
+ end
338
+ end
339
+
340
+ it 'call keys' do
341
+ driver_class::session(driver_config) do |kvs|
342
+ expect(kvs.lists.keys.length).to eq(1)
343
+ end
344
+ end
345
+
346
+ it 'call length' do
347
+ driver_class::session(driver_config) do |kvs|
348
+ expect(kvs.lists.length).to eq(1)
349
+ end
350
+ end
351
+
352
+ context 'lists' do
353
+ it 'call[]' do
354
+ driver_class::session(driver_config) do |kvs|
355
+ expect(kvs.lists['anime'][0]).to eq('nyaruko')
356
+ end
357
+ end
358
+
359
+ it 'call []=' do
360
+ driver_class::session(driver_config) do |kvs|
361
+ kvs.lists['anime'][1] = 'inuhasa'
362
+ expect(kvs.lists['anime'][1]).to eq('inuhasa')
363
+ end
364
+ end
365
+
366
+ it 'call delete' do
367
+ driver_class::session(driver_config) do |kvs|
368
+ expect{
369
+ kvs.lists['anime'].delete('nyaruko')
370
+ }.to change{ kvs.lists['anime'].length }.by(-1)
371
+ expect(kvs.lists['anime'][0]).to eq('haganai')
372
+ end
373
+ end
374
+
375
+ it 'call delete_at' do
376
+ driver_class::session(driver_config) do |kvs|
377
+ expect{
378
+ kvs.lists['anime'].delete_at(1)
379
+ }.to change{ kvs.lists['anime'].length }.by(-1)
380
+ expect(kvs.lists['anime'][0]).to eq('nyaruko')
381
+ end
382
+ end
383
+
384
+ it 'call each' do
385
+ driver_class::session(driver_config) do |kvs|
386
+ kvs.lists['anime'].each do |index, value|
387
+ expect(kvs.lists['anime'][index]).to eq(value)
388
+ end
389
+ end
390
+ end
391
+
392
+ it 'call each' do
393
+ driver_class::session(driver_config) do |kvs|
394
+ kvs.lists['anime'].each do |index, value|
395
+ expect(kvs.lists['anime'][index]).to eq(value)
396
+ end
397
+ end
398
+ end
399
+
400
+ it 'call include?' do
401
+ driver_class::session(driver_config) do |kvs|
402
+ expect(kvs.lists['anime'].include?('nyaruko')).to be_true
403
+ expect(kvs.lists['anime'].include?('konnanonaiyo')).to be_false
404
+ end
405
+ end
406
+
407
+ it 'call push pop' do
408
+ driver_class::session(driver_config) do |kvs|
409
+ kvs.lists['anime'].push_first('rozen')
410
+ kvs.lists['anime'].push_last('maiden')
411
+
412
+ expect(kvs.lists['anime'].pop_first).to eq('rozen')
413
+ expect(kvs.lists['anime'].pop_last).to eq('maiden')
414
+ end
415
+ end
416
+ end
417
+
418
+ end
419
+
420
+
193
421
  context 'sorted_sets' do
194
422
  before(:each) do
195
423
  driver_class::session(driver_config) do |kvs|
@@ -46,10 +46,25 @@ describe RailsKvsDriver::Lists::List do
46
46
  }.to change{count}.by(100)
47
47
  end
48
48
 
49
+ it 'call include?' do
50
+ expect(@driver.lists[:key].include?(:Nyarukosan)).to be_true
51
+ end
52
+
49
53
  it 'call length' do
50
54
  expect(@driver.lists[:key].length).to eq(100)
51
55
  end
52
56
 
57
+ it 'call push_*' do
58
+ expect(@driver.lists[:key].push_first('Nyarukosan')).to eq(5)
59
+ expect(@driver.lists[:key].push_last('Nyarukosan')).to eq(5)
60
+ end
61
+
62
+ it 'call push_*' do
63
+ expect(@driver.lists[:key].pop_first).to eq('Nyarukosan')
64
+ expect(@driver.lists[:key].pop_last).to eq('Nyarukosan')
65
+ end
66
+
67
+
53
68
  it 'call size' do
54
69
  expect(@driver.lists[:key].size).to eq(100)
55
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_kvs_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn