undo-storage-redis 0.0.3 → 0.0.4

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: edd9a180385da03e19b81be3edaae162dd0e3a7d
4
- data.tar.gz: 4069f20905bc6857bee257189028eb239419cffe
3
+ metadata.gz: c8a882c3f5c0a35076305a12e0ac865a59c69154
4
+ data.tar.gz: 75bce602064d04e209fa91b6bbdee752e020b0da
5
5
  SHA512:
6
- metadata.gz: 6a96814bcb3ba4dd9abab5996967afe1a19e4b2c7a7b8263b719b94b93cb3e576e33097699134f402c75bf01a406d0b05aac1f2002869010d9f449fafbdbb40d
7
- data.tar.gz: 4620e858d2ce08ef364ce300b5fea375c29c1e3a0891c4df7719ea80b4ef5ec7302482efff4e9339457d1619891557110d9a3d203cc89308c1973aa989f7fac5
6
+ metadata.gz: c12060ce18bae507d6559fa1ee796a4a93245fd8cb76348d865711d382810ddd10dbb000f806de21d7e5caa2a1f0d4c5fc38b68030ec19096a8172ef518e9542
7
+ data.tar.gz: baaee65da3bf978c953acf6e6431550052002fb49b88540b43737e744ff9eb5ae1286ea21b51823747a9f525be5802aa370ecf64b151e7db5f95a6ef9f310c4e
@@ -3,29 +3,30 @@ require 'json'
3
3
  module Undo
4
4
  module Storage
5
5
  class Redis
6
- VERSION = "0.0.3"
6
+ VERSION = "0.0.4"
7
7
 
8
8
  def initialize(redis, options = {})
9
9
  @redis = redis
10
+ @options = options
10
11
  end
11
12
 
12
13
  def put(uuid, object)
13
- redis.set uuid, serialize(object)
14
+ redis.set uuid, serialize(object), options
14
15
  end
15
16
 
16
17
  def fetch(uuid)
17
- deserialize redis.get(uuid)
18
+ deserialize redis.get uuid, options
18
19
  end
19
20
 
20
21
  private
21
- attr_reader :redis
22
+ attr_reader :redis, :options
22
23
 
23
24
  def serialize(object)
24
25
  object.to_json
25
26
  end
26
27
 
27
28
  def deserialize(data)
28
- JSON.parse data
29
+ JSON.load data
29
30
  end
30
31
  end
31
32
  end
@@ -6,12 +6,32 @@ describe Undo::Storage::Redis do
6
6
  let(:redis) { double :redis }
7
7
 
8
8
  it "writes hash to redis" do
9
- expect(redis).to receive(:set).with("123", '{"hello":"world"}')
9
+ expect(redis).to receive(:set).with "123", '{"hello":"world"}', anything
10
10
  adapter.put "123", "hello" => "world"
11
11
  end
12
12
 
13
13
  it "reads hash from redis" do
14
- expect(redis).to receive(:get).with("123") { '{"hello":"world"}' }
14
+ expect(redis).to receive(:get).with("123", anything) { '{"hello":"world"}' }
15
15
  expect(adapter.fetch "123").to eq "hello" => "world"
16
16
  end
17
+
18
+ describe "options" do
19
+ let(:adapter) { described_class.new redis, options }
20
+ let(:options) { { :additional => :option } }
21
+
22
+ it "sends provided options to redis.get" do
23
+ expect(redis).to receive(:get).with anything, options
24
+ adapter.fetch "foo"
25
+ end
26
+
27
+ it "sends provided options to redis.set" do
28
+ expect(redis).to receive(:set).with anything, anything, options
29
+ adapter.put "foo", "bar"
30
+ end
31
+
32
+ before do
33
+ # JSON.load behaves differently in 1.9
34
+ allow(redis).to receive(:get).with(any_args) { { :foo => :bar }.to_json }
35
+ end if RUBY_VERSION < "2.0"
36
+ end
17
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: undo-storage-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Paramonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-16 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler