hikki 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +98 -0
- data/Rakefile +6 -0
- data/adapters/hikki-memcache/.rspec +2 -0
- data/adapters/hikki-memcache/.travis.yml +3 -0
- data/adapters/hikki-memcache/Gemfile +7 -0
- data/adapters/hikki-memcache/LICENSE.txt +22 -0
- data/adapters/hikki-memcache/README.md +50 -0
- data/adapters/hikki-memcache/Rakefile +6 -0
- data/adapters/hikki-memcache/hikki-memcache.gemspec +27 -0
- data/adapters/hikki-memcache/lib/hikki/adapters/memcache_adapter.rb +22 -0
- data/adapters/hikki-memcache/lib/hikki/adapters/memcache_collection.rb +54 -0
- data/adapters/hikki-memcache/spec/hikki/adapters/memcache_adapter_integration_spec.rb +39 -0
- data/adapters/hikki-memcache/spec/hikki/adapters/memcache_adapter_spec.rb +115 -0
- data/adapters/hikki-memcache/spec/spec_helper.rb +8 -0
- data/adapters/hikki-mongo/.rspec +2 -0
- data/adapters/hikki-mongo/.travis.yml +3 -0
- data/adapters/hikki-mongo/Gemfile +7 -0
- data/adapters/hikki-mongo/LICENSE.txt +22 -0
- data/adapters/hikki-mongo/README.md +44 -0
- data/adapters/hikki-mongo/Rakefile +6 -0
- data/adapters/hikki-mongo/hikki-mongo.gemspec +28 -0
- data/adapters/hikki-mongo/lib/hikki/adapters/mongo_adapter.rb +22 -0
- data/adapters/hikki-mongo/lib/hikki/adapters/mongo_collection.rb +86 -0
- data/adapters/hikki-mongo/spec/hikki/adapters/mongo_adapter_integration_spec.rb +39 -0
- data/adapters/hikki-mongo/spec/hikki/adapters/mongo_adapter_spec.rb +231 -0
- data/adapters/hikki-mongo/spec/spec_helper.rb +8 -0
- data/adapters/hikki-redis/.rspec +2 -0
- data/adapters/hikki-redis/.travis.yml +3 -0
- data/adapters/hikki-redis/Gemfile +7 -0
- data/adapters/hikki-redis/LICENSE.txt +22 -0
- data/adapters/hikki-redis/README.md +44 -0
- data/adapters/hikki-redis/Rakefile +6 -0
- data/adapters/hikki-redis/hikki-redis.gemspec +27 -0
- data/adapters/hikki-redis/lib/hikki/adapters/redis_adapter.rb +21 -0
- data/adapters/hikki-redis/lib/hikki/adapters/redis_collection.rb +105 -0
- data/adapters/hikki-redis/spec/hikki/adapters/redis_adapter_integration_spec.rb +39 -0
- data/adapters/hikki-redis/spec/hikki/adapters/redis_adapter_spec.rb +258 -0
- data/adapters/hikki-redis/spec/spec_helper.rb +8 -0
- data/all_specs +13 -0
- data/hikki.gemspec +24 -0
- data/lib/hikki.rb +9 -0
- data/lib/hikki/adapters/adapter.rb +43 -0
- data/lib/hikki/adapters/memory_adapter.rb +18 -0
- data/lib/hikki/adapters/memory_collection.rb +87 -0
- data/lib/hikki/collection.rb +62 -0
- data/lib/hikki/repository.rb +54 -0
- data/lib/hikki/version.rb +3 -0
- data/spec/hikki/adapters/memory_adapter_spec.rb +242 -0
- data/spec/hikki/repository_spec.rb +260 -0
- data/spec/hikki_spec.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08957b3a154474bf8776ae760a82d17b320fbd9c
|
4
|
+
data.tar.gz: 2d91c550f7242fb6ba5e8a9279dd5da0067940f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b6aa2e88a9ebc8a0e473840f923cab9d0ebb68139f9b046b829baf04fd559019f5b80eb40d7e9993f8ca49c77ce56626280efba0b2c1723e1b0a304c55e905d
|
7
|
+
data.tar.gz: bb482c366cabd64be93648c020ac5ea5363c6b9f15121d5b987a28514a4173dcc1103ab3605519abe22f4de5e73c589fae18d4f0cc3cbfd5b96293e11897111b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Hikki
|
2
|
+
|
3
|
+
A light weight persistence system for use with key/value type data.
|
4
|
+
Hikki allows you to use a repository with one or more adapters for reading and writing data.
|
5
|
+
Data is represented as a `Hash` and should be seralizable to/from JSON.
|
6
|
+
Current adapters include:
|
7
|
+
|
8
|
+
* `Hikki:Adapters::MemoryAdapter`
|
9
|
+
* `Hikki:Adapters::RedisAdapter`
|
10
|
+
* `Hikki:Adapters::MongoAdapter`
|
11
|
+
* `Hikki:Adapters::MemcacheAdapter`
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'hikki'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install hikki
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
By default Hikki will use the included memory adapter.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Create a new repository
|
33
|
+
repository = Hikki::Repository.new
|
34
|
+
|
35
|
+
# Create an index on the name field for the people collection
|
36
|
+
repository.index :people, :name
|
37
|
+
|
38
|
+
# Save a hash of data
|
39
|
+
repository.save :people, { id: '1', name: 'Alex' }
|
40
|
+
|
41
|
+
# If you don't specify an id, most adapters will make one for you
|
42
|
+
repository.save :people, { name: 'Jim' } # => { 'id' => '8107326a-77b6-4018-bd0b-7588442ce36b', 'name' => 'Jim' }
|
43
|
+
|
44
|
+
# Get the data back
|
45
|
+
repository.find :people, '1' # => { 'id' => '1', 'name' => 'Jim' }
|
46
|
+
|
47
|
+
# Grab all of the records in a collection
|
48
|
+
repository.all :people
|
49
|
+
|
50
|
+
# You can add a limit and/or offset
|
51
|
+
repository.all :people, { limit: 10, offset: 20 }
|
52
|
+
|
53
|
+
# Find by a field (Also can take limit/offset options)
|
54
|
+
repository.find_by :people, :name, 'Alex'
|
55
|
+
|
56
|
+
# Remove a record
|
57
|
+
repository.remove :people, '1'
|
58
|
+
|
59
|
+
# Remove all records
|
60
|
+
repository.remove_all :people
|
61
|
+
```
|
62
|
+
|
63
|
+
Hikki supports repositories with multiple adapters for reading and writing.
|
64
|
+
It will write to all specified writers and read from the specified readers until a non-empty result is found.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
redis = Hikki::Adapters::RedisAdapter.new
|
68
|
+
mongo = Hikki::Adapters::MongoAdapter.new
|
69
|
+
|
70
|
+
# Hikki::Repository.new(writers, readers)
|
71
|
+
repository = Hikki::Repository.new([redis, mongo], [redis, mongo])
|
72
|
+
```
|
73
|
+
|
74
|
+
You can subclass `Hikki::Repository` and add conversions to your models.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class MyRepository < Hikki::Repository
|
78
|
+
def save(model)
|
79
|
+
result = super(model.class.name, model.to_hash)
|
80
|
+
model.update_from_hash(result)
|
81
|
+
end
|
82
|
+
|
83
|
+
def find(klass, id)
|
84
|
+
result = super(klass.name, id)
|
85
|
+
klass.new(result)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it ( http://github.com/originate/hikki/fork )
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Write your specifications
|
95
|
+
4. Implement your specifications
|
96
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
97
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
98
|
+
7. Create new Pull Request
|
data/Rakefile
ADDED
@@ -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,50 @@
|
|
1
|
+
# Hikki::Adapters::MemcacheAdapter
|
2
|
+
|
3
|
+
A Memcache adapter for Hikki.
|
4
|
+
It uses the `dalli` gem to communicate with Memcache.
|
5
|
+
Depending on expiry options and size of memory, all objects are not guaranteed to be available.
|
6
|
+
As such, `index`, `all`, and `find_by` are not implemented.
|
7
|
+
The `index` method will just return `false` if called.
|
8
|
+
The `all` and `find_by` will return `[]`. Due to the repository logic, if this adapter is your first
|
9
|
+
adapter then calling `all` on the repository will immediately try the next reader in the list.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'hikki-memcache'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install hikki-memcache
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
By default, the adapter will use `Dalli::Client.new('localhost:11211', { namespace: 'hikki', compress: true })` as
|
28
|
+
it's connection.
|
29
|
+
You can pass in your own connection to use instead, useful for specifying a server, namespace and other options.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Use the default connection
|
33
|
+
adapter = Hikki::Adapters::MemcacheAdapter.new
|
34
|
+
|
35
|
+
# Use a specific connection
|
36
|
+
cache = Dalli::Client.new('cache.example.com:11211', { namespace: 'my_cache' })
|
37
|
+
adapter = Hikki::Adapters::MemcacheAdapter.new(cache)
|
38
|
+
```
|
39
|
+
|
40
|
+
If you do not specify an `id` when saving, the adapter will generate a uuid using `SecureRandom`.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( http://github.com/originate/hikki/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Write your specifications
|
47
|
+
4. Implement your specifications
|
48
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
7. Create new Pull Request
|
@@ -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-memcache"
|
8
|
+
spec.version = Hikki::VERSION
|
9
|
+
spec.authors = ["alexpeachey"]
|
10
|
+
spec.email = ["alex.peachey@originate.com"]
|
11
|
+
spec.summary = 'A Memcache adapter for Hikki.'
|
12
|
+
spec.description = 'A Memcache 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 'dalli'
|
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,22 @@
|
|
1
|
+
require 'dalli'
|
2
|
+
require 'hikki'
|
3
|
+
require_relative './memcache_collection'
|
4
|
+
|
5
|
+
module Hikki
|
6
|
+
module Adapters
|
7
|
+
class MemcacheAdapter < Hikki::Adapters::Adapter
|
8
|
+
attr_reader :connection, :uuid_generator
|
9
|
+
|
10
|
+
def initialize(connection=Dalli::Client.new('localhost:11211', { namespace: 'hikki', compress: true }), 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, MemcacheCollection.new(collection, connection, uuid_generator))
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Hikki
|
2
|
+
module Adapters
|
3
|
+
class MemcacheCollection < 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
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def save(data)
|
17
|
+
data = normalize_data(data)
|
18
|
+
connection.set(key(data['id']), data)
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
def find(id)
|
23
|
+
connection.get(key(id)) || {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def all(options={})
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_by(field, value, options={})
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove(id)
|
35
|
+
connection.delete(key(id))
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_all
|
40
|
+
connection.flush
|
41
|
+
end
|
42
|
+
|
43
|
+
def id_for(data)
|
44
|
+
data.fetch('id', uuid_generator.uuid).to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def key(id)
|
49
|
+
collection + ':' + id.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hikki
|
4
|
+
module Adapters
|
5
|
+
describe MemcacheAdapter, :integration do
|
6
|
+
context 'when actually using Memcache' do
|
7
|
+
subject(:adapter) { MemcacheAdapter.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 []
|
20
|
+
expect(adapter.find_by(collection, :field1, 'test')).to eq []
|
21
|
+
expect(adapter.find_by(collection, :field2, 123)).to eq []
|
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 []
|
31
|
+
expect(adapter.find_by(collection, :field1, 'test-0', {limit: 2})).to eq []
|
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,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hikki
|
4
|
+
module Adapters
|
5
|
+
describe MemcacheAdapter do
|
6
|
+
subject(:adapter) { MemcacheAdapter.new(connection, uuid_generator) }
|
7
|
+
let(:connection) { double :connection, set: true, get: nil, delete: true, flush: true }
|
8
|
+
let(:uuid_generator) { double :uuid_generator, uuid: '12345' }
|
9
|
+
let(:collection) { 'collection1' }
|
10
|
+
|
11
|
+
describe '#index' do
|
12
|
+
it 'returns false' do
|
13
|
+
expect(adapter.index(collection, :field1)).to be_false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#save' do
|
18
|
+
context 'when an id is provided in the data' do
|
19
|
+
let(:data) { { id: id, field1: 'test', field2: 123 } }
|
20
|
+
let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
|
21
|
+
let(:id) { '1' }
|
22
|
+
let(:key) { collection + ':' + id }
|
23
|
+
|
24
|
+
it 'returns the data' do
|
25
|
+
expect(adapter.save(collection, data)).to eq expected
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'persists the data in the store' do
|
29
|
+
adapter.save(collection, data)
|
30
|
+
expect(connection).to have_received(:set).with(key, expected)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when an id is not provided in the data' do
|
35
|
+
let(:data) { { field1: 'test', field2: 123 } }
|
36
|
+
let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
|
37
|
+
let(:id) { '12345' }
|
38
|
+
let(:key) { collection + ':' + id }
|
39
|
+
|
40
|
+
it 'returns the data with the id added' do
|
41
|
+
expect(adapter.save(collection, data)).to eq expected
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'persists the data in the store' do
|
45
|
+
adapter.save(collection, data)
|
46
|
+
expect(connection).to have_received(:set).with(key, expected)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#find' do
|
52
|
+
let(:id) { '1' }
|
53
|
+
let(:key) { collection + ':' + id }
|
54
|
+
|
55
|
+
context 'when the id exists' do
|
56
|
+
let(:expected) { { 'id' => id, 'field1' => 'test', 'field2' => 123 } }
|
57
|
+
before { connection.stub(:get).with(key).and_return(expected) }
|
58
|
+
|
59
|
+
it 'retrieves the data' do
|
60
|
+
expect(adapter.find(collection, id)).to eq expected
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when the id does not exist' do
|
65
|
+
let(:expected) { {} }
|
66
|
+
before { connection.stub(:get).with(key).and_return(nil) }
|
67
|
+
|
68
|
+
it 'returns an empty hash' do
|
69
|
+
expect(adapter.find(collection, id)).to eq expected
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#all' do
|
75
|
+
it 'returns []' do
|
76
|
+
expect(adapter.all(collection)).to eq []
|
77
|
+
expect(adapter.all(collection, {})).to eq []
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#find_by' do
|
82
|
+
it 'returns []' do
|
83
|
+
expect(adapter.find_by(collection, :field1, 'test')).to eq []
|
84
|
+
expect(adapter.find_by(collection, :field1, 'test', {})).to eq []
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#remove' do
|
89
|
+
let(:id) { '1' }
|
90
|
+
let(:key) { collection + ':' + id }
|
91
|
+
|
92
|
+
it 'returns true' do
|
93
|
+
expect(adapter.remove(collection, id)).to be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'removes the record from the store' do
|
97
|
+
adapter.remove(collection, id)
|
98
|
+
expect(connection).to have_received(:delete).with(key)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#remove_all' do
|
103
|
+
it 'returns true' do
|
104
|
+
expect(adapter.remove_all(collection)).to be_true
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'removes all of the records from the store' do
|
108
|
+
adapter.remove_all(collection)
|
109
|
+
expect(connection).to have_received(:flush)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|