riak-shim 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/riak-shim/persistable.rb +7 -1
- data/lib/riak-shim/version.rb +1 -1
- data/riak-shim.gemspec +1 -0
- data/spec/persistable_spec.rb +36 -16
- data/spec/spec_helper.rb +1 -0
- metadata +18 -2
@@ -45,7 +45,7 @@ module Riak
|
|
45
45
|
module ClassMethods
|
46
46
|
def delete_all
|
47
47
|
bucket.keys.each do |key|
|
48
|
-
bucket.delete
|
48
|
+
bucket.delete(key)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -91,6 +91,12 @@ module Riak
|
|
91
91
|
def gen_key
|
92
92
|
UUIDTools::UUID.random_create.to_s
|
93
93
|
end
|
94
|
+
|
95
|
+
def count
|
96
|
+
counter = 0
|
97
|
+
bucket.keys {|keys| counter += keys.count }
|
98
|
+
return counter
|
99
|
+
end
|
94
100
|
end
|
95
101
|
|
96
102
|
def self.included(base)
|
data/lib/riak-shim/version.rb
CHANGED
data/riak-shim.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_development_dependency "guard"
|
25
25
|
gem.add_development_dependency "guard-rspec"
|
26
26
|
gem.add_development_dependency "pry"
|
27
|
+
gem.add_development_dependency "awesome_print"
|
27
28
|
|
28
29
|
if RUBY_PLATFORM.include? 'darwin'
|
29
30
|
gem.add_development_dependency 'growl'
|
data/spec/persistable_spec.rb
CHANGED
@@ -20,10 +20,10 @@ class PersistableExample
|
|
20
20
|
|
21
21
|
def ==(other)
|
22
22
|
other.instance_of?(self.class) and
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
self.key == other.key and
|
24
|
+
self.foo == other.foo and
|
25
|
+
self.bar == other.bar and
|
26
|
+
self.baz == other.baz
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -33,6 +33,14 @@ class PersistableExampleWithIndex < PersistableExample
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def create_test_data(copies)
|
37
|
+
copies.times do |i|
|
38
|
+
p = PersistableExample.new
|
39
|
+
p.foo, p.bar, p.baz = i, i, i
|
40
|
+
p.save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
describe 'persistable' do
|
37
45
|
let(:persistable) do
|
38
46
|
p = PersistableExample.new ; p.foo = 'boo' ; p.bar = 'who' ; p
|
@@ -96,7 +104,7 @@ describe 'persistable' do
|
|
96
104
|
@indexes[:oldkey] = ['oldval']
|
97
105
|
end
|
98
106
|
|
99
|
-
context 'with a model which does not need
|
107
|
+
context 'with a model which does not need indexes' do
|
100
108
|
it 'does not require #fields_to_index to be defined' do
|
101
109
|
expect { persistable.set_indexes(@indexes) }.to_not raise_error
|
102
110
|
end
|
@@ -116,6 +124,10 @@ describe 'persistable' do
|
|
116
124
|
indexable.set_indexes(@indexes)
|
117
125
|
end
|
118
126
|
|
127
|
+
after do
|
128
|
+
PersistableExampleWithIndex.delete_all
|
129
|
+
end
|
130
|
+
|
119
131
|
it 'sets indexes for specified fields and no others' do
|
120
132
|
@indexes.keys.should =~ ['bar_bin', 'baz_bin']
|
121
133
|
end
|
@@ -124,22 +136,18 @@ describe 'persistable' do
|
|
124
136
|
|
125
137
|
describe '#delete_all' do
|
126
138
|
before do
|
127
|
-
10
|
128
|
-
p = PersistableExample.new
|
129
|
-
p.foo, p.bar, p.baz = i, i, i
|
130
|
-
p.save
|
131
|
-
end
|
132
|
-
@keys = bucket.keys
|
139
|
+
create_test_data(10)
|
133
140
|
PersistableExample.delete_all
|
141
|
+
sleep(5)
|
134
142
|
end
|
135
143
|
|
136
144
|
it 'has no instances in the DB' do
|
137
|
-
|
145
|
+
PersistableExample.bucket.keys.count.should eq 0
|
138
146
|
end
|
139
147
|
end
|
140
148
|
|
141
149
|
describe '#de_camel' do
|
142
|
-
it 'handles a
|
150
|
+
it 'handles a basic camel-case name' do
|
143
151
|
DeCamel.each do |camelcase, lowered|
|
144
152
|
PersistableExample.de_camel(camelcase).should eq(lowered)
|
145
153
|
end
|
@@ -158,8 +166,7 @@ describe 'persistable' do
|
|
158
166
|
end
|
159
167
|
|
160
168
|
it 'does not produce collisions' do
|
161
|
-
PersistableExample.de_camel('RiakShim').should_not
|
162
|
-
eq PersistableExample.de_camel('Riak::Shim')
|
169
|
+
PersistableExample.de_camel('RiakShim').should_not eq PersistableExample.de_camel('Riak::Shim')
|
163
170
|
end
|
164
171
|
end
|
165
172
|
|
@@ -209,5 +216,18 @@ describe 'persistable' do
|
|
209
216
|
@keys.uniq!.should be_nil
|
210
217
|
end
|
211
218
|
end
|
212
|
-
end
|
213
219
|
|
220
|
+
describe '#count' do
|
221
|
+
COUNT = 50
|
222
|
+
|
223
|
+
before do
|
224
|
+
PersistableExample.delete_all
|
225
|
+
sleep(5)
|
226
|
+
create_test_data(COUNT)
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'returns an accurate count' do
|
230
|
+
PersistableExample.count.should eq COUNT
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riak-shim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: riak-client
|
@@ -139,6 +139,22 @@ dependencies:
|
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: awesome_print
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
142
158
|
- !ruby/object:Gem::Dependency
|
143
159
|
name: growl
|
144
160
|
requirement: !ruby/object:Gem::Requirement
|