hikki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +98 -0
  8. data/Rakefile +6 -0
  9. data/adapters/hikki-memcache/.rspec +2 -0
  10. data/adapters/hikki-memcache/.travis.yml +3 -0
  11. data/adapters/hikki-memcache/Gemfile +7 -0
  12. data/adapters/hikki-memcache/LICENSE.txt +22 -0
  13. data/adapters/hikki-memcache/README.md +50 -0
  14. data/adapters/hikki-memcache/Rakefile +6 -0
  15. data/adapters/hikki-memcache/hikki-memcache.gemspec +27 -0
  16. data/adapters/hikki-memcache/lib/hikki/adapters/memcache_adapter.rb +22 -0
  17. data/adapters/hikki-memcache/lib/hikki/adapters/memcache_collection.rb +54 -0
  18. data/adapters/hikki-memcache/spec/hikki/adapters/memcache_adapter_integration_spec.rb +39 -0
  19. data/adapters/hikki-memcache/spec/hikki/adapters/memcache_adapter_spec.rb +115 -0
  20. data/adapters/hikki-memcache/spec/spec_helper.rb +8 -0
  21. data/adapters/hikki-mongo/.rspec +2 -0
  22. data/adapters/hikki-mongo/.travis.yml +3 -0
  23. data/adapters/hikki-mongo/Gemfile +7 -0
  24. data/adapters/hikki-mongo/LICENSE.txt +22 -0
  25. data/adapters/hikki-mongo/README.md +44 -0
  26. data/adapters/hikki-mongo/Rakefile +6 -0
  27. data/adapters/hikki-mongo/hikki-mongo.gemspec +28 -0
  28. data/adapters/hikki-mongo/lib/hikki/adapters/mongo_adapter.rb +22 -0
  29. data/adapters/hikki-mongo/lib/hikki/adapters/mongo_collection.rb +86 -0
  30. data/adapters/hikki-mongo/spec/hikki/adapters/mongo_adapter_integration_spec.rb +39 -0
  31. data/adapters/hikki-mongo/spec/hikki/adapters/mongo_adapter_spec.rb +231 -0
  32. data/adapters/hikki-mongo/spec/spec_helper.rb +8 -0
  33. data/adapters/hikki-redis/.rspec +2 -0
  34. data/adapters/hikki-redis/.travis.yml +3 -0
  35. data/adapters/hikki-redis/Gemfile +7 -0
  36. data/adapters/hikki-redis/LICENSE.txt +22 -0
  37. data/adapters/hikki-redis/README.md +44 -0
  38. data/adapters/hikki-redis/Rakefile +6 -0
  39. data/adapters/hikki-redis/hikki-redis.gemspec +27 -0
  40. data/adapters/hikki-redis/lib/hikki/adapters/redis_adapter.rb +21 -0
  41. data/adapters/hikki-redis/lib/hikki/adapters/redis_collection.rb +105 -0
  42. data/adapters/hikki-redis/spec/hikki/adapters/redis_adapter_integration_spec.rb +39 -0
  43. data/adapters/hikki-redis/spec/hikki/adapters/redis_adapter_spec.rb +258 -0
  44. data/adapters/hikki-redis/spec/spec_helper.rb +8 -0
  45. data/all_specs +13 -0
  46. data/hikki.gemspec +24 -0
  47. data/lib/hikki.rb +9 -0
  48. data/lib/hikki/adapters/adapter.rb +43 -0
  49. data/lib/hikki/adapters/memory_adapter.rb +18 -0
  50. data/lib/hikki/adapters/memory_collection.rb +87 -0
  51. data/lib/hikki/collection.rb +62 -0
  52. data/lib/hikki/repository.rb +54 -0
  53. data/lib/hikki/version.rb +3 -0
  54. data/spec/hikki/adapters/memory_adapter_spec.rb +242 -0
  55. data/spec/hikki/repository_spec.rb +260 -0
  56. data/spec/hikki_spec.rb +5 -0
  57. data/spec/spec_helper.rb +2 -0
  58. metadata +146 -0
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'hikki/adapters/mongo_adapter'
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.filter_run_excluding :integration
8
+ end
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hikki-redis.gemspec
4
+ gemspec
5
+
6
+ # Grab Hikki from local relative
7
+ gem 'hikki', path: '../../'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 alexpeachey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Hikki::Adapters::RedisAdapter
2
+
3
+ A Redis adapter for Hikki.
4
+ It uses the `redis` gem to communicate with Redis.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'hikki-redis'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install hikki-redis
19
+
20
+ ## Usage
21
+
22
+ By default, the adapter will use `Redis.new` as it's connection which uses the defaults in that gem.
23
+ You can pass in your own connection to use instead, useful for specifying a server and other options.
24
+
25
+ ```ruby
26
+ # Use the default connection
27
+ adapter = Hikki::Adapters::RedisAdapter.new
28
+
29
+ # Use a specific connection
30
+ redis = Redis.new(:url => "redis://:p4ssw0rd@10.0.1.1:6380/15")
31
+ adapter = Hikki::Adapters::RedisAdapter.new(redis)
32
+ ```
33
+
34
+ If you do not specify an `id` when saving, the adapter will generate a uuid using `SecureRandom`.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( http://github.com/originate/hikki/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Write your specifications
41
+ 4. Implement your specifications
42
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 6. Push to the branch (`git push origin my-new-feature`)
44
+ 7. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../../../lib/hikki/version', __FILE__)
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hikki-redis'
8
+ spec.version = Hikki::VERSION
9
+ spec.authors = ['alexpeachey']
10
+ spec.email = ['alex.peachey@originate.com']
11
+ spec.summary = 'A Redis adapter for Hikki.'
12
+ spec.description = 'A Redis adapter for Hikki.'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ #spec.add_dependency 'hikki', Hikki::VERSION
22
+ spec.add_dependency 'redis'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'redis'
2
+ require 'hikki'
3
+ require_relative './redis_collection'
4
+
5
+ module Hikki
6
+ module Adapters
7
+ class RedisAdapter < Hikki::Adapters::Adapter
8
+ attr_reader :connection, :uuid_generator
9
+
10
+ def initialize(connection=Redis.new, uuid_generator=SecureRandom)
11
+ super()
12
+ @connection = connection
13
+ @uuid_generator = uuid_generator
14
+ end
15
+
16
+ def collection_for(collection)
17
+ collections.fetch(collection, RedisCollection.new(collection, connection, uuid_generator))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,105 @@
1
+ module Hikki
2
+ module Adapters
3
+ class RedisCollection < Hikki::Collection
4
+ attr_reader :connection, :uuid_generator
5
+
6
+ def initialize(collection, connection, uuid_generator)
7
+ super(collection)
8
+ @connection = connection
9
+ @uuid_generator = uuid_generator
10
+ end
11
+
12
+ def index(field)
13
+ connection.sadd collection_indexes_key, field.to_s
14
+ true
15
+ end
16
+
17
+ def save(data)
18
+ data = normalize_data(data)
19
+ connection.hset collection_key, data['id'], data.to_json
20
+ add_to_index(data)
21
+ data
22
+ end
23
+
24
+ def find(id)
25
+ JSON.parse(connection.hget(collection_key, id.to_s) || '{}')
26
+ end
27
+
28
+ def all(options={})
29
+ options = normalize_options(options)
30
+ connection.hvals(collection_key)[page_range(options)].map { |j| JSON.parse(j) }
31
+ end
32
+
33
+ def find_by(field, value, options={})
34
+ options = normalize_options(options)
35
+ return find_by_index(field, value, options) if has_index?(field)
36
+ all.select { |o| o.fetch(field.to_s) == value }[page_range(options)]
37
+ end
38
+
39
+ def remove(id)
40
+ remove_from_index(find(id))
41
+ connection.hdel collection_key, id.to_s
42
+ true
43
+ end
44
+
45
+ def remove_all
46
+ indexes.each { |field| connection.del collection_index_key(field) }
47
+ connection.del collection_indexes_key
48
+ connection.del collection_key
49
+ end
50
+
51
+ def has_index?(field)
52
+ connection.sismember collection_indexes_key, field.to_s
53
+ end
54
+
55
+ def indexes
56
+ connection.smembers collection_indexes_key
57
+ end
58
+
59
+ def id_for(data)
60
+ data.fetch('id', uuid_generator.uuid).to_s
61
+ end
62
+
63
+ private
64
+ def collection_indexes_key
65
+ "hikki:#{collection}:indexes"
66
+ end
67
+
68
+ def collection_index_key(field)
69
+ "hikki:#{collection}:#{field.to_s}"
70
+ end
71
+
72
+ def collection_key
73
+ "hikki:#{collection}"
74
+ end
75
+
76
+ def add_to_index(data)
77
+ indexes.each do |field|
78
+ existing = indexed_ids(field, data[field])
79
+ existing << data['id'] unless existing.include? data['id']
80
+ connection.hset collection_index_key(field), data[field], existing.to_json
81
+ end
82
+ end
83
+
84
+ def remove_from_index(data)
85
+ return if data == {}
86
+ indexes.each do |field|
87
+ ids = indexed_ids(field, data[field])
88
+ ids.delete(data['id'])
89
+ connection.hset collection_index_key(field), data[field].to_s, ids.to_json
90
+ end
91
+ end
92
+
93
+ def indexed_ids(field, value)
94
+ JSON.parse(connection.hget(collection_index_key(field), value.to_s) || '[]')
95
+ end
96
+
97
+ def find_by_index(field, value, options)
98
+ ids = indexed_ids(field, value)
99
+ results = connection.pipelined { ids.each { |id| connection.hget collection_key, id } }
100
+ results.map { |j| JSON.parse(j) }.reject { |v| v == {} }[page_range(options)]
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module Hikki
4
+ module Adapters
5
+ describe RedisAdapter, :integration do
6
+ context 'when actually using Redis' do
7
+ subject(:adapter) { RedisAdapter.new }
8
+ let(:data) { { id: id, field1: 'test', field2: 123 } }
9
+ let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
10
+ let(:id) { '1' }
11
+ let(:collection) { 'collection1' }
12
+
13
+ it 'can store and retreive data' do
14
+ adapter.remove_all(collection)
15
+ adapter.index(collection, :field1)
16
+ adapter.save(collection, data)
17
+ expect(adapter.find(collection, id)).to eq expected
18
+ expect(adapter.find(collection, '2')).to eq Hash.new
19
+ expect(adapter.all(collection)).to eq [expected]
20
+ expect(adapter.find_by(collection, :field1, 'test')).to eq [expected]
21
+ expect(adapter.find_by(collection, :field2, 123)).to eq [expected]
22
+ expect(adapter.find_by(collection, :field1, 'foo')).to eq []
23
+ expect(adapter.find_by(collection, :field2, 1)).to eq []
24
+ adapter.remove(collection, id)
25
+ expect(adapter.find(collection, id)).to eq Hash.new
26
+ expect(adapter.all(collection)).to eq []
27
+ 10.times do |i|
28
+ adapter.save(collection, { id: i, field1: "test-#{i%2}" })
29
+ end
30
+ expect(adapter.all(collection, {limit: 2, offset: 6})).to eq [{'id' => '6', 'field1' => 'test-0'}, {'id' => '7', 'field1' => 'test-1'}]
31
+ expect(adapter.find_by(collection, :field1, 'test-0', {limit: 2})).to eq [{'id' => '0', 'field1' => 'test-0'}, {'id' => '2', 'field1' => 'test-0'}]
32
+ adapter.remove_all(collection)
33
+ expect(adapter.find(collection, id)).to eq Hash.new
34
+ expect(adapter.all(collection)).to eq []
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,258 @@
1
+ require 'spec_helper'
2
+
3
+ module Hikki
4
+ module Adapters
5
+ describe RedisAdapter do
6
+ subject(:adapter) { RedisAdapter.new(connection, uuid_generator) }
7
+ let(:connection) { double :connection, sadd: true, smembers: [], hset: true, hget: true, hdel: true, del: true }
8
+ let(:uuid_generator) { double :uuid_generator, uuid: '12345' }
9
+ let(:collection) { 'collection1' }
10
+
11
+ describe '#index' do
12
+ it 'returns true' do
13
+ expect(adapter.index(collection, :field1)).to be_true
14
+ end
15
+
16
+ it 'adds the field to the index list' do
17
+ adapter.index(collection, :field1)
18
+ expect(connection).to have_received(:sadd).with('hikki:collection1:indexes', 'field1')
19
+ end
20
+ end
21
+
22
+ describe '#save' do
23
+ context 'when an id is provided in the data' do
24
+ let(:data) { { id: id, field1: 'test', field2: 123 } }
25
+ let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
26
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
27
+ let(:id) { '1' }
28
+
29
+ it 'returns the data' do
30
+ expect(adapter.save(collection, data)).to eq expected
31
+ end
32
+
33
+ it 'persists the data in the store' do
34
+ adapter.save(collection, data)
35
+ expect(connection).to have_received(:hset).with('hikki:collection1', id, json)
36
+ end
37
+ end
38
+
39
+ context 'when an id is not provided in the data' do
40
+ let(:data) { { field1: 'test', field2: 123 } }
41
+ let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
42
+ let(:json) { '{"field1":"test","field2":123,"id":"12345"}' }
43
+ let(:id) { '12345' }
44
+
45
+ it 'returns the data with the id added' do
46
+ expect(adapter.save(collection, data)).to eq expected
47
+ end
48
+
49
+ it 'persists the data in the store' do
50
+ adapter.save(collection, data)
51
+ expect(connection).to have_received(:hset).with('hikki:collection1', id, json)
52
+ end
53
+ end
54
+
55
+ context 'when an index exists on a field in the data' do
56
+ let(:data) { { id: id, field1: 'test', field2: 123 } }
57
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
58
+ let(:id) { '1' }
59
+ before do
60
+ connection.stub(:smembers).with('hikki:collection1:indexes').and_return(['field1'])
61
+ connection.stub(:hget).with('hikki:collection1:field1', 'test').and_return('[]')
62
+ end
63
+
64
+ it 'adds an entry in the index' do
65
+ expect(connection).to receive(:hset).with('hikki:collection1', id, json)
66
+ expect(connection).to receive(:hset).with('hikki:collection1:field1', 'test', '["1"]')
67
+ adapter.save(collection, data)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#find' do
73
+ let(:id) { '1' }
74
+
75
+ context 'when the id exists' do
76
+ let(:data) { { id: id, field1: 'test', field2: 123 } }
77
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
78
+ let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
79
+ before { connection.stub(:hget).with('hikki:collection1', id).and_return(json) }
80
+
81
+ it 'retrieves the data' do
82
+ expect(adapter.find(collection, id)).to eq expected
83
+ end
84
+ end
85
+
86
+ context 'when the id does not exist' do
87
+ let(:expected) { {} }
88
+ before { connection.stub(:hget).with('hikki:collection1', id).and_return(nil) }
89
+
90
+ it 'returns an empty hash' do
91
+ expect(adapter.find(collection, id)).to eq expected
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#all' do
97
+ context 'with a record in the collection' do
98
+ let(:data) { { id: '1', field1: 'test', field2: 123 } }
99
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
100
+ let(:expected) { { 'id' => '1', 'field1' => 'test', 'field2' => 123 } }
101
+ before { connection.stub(:hvals).with('hikki:collection1').and_return([json]) }
102
+
103
+ it 'returns an array containing the record' do
104
+ expect(adapter.all(collection)).to eq [expected]
105
+ end
106
+ end
107
+
108
+ context 'with no records in the collection' do
109
+ before { connection.stub(:hvals).with('hikki:collection1').and_return([]) }
110
+
111
+ it 'returns an array containing the record' do
112
+ expect(adapter.all(collection)).to eq []
113
+ end
114
+ end
115
+
116
+ context 'with multiple records and paging options specified' do
117
+ before do
118
+ results = (1..10).map {|i| "{\"id\":\"#{i}\",\"a\":1}" }
119
+ connection.stub(:hvals).with('hikki:collection1').and_return(results)
120
+ end
121
+
122
+ context 'with limit 2' do
123
+ let(:limit) { 2 }
124
+
125
+ it 'returns only 2 records' do
126
+ expect(adapter.all(collection, {limit: 2}).count).to eq 2
127
+ end
128
+
129
+ context 'with an offset of 4' do
130
+ it 'returns the 2 records starting with the offset' do
131
+ expect(adapter.all(collection, {limit: 2, offset: 4})).to eq [{'id' => '5', 'a' => 1}, {'id' => '6', 'a' => 1}]
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ describe '#find_by' do
139
+ context 'with a record in the collection matching' do
140
+ let(:data) { { id: id, field1: 'test', field2: 123 } }
141
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
142
+ let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
143
+ let(:id) { '1' }
144
+
145
+ context 'without an index' do
146
+ before do
147
+ connection.stub(:sismember).with('hikki:collection1:indexes', 'field2').and_return(false)
148
+ connection.stub(:hvals).with('hikki:collection1').and_return([json])
149
+ end
150
+
151
+ it 'returns an array containing the record' do
152
+ expect(adapter.find_by(collection, :field2, 123)).to eq [expected]
153
+ end
154
+ end
155
+
156
+ context 'with an index' do
157
+ before do
158
+ connection.stub(:sismember).with('hikki:collection1:indexes', 'field1').and_return(true)
159
+ connection.stub(:hget).with('hikki:collection1:field1', 'test').and_return('[1]')
160
+ connection.stub(:hget).with('hikki:collection1', id).and_return(json)
161
+ connection.stub(:pipelined).and_yield.and_return([json])
162
+ end
163
+
164
+ it 'returns an array containing the record' do
165
+ expect(adapter.find_by(collection, :field1, 'test')).to eq [expected]
166
+ end
167
+ end
168
+ end
169
+
170
+ context 'with no matching records in the collection' do
171
+ before do
172
+ connection.stub(:sismember).with('hikki:collection1:indexes', 'field1').and_return(false)
173
+ connection.stub(:hvals).with('hikki:collection1').and_return([])
174
+ end
175
+
176
+ it 'returns an empty array' do
177
+ expect(adapter.find_by(collection, :field1, 'foo')).to eq []
178
+ end
179
+ end
180
+
181
+ context 'with multiple matching records and paging options specified' do
182
+ before do
183
+ results = (1..10).map {|i| "{\"id\":\"#{i}\",\"a\":1}" }
184
+ connection.stub(:sismember).with('hikki:collection1:indexes', 'a').and_return(false)
185
+ connection.stub(:hvals).with('hikki:collection1').and_return(results)
186
+ end
187
+
188
+ context 'with limit 2' do
189
+ let(:limit) { 2 }
190
+
191
+ it 'returns only 2 records' do
192
+ expect(adapter.find_by(collection, :a, 1, {limit: 2}).count).to eq 2
193
+ end
194
+
195
+ context 'with an offset of 4' do
196
+ it 'returns the 2 records starting with the offset' do
197
+ expect(adapter.find_by(collection, :a, 1, {limit: 2, offset: 4})).to eq [{'id' => '5', 'a' => 1}, {'id' => '6', 'a' => 1}]
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ describe '#remove' do
205
+ context 'with a record for the id in the collection' do
206
+ let(:id) { '1' }
207
+ let(:json) { '{"id":"1","field1":"test","field2":123}' }
208
+ before { connection.stub(:hget).with('hikki:collection1', id).and_return(json) }
209
+
210
+ it 'returns true' do
211
+ expect(adapter.remove(collection, id)).to be_true
212
+ end
213
+
214
+ it 'removes the record from the store' do
215
+ adapter.remove(collection, id)
216
+ expect(connection).to have_received(:hdel).with('hikki:collection1', id)
217
+ end
218
+
219
+ context 'when there is an index' do
220
+ before do
221
+ connection.stub(:smembers).with('hikki:collection1:indexes').and_return(['field1'])
222
+ connection.stub(:hget).with('hikki:collection1:field1', 'test').and_return('["1"]')
223
+ end
224
+
225
+ it 'removes the id from the index' do
226
+ adapter.remove(collection, id)
227
+ expect(connection).to have_received(:hset).with('hikki:collection1:field1', 'test', '[]')
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ describe '#remove_all' do
234
+ context 'with a record in the collection' do
235
+ it 'returns true' do
236
+ expect(adapter.remove_all(collection)).to be_true
237
+ end
238
+
239
+ it 'removes all records from the store' do
240
+ expect(connection).to receive(:del).with('hikki:collection1:indexes')
241
+ expect(connection).to receive(:del).with('hikki:collection1')
242
+ adapter.remove_all(collection)
243
+ end
244
+
245
+ context 'when there is an index' do
246
+ before { connection.stub(:smembers).with('hikki:collection1:indexes').and_return(['field1']) }
247
+
248
+ it 'removes the indexes' do
249
+ adapter.remove_all(collection)
250
+ expect(connection).to have_received(:del).with('hikki:collection1:field1')
251
+ expect(connection).to have_received(:del).with('hikki:collection1:indexes')
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end