rails_kvs_driver 0.0.1 → 0.0.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: fbaf6fd75ff39b74ea85707b45a3500cca71e3a8
4
- data.tar.gz: d2b015e79daa282a8fd27c29b393d19506c6a078
3
+ metadata.gz: d9c2d6bc0f0efa423e900af03e85f7f483a1c130
4
+ data.tar.gz: eef288a528f469bbb1b9d8a13ab6738ad6a1657a
5
5
  SHA512:
6
- metadata.gz: 6648bdb2a961f6c47cef36b5c7b5d51b88a66a1a4efe7749b1c8341c5f8242ecfb1938d28b791b3ff24858f8ade7adcb2a2eabdabb399e0c5075dee44f9393f7
7
- data.tar.gz: bd42ee65d4696cb8cc5914619a1615e01670788b513945cf40ec9136ba5bf6f5dcb69c66ee8387586fdd2fb1c71e70279317c7e76f1ae90e63c57427bb7cf1eb
6
+ metadata.gz: 0a8ac3db947ca01228bd56851dbafc146feb00f4e3a9f8d6c6e41107b7dec4c306a099aba15a52b2dc6840d1e57e4b79a0ca801212d6d564e8b1e5687578e732
7
+ data.tar.gz: 2b710cfc50e54ba49492be948f85797a04d7789fcca0600626b9e1e695dfbe5954a28184982f09f96a0256de3928116b3dc3850c7705e71dca640486a71cbb5b
@@ -1,3 +1,3 @@
1
1
  module RailsKvsDriver
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -75,7 +75,7 @@ module RailsKvsDriver
75
75
  # delete all keys from kvs.
76
76
  # @return [Boolean] result.
77
77
  # @abstract delete all keys from kvs.
78
- def delete_all(key)
78
+ def delete_all
79
79
  raise NoMethodError
80
80
  end
81
81
 
@@ -123,7 +123,7 @@ module RailsKvsDriver
123
123
  # @param member [String] member of sorted set.
124
124
  # @return [Float] score of member.
125
125
  # @abstract get the score of member.
126
- def get_sorted_set_score(key, member)
126
+ def sorted_set_score(key, member)
127
127
  raise NoMethodError
128
128
  end
129
129
 
@@ -136,7 +136,7 @@ module RailsKvsDriver
136
136
  # @param reverse [Boolean] order by desc
137
137
  # @return [Array<String, Float>>] array of the member and score.
138
138
  # @abstract get array of sorted set.
139
- def get_sorted_set(key, start=0, stop=-1, reverse=false)
139
+ def sorted_set(key, start=0, stop=-1, reverse=false)
140
140
  raise NoMethodError
141
141
  end
142
142
 
@@ -0,0 +1,132 @@
1
+ # How to use
2
+ # copying #{ProjectRoot}/spec
3
+ #
4
+ # require "common_example"
5
+ #
6
+ # it_should_behave_like 'RailsKvsDriver example', driver_class, driver_config
7
+ #
8
+
9
+ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
10
+
11
+ it 'inheritance RailsKvsDriver::Base' do
12
+ expect(driver_class.ancestors.include?(RailsKvsDriver::Base)).to be_true
13
+ end
14
+
15
+ context 'connect kvs' do
16
+ before(:each) do
17
+ driver_class::session(driver_config) do |kvs|
18
+ kvs.delete_all
19
+ end
20
+ end
21
+
22
+ after(:each) do
23
+ driver_class::session(driver_config) do |kvs|
24
+ kvs.delete_all
25
+ end
26
+ end
27
+
28
+ it 'call set value' do
29
+ driver_class::session(driver_config) do |kvs|
30
+ expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
31
+ end
32
+ end
33
+
34
+ it 'call get value' do
35
+ driver_class::session(driver_config) do |kvs|
36
+ expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
37
+ expect(kvs['example']).to eq('nico-nico')
38
+ end
39
+ end
40
+
41
+ it 'call all keys' do
42
+ driver_class::session(driver_config) do |kvs|
43
+ expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
44
+ expect(kvs.all_keys.length).to eq(1)
45
+ end
46
+ end
47
+
48
+ it 'call delete value' do
49
+ driver_class::session(driver_config) do |kvs|
50
+ kvs['example'] = 'nico-nico'
51
+ kvs['example2'] = 'movie'
52
+
53
+ expect{ kvs.delete('example') }.to change{ kvs.all_keys.length }.by(-1)
54
+
55
+ expect(kvs['example']).to eq(nil)
56
+ expect(kvs['example2']).to eq('movie')
57
+ end
58
+ end
59
+
60
+ it 'call delete_all' do
61
+ driver_class::session(driver_config) do |kvs|
62
+ kvs['example'] = 'nico-nico'
63
+ kvs['example2'] = 'movie'
64
+
65
+ expect{ kvs.delete_all }.to change{ kvs.all_keys.length }.by(-2)
66
+
67
+ expect(kvs['example']).to eq(nil)
68
+ expect(kvs['example2']).to eq(nil)
69
+ end
70
+ end
71
+
72
+ it 'call add_sorted_set' do
73
+ driver_class::session(driver_config) do |kvs|
74
+ expect{
75
+ kvs.add_sorted_set('example', 'element', 1)
76
+ }.to change{ kvs.all_keys.length }.by(1)
77
+ end
78
+ end
79
+
80
+ it 'call remove_sorted_set' do
81
+ driver_class::session(driver_config) do |kvs|
82
+ kvs.add_sorted_set('example', 'element', 1)
83
+ kvs.add_sorted_set('example', 'element2', 1)
84
+
85
+ expect{
86
+ kvs.remove_sorted_set('example', 'element')
87
+ }.to change{ kvs.count_sorted_set_member('example') }.by(-1)
88
+ end
89
+ end
90
+
91
+ it 'call increment_sorted_set' do
92
+ driver_class::session(driver_config) do |kvs|
93
+ kvs.add_sorted_set('example', 'element', 1)
94
+
95
+ expect{
96
+ kvs.increment_sorted_set('example', 'element', 10)
97
+ }.to change{ kvs.sorted_set_score('example', 'element') }.by(10)
98
+ end
99
+ end
100
+
101
+ it 'call sorted_set' do
102
+ driver_class::session(driver_config) do |kvs|
103
+ kvs.add_sorted_set('example', 'element1', 1)
104
+ kvs.add_sorted_set('example', 'element5', 5)
105
+ kvs.add_sorted_set('example', 'element2', 2)
106
+
107
+ sorted_set = kvs.sorted_set('example')
108
+
109
+ expect(sorted_set[0][0]).to eq('element1')
110
+ expect(sorted_set[1][0]).to eq('element2')
111
+ expect(sorted_set[2][0]).to eq('element5')
112
+ end
113
+ end
114
+
115
+ it 'call sorted_set_score' do
116
+ driver_class::session(driver_config) do |kvs|
117
+ kvs.add_sorted_set('example', 'element5', 5)
118
+ expect(kvs.sorted_set('example')[0][1]).to eq(5)
119
+ end
120
+ end
121
+
122
+ it 'call count_sorted_set_member' do
123
+ driver_class::session(driver_config) do |kvs|
124
+ kvs.add_sorted_set('example', 'element1', 5)
125
+ kvs.add_sorted_set('example', 'element2', 5)
126
+ kvs.add_sorted_set('example', 'element3', 5)
127
+ expect(kvs.count_sorted_set_member('example')).to eq(3)
128
+ end
129
+ end
130
+ end
131
+ end
132
+
@@ -25,52 +25,57 @@ describe RailsKvsDriver do
25
25
  end
26
26
 
27
27
  it 'raise NoMethodError when does not override []' do
28
- expect{MockDriver.new.respond_to?('[]')}.to be_true
28
+ expect(MockDriver.method_defined?('[]')).to be_true
29
29
  expect{MockDriver.new['a']}.to raise_error
30
30
  end
31
31
 
32
32
  it 'raise NoMethodError when does not override []=' do
33
- expect{MockDriver.new.respond_to?('[]=')}.to be_true
33
+ expect(MockDriver.method_defined?('[]=')).to be_true
34
34
  expect{MockDriver.new['a']='b'}.to raise_error
35
35
  end
36
36
 
37
37
  it 'raise NoMethodError when does not override all_keys' do
38
- expect{MockDriver.new.respond_to?(:all_keys)}.to be_true
38
+ expect(MockDriver.method_defined?(:all_keys)).to be_true
39
39
  expect{MockDriver.new.all_keys}.to raise_error
40
40
  end
41
41
 
42
42
  it 'raise NoMethodError when does not override delete' do
43
- expect{MockDriver.new.respond_to?(:delete)}.to be_true
43
+ expect(MockDriver.method_defined?(:delete)).to be_true
44
44
  expect{MockDriver.new.delete}.to raise_error
45
45
  end
46
46
 
47
47
  it 'raise NoMethodError when does not override delete_all' do
48
- expect{MockDriver.new.respond_to?(:delete_all)}.to be_true
48
+ expect(MockDriver.method_defined?(:delete_all)).to be_true
49
49
  expect{MockDriver.new.delete_all}.to raise_error
50
50
  end
51
51
 
52
52
  it 'raise NoMethodError when does not override add_sorted_set' do
53
- expect{MockDriver.new.respond_to?(:add_sorted_set)}.to be_true
53
+ expect(MockDriver.method_defined?(:add_sorted_set)).to be_true
54
54
  expect{MockDriver.new.add_sorted_set}.to raise_error
55
55
  end
56
56
 
57
57
  it 'raise NoMethodError when does not override remove_sorted_set' do
58
- expect{MockDriver.new.respond_to?(:remove_sorted_set)}.to be_true
58
+ expect(MockDriver.method_defined?(:remove_sorted_set)).to be_true
59
59
  expect{MockDriver.new.remove_sorted_set}.to raise_error
60
60
  end
61
61
 
62
62
  it 'raise NoMethodError when does not override increment_sorted_set' do
63
- expect{MockDriver.new.respond_to?(:increment_sorted_set)}.to be_true
63
+ expect(MockDriver.method_defined?(:increment_sorted_set)).to be_true
64
64
  expect{MockDriver.new.increment_sorted_set}.to raise_error
65
65
  end
66
66
 
67
- it 'raise NoMethodError when does not override get_sorted_set' do
68
- expect{MockDriver.new.respond_to?(:get_sorted_set)}.to be_true
69
- expect{MockDriver.new.get_sorted_set}.to raise_error
67
+ it 'raise NoMethodError when does not override sorted_set_score' do
68
+ expect(MockDriver.method_defined?(:sorted_set_score)).to be_true
69
+ expect{MockDriver.new.sorted_set_score}.to raise_error
70
+ end
71
+
72
+ it 'raise NoMethodError when does not override sorted_set' do
73
+ expect(MockDriver.method_defined?(:sorted_set)).to be_true
74
+ expect{MockDriver.new.sorted_set}.to raise_error
70
75
  end
71
76
 
72
77
  it 'raise NoMethodError when does not override count_sorted_set_member' do
73
- expect{MockDriver.new.respond_to?(:count_sorted_set_member)}.to be_true
78
+ expect(MockDriver.method_defined?(:count_sorted_set_member)).to be_true
74
79
  expect{MockDriver.new.count_sorted_set_member}.to raise_error
75
80
  end
76
81
 
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn
@@ -95,6 +95,7 @@ files:
95
95
  - lib/rails_kvs_driver.rb
96
96
  - lib/rails_kvs_driver/version.rb
97
97
  - rails_kvs_driver.gemspec
98
+ - spec/common_example.rb
98
99
  - spec/rails_kvs_driver_spec.rb
99
100
  - spec/spec_helper.rb
100
101
  homepage: https://github.com/alfa-jpn/rails-kvs-driver
@@ -122,6 +123,7 @@ signing_key:
122
123
  specification_version: 4
123
124
  summary: rails kvs driver wrap access key-value store.
124
125
  test_files:
126
+ - spec/common_example.rb
125
127
  - spec/rails_kvs_driver_spec.rb
126
128
  - spec/spec_helper.rb
127
129
  has_rdoc: