moneta 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.travis.yml +39 -0
- data/Gemfile +61 -0
- data/LICENSE +2 -2
- data/README.md +450 -0
- data/Rakefile +29 -51
- data/SPEC.md +75 -0
- data/benchmarks/run.rb +195 -0
- data/lib/action_dispatch/middleware/session/moneta_store.rb +11 -0
- data/lib/active_support/cache/moneta_store.rb +55 -0
- data/lib/moneta.rb +121 -67
- data/lib/moneta/adapters/activerecord.rb +87 -0
- data/lib/moneta/adapters/cassandra.rb +91 -0
- data/lib/moneta/adapters/client.rb +69 -0
- data/lib/moneta/adapters/cookie.rb +35 -0
- data/lib/moneta/adapters/couch.rb +57 -0
- data/lib/moneta/adapters/datamapper.rb +75 -0
- data/lib/moneta/adapters/dbm.rb +25 -0
- data/lib/moneta/adapters/file.rb +79 -0
- data/lib/moneta/adapters/fog.rb +51 -0
- data/lib/moneta/adapters/gdbm.rb +25 -0
- data/lib/moneta/adapters/hbase.rb +101 -0
- data/lib/moneta/adapters/leveldb.rb +35 -0
- data/lib/moneta/adapters/localmemcache.rb +28 -0
- data/lib/moneta/adapters/lruhash.rb +85 -0
- data/lib/moneta/adapters/memcached.rb +11 -0
- data/lib/moneta/adapters/memcached_dalli.rb +69 -0
- data/lib/moneta/adapters/memcached_native.rb +70 -0
- data/lib/moneta/adapters/memory.rb +10 -0
- data/lib/moneta/adapters/mongo.rb +50 -0
- data/lib/moneta/adapters/null.rb +30 -0
- data/lib/moneta/adapters/pstore.rb +69 -0
- data/lib/moneta/adapters/redis.rb +68 -0
- data/lib/moneta/adapters/riak.rb +57 -0
- data/lib/moneta/adapters/sdbm.rb +35 -0
- data/lib/moneta/adapters/sequel.rb +79 -0
- data/lib/moneta/adapters/sqlite.rb +65 -0
- data/lib/moneta/adapters/tokyocabinet.rb +41 -0
- data/lib/moneta/adapters/yaml.rb +15 -0
- data/lib/moneta/base.rb +78 -0
- data/lib/moneta/builder.rb +39 -0
- data/lib/moneta/cache.rb +84 -0
- data/lib/moneta/expires.rb +71 -0
- data/lib/moneta/lock.rb +25 -0
- data/lib/moneta/logger.rb +61 -0
- data/lib/moneta/mixins.rb +65 -0
- data/lib/moneta/net.rb +18 -0
- data/lib/moneta/optionmerger.rb +39 -0
- data/lib/moneta/proxy.rb +86 -0
- data/lib/moneta/server.rb +81 -0
- data/lib/moneta/shared.rb +60 -0
- data/lib/moneta/stack.rb +78 -0
- data/lib/moneta/transformer.rb +159 -0
- data/lib/moneta/transformer/config.rb +42 -0
- data/lib/moneta/transformer/helper.rb +37 -0
- data/lib/moneta/version.rb +5 -0
- data/lib/moneta/wrapper.rb +33 -0
- data/lib/rack/cache/moneta.rb +93 -0
- data/lib/rack/moneta_cookies.rb +64 -0
- data/lib/rack/session/moneta.rb +63 -0
- data/moneta.gemspec +19 -0
- data/spec/action_dispatch/fixtures/session_autoload_test/foo.rb +10 -0
- data/spec/action_dispatch/session_moneta_store_spec.rb +196 -0
- data/spec/active_support/cache_moneta_store_spec.rb +197 -0
- data/spec/generate.rb +1489 -0
- data/spec/helper.rb +91 -0
- data/spec/moneta/adapter_activerecord_spec.rb +32 -0
- data/spec/moneta/adapter_cassandra_spec.rb +30 -0
- data/spec/moneta/adapter_client_spec.rb +19 -0
- data/spec/moneta/adapter_cookie_spec.rb +18 -0
- data/spec/moneta/adapter_couch_spec.rb +18 -0
- data/spec/moneta/adapter_datamapper_spec.rb +49 -0
- data/spec/moneta/adapter_dbm_spec.rb +18 -0
- data/spec/moneta/adapter_file_spec.rb +18 -0
- data/spec/moneta/adapter_fog_spec.rb +23 -0
- data/spec/moneta/adapter_gdbm_spec.rb +18 -0
- data/spec/moneta/adapter_hbase_spec.rb +18 -0
- data/spec/moneta/adapter_leveldb_spec.rb +18 -0
- data/spec/moneta/adapter_localmemcache_spec.rb +18 -0
- data/spec/moneta/adapter_lruhash_spec.rb +31 -0
- data/spec/moneta/adapter_memcached_dalli_spec.rb +30 -0
- data/spec/moneta/adapter_memcached_native_spec.rb +31 -0
- data/spec/moneta/adapter_memcached_spec.rb +30 -0
- data/spec/moneta/adapter_memory_spec.rb +39 -0
- data/spec/moneta/adapter_mongo_spec.rb +18 -0
- data/spec/moneta/adapter_pstore_spec.rb +21 -0
- data/spec/moneta/adapter_redis_spec.rb +30 -0
- data/spec/moneta/adapter_riak_spec.rb +22 -0
- data/spec/moneta/adapter_sdbm_spec.rb +18 -0
- data/spec/moneta/adapter_sequel_spec.rb +18 -0
- data/spec/moneta/adapter_sqlite_spec.rb +18 -0
- data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +18 -0
- data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +18 -0
- data/spec/moneta/adapter_yaml_spec.rb +21 -0
- data/spec/moneta/cache_file_memory_spec.rb +34 -0
- data/spec/moneta/cache_memory_null_spec.rb +23 -0
- data/spec/moneta/expires_file_spec.rb +76 -0
- data/spec/moneta/expires_memory_spec.rb +65 -0
- data/spec/moneta/lock_spec.rb +42 -0
- data/spec/moneta/null_adapter_spec.rb +26 -0
- data/spec/moneta/optionmerger_spec.rb +92 -0
- data/spec/moneta/proxy_expires_memory_spec.rb +55 -0
- data/spec/moneta/proxy_redis_spec.rb +23 -0
- data/spec/moneta/shared_spec.rb +30 -0
- data/spec/moneta/simple_activerecord_spec.rb +51 -0
- data/spec/moneta/simple_activerecord_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_cassandra_spec.rb +52 -0
- data/spec/moneta/simple_client_tcp_spec.rb +67 -0
- data/spec/moneta/simple_client_unix_spec.rb +53 -0
- data/spec/moneta/simple_couch_spec.rb +51 -0
- data/spec/moneta/simple_couch_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_datamapper_spec.rb +53 -0
- data/spec/moneta/simple_datamapper_with_expires_spec.rb +54 -0
- data/spec/moneta/simple_datamapper_with_repository_spec.rb +53 -0
- data/spec/moneta/simple_dbm_spec.rb +51 -0
- data/spec/moneta/simple_dbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_file_spec.rb +51 -0
- data/spec/moneta/simple_file_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_fog_spec.rb +56 -0
- data/spec/moneta/simple_fog_with_expires_spec.rb +58 -0
- data/spec/moneta/simple_gdbm_spec.rb +51 -0
- data/spec/moneta/simple_gdbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_hashfile_spec.rb +51 -0
- data/spec/moneta/simple_hashfile_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_hbase_spec.rb +51 -0
- data/spec/moneta/simple_hbase_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_leveldb_spec.rb +51 -0
- data/spec/moneta/simple_leveldb_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_localmemcache_spec.rb +51 -0
- data/spec/moneta/simple_localmemcache_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_lruhash_spec.rb +51 -0
- data/spec/moneta/simple_lruhash_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_memcached_dalli_spec.rb +52 -0
- data/spec/moneta/simple_memcached_native_spec.rb +52 -0
- data/spec/moneta/simple_memcached_spec.rb +52 -0
- data/spec/moneta/simple_memory_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_compress_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_memory_with_json_key_serializer_spec.rb +37 -0
- data/spec/moneta/simple_memory_with_json_serializer_spec.rb +28 -0
- data/spec/moneta/simple_memory_with_json_value_serializer_spec.rb +35 -0
- data/spec/moneta/simple_memory_with_prefix_spec.rb +51 -0
- data/spec/moneta/simple_memory_with_snappy_compress_spec.rb +51 -0
- data/spec/moneta/simple_mongo_spec.rb +51 -0
- data/spec/moneta/simple_mongo_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_null_spec.rb +36 -0
- data/spec/moneta/simple_pstore_spec.rb +51 -0
- data/spec/moneta/simple_pstore_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_redis_spec.rb +52 -0
- data/spec/moneta/simple_riak_spec.rb +55 -0
- data/spec/moneta/simple_riak_with_expires_spec.rb +56 -0
- data/spec/moneta/simple_sdbm_spec.rb +51 -0
- data/spec/moneta/simple_sdbm_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_sequel_spec.rb +51 -0
- data/spec/moneta/simple_sequel_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_sqlite_spec.rb +51 -0
- data/spec/moneta/simple_sqlite_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_tokyocabinet_spec.rb +51 -0
- data/spec/moneta/simple_tokyocabinet_with_expires_spec.rb +52 -0
- data/spec/moneta/simple_yaml_spec.rb +50 -0
- data/spec/moneta/simple_yaml_with_expires_spec.rb +51 -0
- data/spec/moneta/stack_file_memory_spec.rb +25 -0
- data/spec/moneta/stack_memory_file_spec.rb +24 -0
- data/spec/moneta/transformer_bencode_spec.rb +30 -0
- data/spec/moneta/transformer_bert_spec.rb +30 -0
- data/spec/moneta/transformer_bson_spec.rb +30 -0
- data/spec/moneta/transformer_bzip2_spec.rb +27 -0
- data/spec/moneta/transformer_json_spec.rb +30 -0
- data/spec/moneta/transformer_lzma_spec.rb +27 -0
- data/spec/moneta/transformer_lzo_spec.rb +27 -0
- data/spec/moneta/transformer_marshal_base64_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_escape_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_hmac_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_md5_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_md5_spread_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_prefix_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_rmd160_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha1_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha256_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha384_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_sha512_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_truncate_spec.rb +54 -0
- data/spec/moneta/transformer_marshal_uuencode_spec.rb +54 -0
- data/spec/moneta/transformer_msgpack_spec.rb +30 -0
- data/spec/moneta/transformer_ox_spec.rb +51 -0
- data/spec/moneta/transformer_quicklz_spec.rb +27 -0
- data/spec/moneta/transformer_snappy_spec.rb +27 -0
- data/spec/moneta/transformer_tnet_spec.rb +30 -0
- data/spec/moneta/transformer_yaml_spec.rb +51 -0
- data/spec/moneta/transformer_zlib_spec.rb +27 -0
- data/spec/monetaspecs.rb +2663 -0
- data/spec/rack/cache_moneta_spec.rb +355 -0
- data/spec/rack/moneta_cookies_spec.rb +81 -0
- data/spec/rack/session_moneta_spec.rb +305 -0
- metadata +359 -56
- data/README +0 -51
- data/TODO +0 -4
- data/lib/moneta/basic_file.rb +0 -111
- data/lib/moneta/berkeley.rb +0 -53
- data/lib/moneta/couch.rb +0 -63
- data/lib/moneta/datamapper.rb +0 -117
- data/lib/moneta/file.rb +0 -91
- data/lib/moneta/lmc.rb +0 -52
- data/lib/moneta/memcache.rb +0 -52
- data/lib/moneta/memory.rb +0 -11
- data/lib/moneta/mongodb.rb +0 -58
- data/lib/moneta/redis.rb +0 -49
- data/lib/moneta/rufus.rb +0 -41
- data/lib/moneta/s3.rb +0 -162
- data/lib/moneta/sdbm.rb +0 -33
- data/lib/moneta/tyrant.rb +0 -58
- data/lib/moneta/xattr.rb +0 -58
@@ -0,0 +1,30 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_msgpack" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :key => :msgpack, :value => :msgpack
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::MessagePack.unpack(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_hashkey_hashvalue'
|
18
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_stringkey_hashvalue'
|
20
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
21
|
+
it_should_behave_like 'store_hashkey_hashvalue'
|
22
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
23
|
+
it_should_behave_like 'store_stringkey_hashvalue'
|
24
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
25
|
+
it_should_behave_like 'returndifferent_hashkey_hashvalue'
|
26
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
27
|
+
it_should_behave_like 'returndifferent_stringkey_hashvalue'
|
28
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
29
|
+
it_should_behave_like 'transform_value'
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_ox" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :key => :ox, :value => :ox
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::Ox.parse_obj(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_objectkey_objectvalue'
|
18
|
+
it_should_behave_like 'null_objectkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_objectkey_hashvalue'
|
20
|
+
it_should_behave_like 'null_objectkey_booleanvalue'
|
21
|
+
it_should_behave_like 'null_stringkey_objectvalue'
|
22
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
23
|
+
it_should_behave_like 'null_stringkey_hashvalue'
|
24
|
+
it_should_behave_like 'null_stringkey_booleanvalue'
|
25
|
+
it_should_behave_like 'null_hashkey_objectvalue'
|
26
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
27
|
+
it_should_behave_like 'null_hashkey_hashvalue'
|
28
|
+
it_should_behave_like 'null_hashkey_booleanvalue'
|
29
|
+
it_should_behave_like 'store_objectkey_objectvalue'
|
30
|
+
it_should_behave_like 'store_objectkey_stringvalue'
|
31
|
+
it_should_behave_like 'store_objectkey_hashvalue'
|
32
|
+
it_should_behave_like 'store_objectkey_booleanvalue'
|
33
|
+
it_should_behave_like 'store_stringkey_objectvalue'
|
34
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
35
|
+
it_should_behave_like 'store_stringkey_hashvalue'
|
36
|
+
it_should_behave_like 'store_stringkey_booleanvalue'
|
37
|
+
it_should_behave_like 'store_hashkey_objectvalue'
|
38
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
39
|
+
it_should_behave_like 'store_hashkey_hashvalue'
|
40
|
+
it_should_behave_like 'store_hashkey_booleanvalue'
|
41
|
+
it_should_behave_like 'returndifferent_objectkey_objectvalue'
|
42
|
+
it_should_behave_like 'returndifferent_objectkey_stringvalue'
|
43
|
+
it_should_behave_like 'returndifferent_objectkey_hashvalue'
|
44
|
+
it_should_behave_like 'returndifferent_stringkey_objectvalue'
|
45
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
46
|
+
it_should_behave_like 'returndifferent_stringkey_hashvalue'
|
47
|
+
it_should_behave_like 'returndifferent_hashkey_objectvalue'
|
48
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
49
|
+
it_should_behave_like 'returndifferent_hashkey_hashvalue'
|
50
|
+
it_should_behave_like 'transform_value'
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_quicklz" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :value => :quicklz
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::QuickLZ.decompress(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_objectkey_stringvalue'
|
18
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
20
|
+
it_should_behave_like 'store_objectkey_stringvalue'
|
21
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
22
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
23
|
+
it_should_behave_like 'returndifferent_objectkey_stringvalue'
|
24
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
25
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
26
|
+
it_should_behave_like 'transform_value'
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_snappy" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :value => :snappy
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::Snappy.inflate(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_objectkey_stringvalue'
|
18
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
20
|
+
it_should_behave_like 'store_objectkey_stringvalue'
|
21
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
22
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
23
|
+
it_should_behave_like 'returndifferent_objectkey_stringvalue'
|
24
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
25
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
26
|
+
it_should_behave_like 'transform_value'
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_tnet" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :key => :tnet, :value => :tnet
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::TNetstring.parse(value).first
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_hashkey_hashvalue'
|
18
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_stringkey_hashvalue'
|
20
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
21
|
+
it_should_behave_like 'store_hashkey_hashvalue'
|
22
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
23
|
+
it_should_behave_like 'store_stringkey_hashvalue'
|
24
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
25
|
+
it_should_behave_like 'returndifferent_hashkey_hashvalue'
|
26
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
27
|
+
it_should_behave_like 'returndifferent_stringkey_hashvalue'
|
28
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
29
|
+
it_should_behave_like 'transform_value'
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_yaml" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :key => :yaml, :value => :yaml
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::YAML.load(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_objectkey_objectvalue'
|
18
|
+
it_should_behave_like 'null_objectkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_objectkey_hashvalue'
|
20
|
+
it_should_behave_like 'null_objectkey_booleanvalue'
|
21
|
+
it_should_behave_like 'null_stringkey_objectvalue'
|
22
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
23
|
+
it_should_behave_like 'null_stringkey_hashvalue'
|
24
|
+
it_should_behave_like 'null_stringkey_booleanvalue'
|
25
|
+
it_should_behave_like 'null_hashkey_objectvalue'
|
26
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
27
|
+
it_should_behave_like 'null_hashkey_hashvalue'
|
28
|
+
it_should_behave_like 'null_hashkey_booleanvalue'
|
29
|
+
it_should_behave_like 'store_objectkey_objectvalue'
|
30
|
+
it_should_behave_like 'store_objectkey_stringvalue'
|
31
|
+
it_should_behave_like 'store_objectkey_hashvalue'
|
32
|
+
it_should_behave_like 'store_objectkey_booleanvalue'
|
33
|
+
it_should_behave_like 'store_stringkey_objectvalue'
|
34
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
35
|
+
it_should_behave_like 'store_stringkey_hashvalue'
|
36
|
+
it_should_behave_like 'store_stringkey_booleanvalue'
|
37
|
+
it_should_behave_like 'store_hashkey_objectvalue'
|
38
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
39
|
+
it_should_behave_like 'store_hashkey_hashvalue'
|
40
|
+
it_should_behave_like 'store_hashkey_booleanvalue'
|
41
|
+
it_should_behave_like 'returndifferent_objectkey_objectvalue'
|
42
|
+
it_should_behave_like 'returndifferent_objectkey_stringvalue'
|
43
|
+
it_should_behave_like 'returndifferent_objectkey_hashvalue'
|
44
|
+
it_should_behave_like 'returndifferent_stringkey_objectvalue'
|
45
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
46
|
+
it_should_behave_like 'returndifferent_stringkey_hashvalue'
|
47
|
+
it_should_behave_like 'returndifferent_hashkey_objectvalue'
|
48
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
49
|
+
it_should_behave_like 'returndifferent_hashkey_hashvalue'
|
50
|
+
it_should_behave_like 'transform_value'
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe_moneta "transformer_zlib" do
|
5
|
+
def new_store
|
6
|
+
Moneta.build do
|
7
|
+
use :Transformer, :value => :zlib
|
8
|
+
adapter :Memory
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_value(value)
|
13
|
+
::Zlib::Inflate.inflate(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
include_context 'setup_store'
|
17
|
+
it_should_behave_like 'null_objectkey_stringvalue'
|
18
|
+
it_should_behave_like 'null_stringkey_stringvalue'
|
19
|
+
it_should_behave_like 'null_hashkey_stringvalue'
|
20
|
+
it_should_behave_like 'store_objectkey_stringvalue'
|
21
|
+
it_should_behave_like 'store_stringkey_stringvalue'
|
22
|
+
it_should_behave_like 'store_hashkey_stringvalue'
|
23
|
+
it_should_behave_like 'returndifferent_objectkey_stringvalue'
|
24
|
+
it_should_behave_like 'returndifferent_stringkey_stringvalue'
|
25
|
+
it_should_behave_like 'returndifferent_hashkey_stringvalue'
|
26
|
+
it_should_behave_like 'transform_value'
|
27
|
+
end
|
data/spec/monetaspecs.rb
ADDED
@@ -0,0 +1,2663 @@
|
|
1
|
+
# Generated by generate.rb
|
2
|
+
|
3
|
+
#################### null_stringkey_booleanvalue ####################
|
4
|
+
|
5
|
+
shared_examples_for 'null_stringkey_booleanvalue' do
|
6
|
+
it "reads from keys that are Strings like a Hash" do
|
7
|
+
store["strkey1"].should == nil
|
8
|
+
store.load("strkey1").should == nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "guarantees that the same Boolean value is returned when setting a String key" do
|
12
|
+
value = true
|
13
|
+
(store["strkey1"] = value).should equal(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false from key? if a String key is not available" do
|
17
|
+
store.key?("strkey1").should == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil from delete if an element for a String key does not exist" do
|
21
|
+
store.delete("strkey1").should == nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "removes all String keys from the store with clear" do
|
25
|
+
store["strkey1"] = true
|
26
|
+
store["strkey2"] = false
|
27
|
+
store.clear.should equal(store)
|
28
|
+
store.key?("strkey1").should_not == true
|
29
|
+
store.key?("strkey2").should_not == true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "fetches a String key with a default value with fetch, if the key is not available" do
|
33
|
+
store.fetch("strkey1", true).should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "fetches a String key with a block with fetch, if the key is not available" do
|
37
|
+
key = "strkey1"
|
38
|
+
value = true
|
39
|
+
store.fetch(key) do |k|
|
40
|
+
k.should equal(key)
|
41
|
+
value
|
42
|
+
end.should equal(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should accept options' do
|
46
|
+
store.key?("strkey1", :option1 => 1).should == false
|
47
|
+
store.load("strkey1", :option2 => 2).should == nil
|
48
|
+
store.fetch("strkey1", 42, :option3 => 3).should == 42
|
49
|
+
store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
|
50
|
+
store.delete("strkey1", :option4 => 4).should == nil
|
51
|
+
store.clear(:option5 => 5).should equal(store)
|
52
|
+
store.store("strkey1", true, :option6 => 6).should == true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#################### store_stringkey_booleanvalue ####################
|
57
|
+
|
58
|
+
shared_examples_for 'store_stringkey_booleanvalue' do
|
59
|
+
it "writes Boolean values to keys that are Strings like a Hash" do
|
60
|
+
store["strkey1"] = true
|
61
|
+
store["strkey1"].should == true
|
62
|
+
store.load("strkey1").should == true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns true from key? if a String key is available" do
|
66
|
+
store["strkey1"] = true
|
67
|
+
store.key?("strkey1").should == true
|
68
|
+
store["strkey2"] = false
|
69
|
+
store.key?("strkey2").should == true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "stores Boolean values with String keys with #store" do
|
73
|
+
value = true
|
74
|
+
store.store("strkey1", value).should equal(value)
|
75
|
+
store["strkey1"].should == true
|
76
|
+
store.load("strkey1").should == true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "stores String after clear" do
|
80
|
+
store["strkey1"] = true
|
81
|
+
store["strkey2"] = false
|
82
|
+
store.clear.should equal(store)
|
83
|
+
store["strkey1"] = true
|
84
|
+
store["strkey1"].should == true
|
85
|
+
store["strkey2"].should be_nil
|
86
|
+
end
|
87
|
+
|
88
|
+
it "removes and returns a Boolean element with a String key from the backing store via delete if it exists" do
|
89
|
+
store["strkey1"] = true
|
90
|
+
store.delete("strkey1").should == true
|
91
|
+
store.key?("strkey1").should == false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "overwrites existing Boolean values with String" do
|
95
|
+
store["strkey1"] = true
|
96
|
+
store["strkey1"].should == true
|
97
|
+
store["strkey1"] = false
|
98
|
+
store["strkey1"].should == false
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not run the block if the String key is available" do
|
102
|
+
store["strkey1"] = true
|
103
|
+
unaltered = "unaltered"
|
104
|
+
store.fetch("strkey1") { unaltered = "altered" }
|
105
|
+
unaltered.should == "unaltered"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "fetches a String key with a default value with fetch, if the key is available" do
|
109
|
+
store["strkey1"] = true
|
110
|
+
store.fetch("strkey1", false).should == true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#################### expires_stringkey_booleanvalue ####################
|
115
|
+
|
116
|
+
shared_examples_for 'expires_stringkey_booleanvalue' do
|
117
|
+
it 'should support expires on store and #[]' do
|
118
|
+
store.store("strkey1", true, :expires => 2)
|
119
|
+
store["strkey1"].should == true
|
120
|
+
sleep 1
|
121
|
+
store["strkey1"].should == true
|
122
|
+
sleep 2
|
123
|
+
store["strkey1"].should == nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should support expires on store and load' do
|
127
|
+
store.store("strkey1", true, :expires => 2)
|
128
|
+
store.load("strkey1").should == true
|
129
|
+
sleep 1
|
130
|
+
store.load("strkey1").should == true
|
131
|
+
sleep 2
|
132
|
+
store.load("strkey1").should == nil
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should support expires on store and key?' do
|
136
|
+
store.store("strkey1", true, :expires => 2)
|
137
|
+
store.key?("strkey1").should == true
|
138
|
+
sleep 1
|
139
|
+
store.key?("strkey1").should == true
|
140
|
+
sleep 2
|
141
|
+
store.key?("strkey1").should == false
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should support updating the expiration time in load' do
|
145
|
+
store.store("strkey2", false, :expires => 2)
|
146
|
+
store["strkey2"].should == false
|
147
|
+
sleep 1
|
148
|
+
store.load("strkey2", :expires => 3).should == false
|
149
|
+
store["strkey2"].should == false
|
150
|
+
sleep 1
|
151
|
+
store["strkey2"].should == false
|
152
|
+
sleep 3
|
153
|
+
store["strkey2"].should == nil
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should support updating the expiration time in key?' do
|
157
|
+
store.store("strkey2", false, :expires => 2)
|
158
|
+
store["strkey2"].should == false
|
159
|
+
sleep 1
|
160
|
+
store.key?("strkey2", :expires => 3).should be_true
|
161
|
+
store["strkey2"].should == false
|
162
|
+
sleep 1
|
163
|
+
store["strkey2"].should == false
|
164
|
+
sleep 3
|
165
|
+
store["strkey2"].should == nil
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should support updating the expiration time in fetch' do
|
169
|
+
store.store("strkey1", true, :expires => 2)
|
170
|
+
store["strkey1"].should == true
|
171
|
+
sleep 1
|
172
|
+
store.fetch("strkey1", nil, :expires => 3).should == true
|
173
|
+
store["strkey1"].should == true
|
174
|
+
sleep 1
|
175
|
+
store["strkey1"].should == true
|
176
|
+
sleep 3
|
177
|
+
store["strkey1"].should == nil
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should respect expires in delete' do
|
181
|
+
store.store("strkey2", false, :expires => 2)
|
182
|
+
store["strkey2"].should == false
|
183
|
+
sleep 1
|
184
|
+
store["strkey2"].should == false
|
185
|
+
sleep 2
|
186
|
+
store.delete("strkey2").should == nil
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should support the #expires syntactic sugar' do
|
190
|
+
store['longlive_key'] = 'longlive_value'
|
191
|
+
store.expires(2).store("strkey2", false)
|
192
|
+
store["strkey2"].should == false
|
193
|
+
sleep 1
|
194
|
+
store["strkey2"].should == false
|
195
|
+
sleep 2
|
196
|
+
store.delete("strkey2").should == nil
|
197
|
+
store['longlive_key'].should == 'longlive_value'
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
#################### null_stringkey_stringvalue ####################
|
202
|
+
|
203
|
+
shared_examples_for 'null_stringkey_stringvalue' do
|
204
|
+
it "reads from keys that are Strings like a Hash" do
|
205
|
+
store["strkey1"].should == nil
|
206
|
+
store.load("strkey1").should == nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it "guarantees that the same String value is returned when setting a String key" do
|
210
|
+
value = "strval1"
|
211
|
+
(store["strkey1"] = value).should equal(value)
|
212
|
+
end
|
213
|
+
|
214
|
+
it "returns false from key? if a String key is not available" do
|
215
|
+
store.key?("strkey1").should == false
|
216
|
+
end
|
217
|
+
|
218
|
+
it "returns nil from delete if an element for a String key does not exist" do
|
219
|
+
store.delete("strkey1").should == nil
|
220
|
+
end
|
221
|
+
|
222
|
+
it "removes all String keys from the store with clear" do
|
223
|
+
store["strkey1"] = "strval1"
|
224
|
+
store["strkey2"] = "strval2"
|
225
|
+
store.clear.should equal(store)
|
226
|
+
store.key?("strkey1").should_not == true
|
227
|
+
store.key?("strkey2").should_not == true
|
228
|
+
end
|
229
|
+
|
230
|
+
it "fetches a String key with a default value with fetch, if the key is not available" do
|
231
|
+
store.fetch("strkey1", "strval1").should == "strval1"
|
232
|
+
end
|
233
|
+
|
234
|
+
it "fetches a String key with a block with fetch, if the key is not available" do
|
235
|
+
key = "strkey1"
|
236
|
+
value = "strval1"
|
237
|
+
store.fetch(key) do |k|
|
238
|
+
k.should equal(key)
|
239
|
+
value
|
240
|
+
end.should equal(value)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should accept options' do
|
244
|
+
store.key?("strkey1", :option1 => 1).should == false
|
245
|
+
store.load("strkey1", :option2 => 2).should == nil
|
246
|
+
store.fetch("strkey1", 42, :option3 => 3).should == 42
|
247
|
+
store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
|
248
|
+
store.delete("strkey1", :option4 => 4).should == nil
|
249
|
+
store.clear(:option5 => 5).should equal(store)
|
250
|
+
store.store("strkey1", "strval1", :option6 => 6).should == "strval1"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
#################### store_stringkey_stringvalue ####################
|
255
|
+
|
256
|
+
shared_examples_for 'store_stringkey_stringvalue' do
|
257
|
+
it "writes String values to keys that are Strings like a Hash" do
|
258
|
+
store["strkey1"] = "strval1"
|
259
|
+
store["strkey1"].should == "strval1"
|
260
|
+
store.load("strkey1").should == "strval1"
|
261
|
+
end
|
262
|
+
|
263
|
+
it "returns true from key? if a String key is available" do
|
264
|
+
store["strkey1"] = "strval1"
|
265
|
+
store.key?("strkey1").should == true
|
266
|
+
store["strkey2"] = "strval2"
|
267
|
+
store.key?("strkey2").should == true
|
268
|
+
end
|
269
|
+
|
270
|
+
it "stores String values with String keys with #store" do
|
271
|
+
value = "strval1"
|
272
|
+
store.store("strkey1", value).should equal(value)
|
273
|
+
store["strkey1"].should == "strval1"
|
274
|
+
store.load("strkey1").should == "strval1"
|
275
|
+
end
|
276
|
+
|
277
|
+
it "stores String after clear" do
|
278
|
+
store["strkey1"] = "strval1"
|
279
|
+
store["strkey2"] = "strval2"
|
280
|
+
store.clear.should equal(store)
|
281
|
+
store["strkey1"] = "strval1"
|
282
|
+
store["strkey1"].should == "strval1"
|
283
|
+
store["strkey2"].should be_nil
|
284
|
+
end
|
285
|
+
|
286
|
+
it "removes and returns a String element with a String key from the backing store via delete if it exists" do
|
287
|
+
store["strkey1"] = "strval1"
|
288
|
+
store.delete("strkey1").should == "strval1"
|
289
|
+
store.key?("strkey1").should == false
|
290
|
+
end
|
291
|
+
|
292
|
+
it "overwrites existing String values with String" do
|
293
|
+
store["strkey1"] = "strval1"
|
294
|
+
store["strkey1"].should == "strval1"
|
295
|
+
store["strkey1"] = "strval2"
|
296
|
+
store["strkey1"].should == "strval2"
|
297
|
+
end
|
298
|
+
|
299
|
+
it "does not run the block if the String key is available" do
|
300
|
+
store["strkey1"] = "strval1"
|
301
|
+
unaltered = "unaltered"
|
302
|
+
store.fetch("strkey1") { unaltered = "altered" }
|
303
|
+
unaltered.should == "unaltered"
|
304
|
+
end
|
305
|
+
|
306
|
+
it "fetches a String key with a default value with fetch, if the key is available" do
|
307
|
+
store["strkey1"] = "strval1"
|
308
|
+
store.fetch("strkey1", "strval2").should == "strval1"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
#################### returndifferent_stringkey_stringvalue ####################
|
313
|
+
|
314
|
+
shared_examples_for 'returndifferent_stringkey_stringvalue' do
|
315
|
+
it "guarantees that a different String value is retrieved from the String key" do
|
316
|
+
value = "strval1"
|
317
|
+
store["strkey1"] = "strval1"
|
318
|
+
store["strkey1"].should_not be_equal("strval1")
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
#################### expires_stringkey_stringvalue ####################
|
323
|
+
|
324
|
+
shared_examples_for 'expires_stringkey_stringvalue' do
|
325
|
+
it 'should support expires on store and #[]' do
|
326
|
+
store.store("strkey1", "strval1", :expires => 2)
|
327
|
+
store["strkey1"].should == "strval1"
|
328
|
+
sleep 1
|
329
|
+
store["strkey1"].should == "strval1"
|
330
|
+
sleep 2
|
331
|
+
store["strkey1"].should == nil
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should support expires on store and load' do
|
335
|
+
store.store("strkey1", "strval1", :expires => 2)
|
336
|
+
store.load("strkey1").should == "strval1"
|
337
|
+
sleep 1
|
338
|
+
store.load("strkey1").should == "strval1"
|
339
|
+
sleep 2
|
340
|
+
store.load("strkey1").should == nil
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should support expires on store and key?' do
|
344
|
+
store.store("strkey1", "strval1", :expires => 2)
|
345
|
+
store.key?("strkey1").should == true
|
346
|
+
sleep 1
|
347
|
+
store.key?("strkey1").should == true
|
348
|
+
sleep 2
|
349
|
+
store.key?("strkey1").should == false
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should support updating the expiration time in load' do
|
353
|
+
store.store("strkey2", "strval2", :expires => 2)
|
354
|
+
store["strkey2"].should == "strval2"
|
355
|
+
sleep 1
|
356
|
+
store.load("strkey2", :expires => 3).should == "strval2"
|
357
|
+
store["strkey2"].should == "strval2"
|
358
|
+
sleep 1
|
359
|
+
store["strkey2"].should == "strval2"
|
360
|
+
sleep 3
|
361
|
+
store["strkey2"].should == nil
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'should support updating the expiration time in key?' do
|
365
|
+
store.store("strkey2", "strval2", :expires => 2)
|
366
|
+
store["strkey2"].should == "strval2"
|
367
|
+
sleep 1
|
368
|
+
store.key?("strkey2", :expires => 3).should be_true
|
369
|
+
store["strkey2"].should == "strval2"
|
370
|
+
sleep 1
|
371
|
+
store["strkey2"].should == "strval2"
|
372
|
+
sleep 3
|
373
|
+
store["strkey2"].should == nil
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'should support updating the expiration time in fetch' do
|
377
|
+
store.store("strkey1", "strval1", :expires => 2)
|
378
|
+
store["strkey1"].should == "strval1"
|
379
|
+
sleep 1
|
380
|
+
store.fetch("strkey1", nil, :expires => 3).should == "strval1"
|
381
|
+
store["strkey1"].should == "strval1"
|
382
|
+
sleep 1
|
383
|
+
store["strkey1"].should == "strval1"
|
384
|
+
sleep 3
|
385
|
+
store["strkey1"].should == nil
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'should respect expires in delete' do
|
389
|
+
store.store("strkey2", "strval2", :expires => 2)
|
390
|
+
store["strkey2"].should == "strval2"
|
391
|
+
sleep 1
|
392
|
+
store["strkey2"].should == "strval2"
|
393
|
+
sleep 2
|
394
|
+
store.delete("strkey2").should == nil
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should support the #expires syntactic sugar' do
|
398
|
+
store['longlive_key'] = 'longlive_value'
|
399
|
+
store.expires(2).store("strkey2", "strval2")
|
400
|
+
store["strkey2"].should == "strval2"
|
401
|
+
sleep 1
|
402
|
+
store["strkey2"].should == "strval2"
|
403
|
+
sleep 2
|
404
|
+
store.delete("strkey2").should == nil
|
405
|
+
store['longlive_key'].should == 'longlive_value'
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
#################### null_stringkey_hashvalue ####################
|
410
|
+
|
411
|
+
shared_examples_for 'null_stringkey_hashvalue' do
|
412
|
+
it "reads from keys that are Strings like a Hash" do
|
413
|
+
store["strkey1"].should == nil
|
414
|
+
store.load("strkey1").should == nil
|
415
|
+
end
|
416
|
+
|
417
|
+
it "guarantees that the same Hash value is returned when setting a String key" do
|
418
|
+
value = {"hashval1"=>["array1", 1]}
|
419
|
+
(store["strkey1"] = value).should equal(value)
|
420
|
+
end
|
421
|
+
|
422
|
+
it "returns false from key? if a String key is not available" do
|
423
|
+
store.key?("strkey1").should == false
|
424
|
+
end
|
425
|
+
|
426
|
+
it "returns nil from delete if an element for a String key does not exist" do
|
427
|
+
store.delete("strkey1").should == nil
|
428
|
+
end
|
429
|
+
|
430
|
+
it "removes all String keys from the store with clear" do
|
431
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
432
|
+
store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
433
|
+
store.clear.should equal(store)
|
434
|
+
store.key?("strkey1").should_not == true
|
435
|
+
store.key?("strkey2").should_not == true
|
436
|
+
end
|
437
|
+
|
438
|
+
it "fetches a String key with a default value with fetch, if the key is not available" do
|
439
|
+
store.fetch("strkey1", {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
|
440
|
+
end
|
441
|
+
|
442
|
+
it "fetches a String key with a block with fetch, if the key is not available" do
|
443
|
+
key = "strkey1"
|
444
|
+
value = {"hashval1"=>["array1", 1]}
|
445
|
+
store.fetch(key) do |k|
|
446
|
+
k.should equal(key)
|
447
|
+
value
|
448
|
+
end.should equal(value)
|
449
|
+
end
|
450
|
+
|
451
|
+
it 'should accept options' do
|
452
|
+
store.key?("strkey1", :option1 => 1).should == false
|
453
|
+
store.load("strkey1", :option2 => 2).should == nil
|
454
|
+
store.fetch("strkey1", 42, :option3 => 3).should == 42
|
455
|
+
store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
|
456
|
+
store.delete("strkey1", :option4 => 4).should == nil
|
457
|
+
store.clear(:option5 => 5).should equal(store)
|
458
|
+
store.store("strkey1", {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
#################### store_stringkey_hashvalue ####################
|
463
|
+
|
464
|
+
shared_examples_for 'store_stringkey_hashvalue' do
|
465
|
+
it "writes Hash values to keys that are Strings like a Hash" do
|
466
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
467
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
468
|
+
store.load("strkey1").should == {"hashval1"=>["array1", 1]}
|
469
|
+
end
|
470
|
+
|
471
|
+
it "returns true from key? if a String key is available" do
|
472
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
473
|
+
store.key?("strkey1").should == true
|
474
|
+
store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
475
|
+
store.key?("strkey2").should == true
|
476
|
+
end
|
477
|
+
|
478
|
+
it "stores Hash values with String keys with #store" do
|
479
|
+
value = {"hashval1"=>["array1", 1]}
|
480
|
+
store.store("strkey1", value).should equal(value)
|
481
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
482
|
+
store.load("strkey1").should == {"hashval1"=>["array1", 1]}
|
483
|
+
end
|
484
|
+
|
485
|
+
it "stores String after clear" do
|
486
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
487
|
+
store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
488
|
+
store.clear.should equal(store)
|
489
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
490
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
491
|
+
store["strkey2"].should be_nil
|
492
|
+
end
|
493
|
+
|
494
|
+
it "removes and returns a Hash element with a String key from the backing store via delete if it exists" do
|
495
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
496
|
+
store.delete("strkey1").should == {"hashval1"=>["array1", 1]}
|
497
|
+
store.key?("strkey1").should == false
|
498
|
+
end
|
499
|
+
|
500
|
+
it "overwrites existing Hash values with String" do
|
501
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
502
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
503
|
+
store["strkey1"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
504
|
+
store["strkey1"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
505
|
+
end
|
506
|
+
|
507
|
+
it "does not run the block if the String key is available" do
|
508
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
509
|
+
unaltered = "unaltered"
|
510
|
+
store.fetch("strkey1") { unaltered = "altered" }
|
511
|
+
unaltered.should == "unaltered"
|
512
|
+
end
|
513
|
+
|
514
|
+
it "fetches a String key with a default value with fetch, if the key is available" do
|
515
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
516
|
+
store.fetch("strkey1", {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
#################### returndifferent_stringkey_hashvalue ####################
|
521
|
+
|
522
|
+
shared_examples_for 'returndifferent_stringkey_hashvalue' do
|
523
|
+
it "guarantees that a different Hash value is retrieved from the String key" do
|
524
|
+
value = {"hashval1"=>["array1", 1]}
|
525
|
+
store["strkey1"] = {"hashval1"=>["array1", 1]}
|
526
|
+
store["strkey1"].should_not be_equal({"hashval1"=>["array1", 1]})
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
#################### expires_stringkey_hashvalue ####################
|
531
|
+
|
532
|
+
shared_examples_for 'expires_stringkey_hashvalue' do
|
533
|
+
it 'should support expires on store and #[]' do
|
534
|
+
store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
|
535
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
536
|
+
sleep 1
|
537
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
538
|
+
sleep 2
|
539
|
+
store["strkey1"].should == nil
|
540
|
+
end
|
541
|
+
|
542
|
+
it 'should support expires on store and load' do
|
543
|
+
store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
|
544
|
+
store.load("strkey1").should == {"hashval1"=>["array1", 1]}
|
545
|
+
sleep 1
|
546
|
+
store.load("strkey1").should == {"hashval1"=>["array1", 1]}
|
547
|
+
sleep 2
|
548
|
+
store.load("strkey1").should == nil
|
549
|
+
end
|
550
|
+
|
551
|
+
it 'should support expires on store and key?' do
|
552
|
+
store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
|
553
|
+
store.key?("strkey1").should == true
|
554
|
+
sleep 1
|
555
|
+
store.key?("strkey1").should == true
|
556
|
+
sleep 2
|
557
|
+
store.key?("strkey1").should == false
|
558
|
+
end
|
559
|
+
|
560
|
+
it 'should support updating the expiration time in load' do
|
561
|
+
store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
562
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
563
|
+
sleep 1
|
564
|
+
store.load("strkey2", :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
565
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
566
|
+
sleep 1
|
567
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
568
|
+
sleep 3
|
569
|
+
store["strkey2"].should == nil
|
570
|
+
end
|
571
|
+
|
572
|
+
it 'should support updating the expiration time in key?' do
|
573
|
+
store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
574
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
575
|
+
sleep 1
|
576
|
+
store.key?("strkey2", :expires => 3).should be_true
|
577
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
578
|
+
sleep 1
|
579
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
580
|
+
sleep 3
|
581
|
+
store["strkey2"].should == nil
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'should support updating the expiration time in fetch' do
|
585
|
+
store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
|
586
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
587
|
+
sleep 1
|
588
|
+
store.fetch("strkey1", nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
|
589
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
590
|
+
sleep 1
|
591
|
+
store["strkey1"].should == {"hashval1"=>["array1", 1]}
|
592
|
+
sleep 3
|
593
|
+
store["strkey1"].should == nil
|
594
|
+
end
|
595
|
+
|
596
|
+
it 'should respect expires in delete' do
|
597
|
+
store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
598
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
599
|
+
sleep 1
|
600
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
601
|
+
sleep 2
|
602
|
+
store.delete("strkey2").should == nil
|
603
|
+
end
|
604
|
+
|
605
|
+
it 'should support the #expires syntactic sugar' do
|
606
|
+
store['longlive_key'] = 'longlive_value'
|
607
|
+
store.expires(2).store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]})
|
608
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
609
|
+
sleep 1
|
610
|
+
store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
611
|
+
sleep 2
|
612
|
+
store.delete("strkey2").should == nil
|
613
|
+
store['longlive_key'].should == 'longlive_value'
|
614
|
+
end
|
615
|
+
end
|
616
|
+
|
617
|
+
#################### null_stringkey_objectvalue ####################
|
618
|
+
|
619
|
+
shared_examples_for 'null_stringkey_objectvalue' do
|
620
|
+
it "reads from keys that are Strings like a Hash" do
|
621
|
+
store["strkey1"].should == nil
|
622
|
+
store.load("strkey1").should == nil
|
623
|
+
end
|
624
|
+
|
625
|
+
it "guarantees that the same Object value is returned when setting a String key" do
|
626
|
+
value = Value.new(:objval1)
|
627
|
+
(store["strkey1"] = value).should equal(value)
|
628
|
+
end
|
629
|
+
|
630
|
+
it "returns false from key? if a String key is not available" do
|
631
|
+
store.key?("strkey1").should == false
|
632
|
+
end
|
633
|
+
|
634
|
+
it "returns nil from delete if an element for a String key does not exist" do
|
635
|
+
store.delete("strkey1").should == nil
|
636
|
+
end
|
637
|
+
|
638
|
+
it "removes all String keys from the store with clear" do
|
639
|
+
store["strkey1"] = Value.new(:objval1)
|
640
|
+
store["strkey2"] = Value.new(:objval2)
|
641
|
+
store.clear.should equal(store)
|
642
|
+
store.key?("strkey1").should_not == true
|
643
|
+
store.key?("strkey2").should_not == true
|
644
|
+
end
|
645
|
+
|
646
|
+
it "fetches a String key with a default value with fetch, if the key is not available" do
|
647
|
+
store.fetch("strkey1", Value.new(:objval1)).should == Value.new(:objval1)
|
648
|
+
end
|
649
|
+
|
650
|
+
it "fetches a String key with a block with fetch, if the key is not available" do
|
651
|
+
key = "strkey1"
|
652
|
+
value = Value.new(:objval1)
|
653
|
+
store.fetch(key) do |k|
|
654
|
+
k.should equal(key)
|
655
|
+
value
|
656
|
+
end.should equal(value)
|
657
|
+
end
|
658
|
+
|
659
|
+
it 'should accept options' do
|
660
|
+
store.key?("strkey1", :option1 => 1).should == false
|
661
|
+
store.load("strkey1", :option2 => 2).should == nil
|
662
|
+
store.fetch("strkey1", 42, :option3 => 3).should == 42
|
663
|
+
store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
|
664
|
+
store.delete("strkey1", :option4 => 4).should == nil
|
665
|
+
store.clear(:option5 => 5).should equal(store)
|
666
|
+
store.store("strkey1", Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
#################### store_stringkey_objectvalue ####################
|
671
|
+
|
672
|
+
shared_examples_for 'store_stringkey_objectvalue' do
|
673
|
+
it "writes Object values to keys that are Strings like a Hash" do
|
674
|
+
store["strkey1"] = Value.new(:objval1)
|
675
|
+
store["strkey1"].should == Value.new(:objval1)
|
676
|
+
store.load("strkey1").should == Value.new(:objval1)
|
677
|
+
end
|
678
|
+
|
679
|
+
it "returns true from key? if a String key is available" do
|
680
|
+
store["strkey1"] = Value.new(:objval1)
|
681
|
+
store.key?("strkey1").should == true
|
682
|
+
store["strkey2"] = Value.new(:objval2)
|
683
|
+
store.key?("strkey2").should == true
|
684
|
+
end
|
685
|
+
|
686
|
+
it "stores Object values with String keys with #store" do
|
687
|
+
value = Value.new(:objval1)
|
688
|
+
store.store("strkey1", value).should equal(value)
|
689
|
+
store["strkey1"].should == Value.new(:objval1)
|
690
|
+
store.load("strkey1").should == Value.new(:objval1)
|
691
|
+
end
|
692
|
+
|
693
|
+
it "stores String after clear" do
|
694
|
+
store["strkey1"] = Value.new(:objval1)
|
695
|
+
store["strkey2"] = Value.new(:objval2)
|
696
|
+
store.clear.should equal(store)
|
697
|
+
store["strkey1"] = Value.new(:objval1)
|
698
|
+
store["strkey1"].should == Value.new(:objval1)
|
699
|
+
store["strkey2"].should be_nil
|
700
|
+
end
|
701
|
+
|
702
|
+
it "removes and returns a Object element with a String key from the backing store via delete if it exists" do
|
703
|
+
store["strkey1"] = Value.new(:objval1)
|
704
|
+
store.delete("strkey1").should == Value.new(:objval1)
|
705
|
+
store.key?("strkey1").should == false
|
706
|
+
end
|
707
|
+
|
708
|
+
it "overwrites existing Object values with String" do
|
709
|
+
store["strkey1"] = Value.new(:objval1)
|
710
|
+
store["strkey1"].should == Value.new(:objval1)
|
711
|
+
store["strkey1"] = Value.new(:objval2)
|
712
|
+
store["strkey1"].should == Value.new(:objval2)
|
713
|
+
end
|
714
|
+
|
715
|
+
it "does not run the block if the String key is available" do
|
716
|
+
store["strkey1"] = Value.new(:objval1)
|
717
|
+
unaltered = "unaltered"
|
718
|
+
store.fetch("strkey1") { unaltered = "altered" }
|
719
|
+
unaltered.should == "unaltered"
|
720
|
+
end
|
721
|
+
|
722
|
+
it "fetches a String key with a default value with fetch, if the key is available" do
|
723
|
+
store["strkey1"] = Value.new(:objval1)
|
724
|
+
store.fetch("strkey1", Value.new(:objval2)).should == Value.new(:objval1)
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
728
|
+
#################### returndifferent_stringkey_objectvalue ####################
|
729
|
+
|
730
|
+
shared_examples_for 'returndifferent_stringkey_objectvalue' do
|
731
|
+
it "guarantees that a different Object value is retrieved from the String key" do
|
732
|
+
value = Value.new(:objval1)
|
733
|
+
store["strkey1"] = Value.new(:objval1)
|
734
|
+
store["strkey1"].should_not be_equal(Value.new(:objval1))
|
735
|
+
end
|
736
|
+
end
|
737
|
+
|
738
|
+
#################### expires_stringkey_objectvalue ####################
|
739
|
+
|
740
|
+
shared_examples_for 'expires_stringkey_objectvalue' do
|
741
|
+
it 'should support expires on store and #[]' do
|
742
|
+
store.store("strkey1", Value.new(:objval1), :expires => 2)
|
743
|
+
store["strkey1"].should == Value.new(:objval1)
|
744
|
+
sleep 1
|
745
|
+
store["strkey1"].should == Value.new(:objval1)
|
746
|
+
sleep 2
|
747
|
+
store["strkey1"].should == nil
|
748
|
+
end
|
749
|
+
|
750
|
+
it 'should support expires on store and load' do
|
751
|
+
store.store("strkey1", Value.new(:objval1), :expires => 2)
|
752
|
+
store.load("strkey1").should == Value.new(:objval1)
|
753
|
+
sleep 1
|
754
|
+
store.load("strkey1").should == Value.new(:objval1)
|
755
|
+
sleep 2
|
756
|
+
store.load("strkey1").should == nil
|
757
|
+
end
|
758
|
+
|
759
|
+
it 'should support expires on store and key?' do
|
760
|
+
store.store("strkey1", Value.new(:objval1), :expires => 2)
|
761
|
+
store.key?("strkey1").should == true
|
762
|
+
sleep 1
|
763
|
+
store.key?("strkey1").should == true
|
764
|
+
sleep 2
|
765
|
+
store.key?("strkey1").should == false
|
766
|
+
end
|
767
|
+
|
768
|
+
it 'should support updating the expiration time in load' do
|
769
|
+
store.store("strkey2", Value.new(:objval2), :expires => 2)
|
770
|
+
store["strkey2"].should == Value.new(:objval2)
|
771
|
+
sleep 1
|
772
|
+
store.load("strkey2", :expires => 3).should == Value.new(:objval2)
|
773
|
+
store["strkey2"].should == Value.new(:objval2)
|
774
|
+
sleep 1
|
775
|
+
store["strkey2"].should == Value.new(:objval2)
|
776
|
+
sleep 3
|
777
|
+
store["strkey2"].should == nil
|
778
|
+
end
|
779
|
+
|
780
|
+
it 'should support updating the expiration time in key?' do
|
781
|
+
store.store("strkey2", Value.new(:objval2), :expires => 2)
|
782
|
+
store["strkey2"].should == Value.new(:objval2)
|
783
|
+
sleep 1
|
784
|
+
store.key?("strkey2", :expires => 3).should be_true
|
785
|
+
store["strkey2"].should == Value.new(:objval2)
|
786
|
+
sleep 1
|
787
|
+
store["strkey2"].should == Value.new(:objval2)
|
788
|
+
sleep 3
|
789
|
+
store["strkey2"].should == nil
|
790
|
+
end
|
791
|
+
|
792
|
+
it 'should support updating the expiration time in fetch' do
|
793
|
+
store.store("strkey1", Value.new(:objval1), :expires => 2)
|
794
|
+
store["strkey1"].should == Value.new(:objval1)
|
795
|
+
sleep 1
|
796
|
+
store.fetch("strkey1", nil, :expires => 3).should == Value.new(:objval1)
|
797
|
+
store["strkey1"].should == Value.new(:objval1)
|
798
|
+
sleep 1
|
799
|
+
store["strkey1"].should == Value.new(:objval1)
|
800
|
+
sleep 3
|
801
|
+
store["strkey1"].should == nil
|
802
|
+
end
|
803
|
+
|
804
|
+
it 'should respect expires in delete' do
|
805
|
+
store.store("strkey2", Value.new(:objval2), :expires => 2)
|
806
|
+
store["strkey2"].should == Value.new(:objval2)
|
807
|
+
sleep 1
|
808
|
+
store["strkey2"].should == Value.new(:objval2)
|
809
|
+
sleep 2
|
810
|
+
store.delete("strkey2").should == nil
|
811
|
+
end
|
812
|
+
|
813
|
+
it 'should support the #expires syntactic sugar' do
|
814
|
+
store['longlive_key'] = 'longlive_value'
|
815
|
+
store.expires(2).store("strkey2", Value.new(:objval2))
|
816
|
+
store["strkey2"].should == Value.new(:objval2)
|
817
|
+
sleep 1
|
818
|
+
store["strkey2"].should == Value.new(:objval2)
|
819
|
+
sleep 2
|
820
|
+
store.delete("strkey2").should == nil
|
821
|
+
store['longlive_key'].should == 'longlive_value'
|
822
|
+
end
|
823
|
+
end
|
824
|
+
|
825
|
+
#################### null_objectkey_booleanvalue ####################
|
826
|
+
|
827
|
+
shared_examples_for 'null_objectkey_booleanvalue' do
|
828
|
+
it "reads from keys that are Objects like a Hash" do
|
829
|
+
store[Value.new(:objkey1)].should == nil
|
830
|
+
store.load(Value.new(:objkey1)).should == nil
|
831
|
+
end
|
832
|
+
|
833
|
+
it "guarantees that the same Boolean value is returned when setting a Object key" do
|
834
|
+
value = true
|
835
|
+
(store[Value.new(:objkey1)] = value).should equal(value)
|
836
|
+
end
|
837
|
+
|
838
|
+
it "returns false from key? if a Object key is not available" do
|
839
|
+
store.key?(Value.new(:objkey1)).should == false
|
840
|
+
end
|
841
|
+
|
842
|
+
it "returns nil from delete if an element for a Object key does not exist" do
|
843
|
+
store.delete(Value.new(:objkey1)).should == nil
|
844
|
+
end
|
845
|
+
|
846
|
+
it "removes all Object keys from the store with clear" do
|
847
|
+
store[Value.new(:objkey1)] = true
|
848
|
+
store[Value.new(:objkey2)] = false
|
849
|
+
store.clear.should equal(store)
|
850
|
+
store.key?(Value.new(:objkey1)).should_not == true
|
851
|
+
store.key?(Value.new(:objkey2)).should_not == true
|
852
|
+
end
|
853
|
+
|
854
|
+
it "fetches a Object key with a default value with fetch, if the key is not available" do
|
855
|
+
store.fetch(Value.new(:objkey1), true).should == true
|
856
|
+
end
|
857
|
+
|
858
|
+
it "fetches a Object key with a block with fetch, if the key is not available" do
|
859
|
+
key = Value.new(:objkey1)
|
860
|
+
value = true
|
861
|
+
store.fetch(key) do |k|
|
862
|
+
k.should equal(key)
|
863
|
+
value
|
864
|
+
end.should equal(value)
|
865
|
+
end
|
866
|
+
|
867
|
+
it 'should accept options' do
|
868
|
+
store.key?(Value.new(:objkey1), :option1 => 1).should == false
|
869
|
+
store.load(Value.new(:objkey1), :option2 => 2).should == nil
|
870
|
+
store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
|
871
|
+
store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
|
872
|
+
store.delete(Value.new(:objkey1), :option4 => 4).should == nil
|
873
|
+
store.clear(:option5 => 5).should equal(store)
|
874
|
+
store.store(Value.new(:objkey1), true, :option6 => 6).should == true
|
875
|
+
end
|
876
|
+
end
|
877
|
+
|
878
|
+
#################### store_objectkey_booleanvalue ####################
|
879
|
+
|
880
|
+
shared_examples_for 'store_objectkey_booleanvalue' do
|
881
|
+
it "writes Boolean values to keys that are Objects like a Hash" do
|
882
|
+
store[Value.new(:objkey1)] = true
|
883
|
+
store[Value.new(:objkey1)].should == true
|
884
|
+
store.load(Value.new(:objkey1)).should == true
|
885
|
+
end
|
886
|
+
|
887
|
+
it "returns true from key? if a Object key is available" do
|
888
|
+
store[Value.new(:objkey1)] = true
|
889
|
+
store.key?(Value.new(:objkey1)).should == true
|
890
|
+
store[Value.new(:objkey2)] = false
|
891
|
+
store.key?(Value.new(:objkey2)).should == true
|
892
|
+
end
|
893
|
+
|
894
|
+
it "stores Boolean values with Object keys with #store" do
|
895
|
+
value = true
|
896
|
+
store.store(Value.new(:objkey1), value).should equal(value)
|
897
|
+
store[Value.new(:objkey1)].should == true
|
898
|
+
store.load(Value.new(:objkey1)).should == true
|
899
|
+
end
|
900
|
+
|
901
|
+
it "stores Object after clear" do
|
902
|
+
store[Value.new(:objkey1)] = true
|
903
|
+
store[Value.new(:objkey2)] = false
|
904
|
+
store.clear.should equal(store)
|
905
|
+
store[Value.new(:objkey1)] = true
|
906
|
+
store[Value.new(:objkey1)].should == true
|
907
|
+
store[Value.new(:objkey2)].should be_nil
|
908
|
+
end
|
909
|
+
|
910
|
+
it "removes and returns a Boolean element with a Object key from the backing store via delete if it exists" do
|
911
|
+
store[Value.new(:objkey1)] = true
|
912
|
+
store.delete(Value.new(:objkey1)).should == true
|
913
|
+
store.key?(Value.new(:objkey1)).should == false
|
914
|
+
end
|
915
|
+
|
916
|
+
it "overwrites existing Boolean values with Object" do
|
917
|
+
store[Value.new(:objkey1)] = true
|
918
|
+
store[Value.new(:objkey1)].should == true
|
919
|
+
store[Value.new(:objkey1)] = false
|
920
|
+
store[Value.new(:objkey1)].should == false
|
921
|
+
end
|
922
|
+
|
923
|
+
it "does not run the block if the Object key is available" do
|
924
|
+
store[Value.new(:objkey1)] = true
|
925
|
+
unaltered = "unaltered"
|
926
|
+
store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
|
927
|
+
unaltered.should == "unaltered"
|
928
|
+
end
|
929
|
+
|
930
|
+
it "fetches a Object key with a default value with fetch, if the key is available" do
|
931
|
+
store[Value.new(:objkey1)] = true
|
932
|
+
store.fetch(Value.new(:objkey1), false).should == true
|
933
|
+
end
|
934
|
+
end
|
935
|
+
|
936
|
+
#################### expires_objectkey_booleanvalue ####################
|
937
|
+
|
938
|
+
shared_examples_for 'expires_objectkey_booleanvalue' do
|
939
|
+
it 'should support expires on store and #[]' do
|
940
|
+
store.store(Value.new(:objkey1), true, :expires => 2)
|
941
|
+
store[Value.new(:objkey1)].should == true
|
942
|
+
sleep 1
|
943
|
+
store[Value.new(:objkey1)].should == true
|
944
|
+
sleep 2
|
945
|
+
store[Value.new(:objkey1)].should == nil
|
946
|
+
end
|
947
|
+
|
948
|
+
it 'should support expires on store and load' do
|
949
|
+
store.store(Value.new(:objkey1), true, :expires => 2)
|
950
|
+
store.load(Value.new(:objkey1)).should == true
|
951
|
+
sleep 1
|
952
|
+
store.load(Value.new(:objkey1)).should == true
|
953
|
+
sleep 2
|
954
|
+
store.load(Value.new(:objkey1)).should == nil
|
955
|
+
end
|
956
|
+
|
957
|
+
it 'should support expires on store and key?' do
|
958
|
+
store.store(Value.new(:objkey1), true, :expires => 2)
|
959
|
+
store.key?(Value.new(:objkey1)).should == true
|
960
|
+
sleep 1
|
961
|
+
store.key?(Value.new(:objkey1)).should == true
|
962
|
+
sleep 2
|
963
|
+
store.key?(Value.new(:objkey1)).should == false
|
964
|
+
end
|
965
|
+
|
966
|
+
it 'should support updating the expiration time in load' do
|
967
|
+
store.store(Value.new(:objkey2), false, :expires => 2)
|
968
|
+
store[Value.new(:objkey2)].should == false
|
969
|
+
sleep 1
|
970
|
+
store.load(Value.new(:objkey2), :expires => 3).should == false
|
971
|
+
store[Value.new(:objkey2)].should == false
|
972
|
+
sleep 1
|
973
|
+
store[Value.new(:objkey2)].should == false
|
974
|
+
sleep 3
|
975
|
+
store[Value.new(:objkey2)].should == nil
|
976
|
+
end
|
977
|
+
|
978
|
+
it 'should support updating the expiration time in key?' do
|
979
|
+
store.store(Value.new(:objkey2), false, :expires => 2)
|
980
|
+
store[Value.new(:objkey2)].should == false
|
981
|
+
sleep 1
|
982
|
+
store.key?(Value.new(:objkey2), :expires => 3).should be_true
|
983
|
+
store[Value.new(:objkey2)].should == false
|
984
|
+
sleep 1
|
985
|
+
store[Value.new(:objkey2)].should == false
|
986
|
+
sleep 3
|
987
|
+
store[Value.new(:objkey2)].should == nil
|
988
|
+
end
|
989
|
+
|
990
|
+
it 'should support updating the expiration time in fetch' do
|
991
|
+
store.store(Value.new(:objkey1), true, :expires => 2)
|
992
|
+
store[Value.new(:objkey1)].should == true
|
993
|
+
sleep 1
|
994
|
+
store.fetch(Value.new(:objkey1), nil, :expires => 3).should == true
|
995
|
+
store[Value.new(:objkey1)].should == true
|
996
|
+
sleep 1
|
997
|
+
store[Value.new(:objkey1)].should == true
|
998
|
+
sleep 3
|
999
|
+
store[Value.new(:objkey1)].should == nil
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
it 'should respect expires in delete' do
|
1003
|
+
store.store(Value.new(:objkey2), false, :expires => 2)
|
1004
|
+
store[Value.new(:objkey2)].should == false
|
1005
|
+
sleep 1
|
1006
|
+
store[Value.new(:objkey2)].should == false
|
1007
|
+
sleep 2
|
1008
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
it 'should support the #expires syntactic sugar' do
|
1012
|
+
store['longlive_key'] = 'longlive_value'
|
1013
|
+
store.expires(2).store(Value.new(:objkey2), false)
|
1014
|
+
store[Value.new(:objkey2)].should == false
|
1015
|
+
sleep 1
|
1016
|
+
store[Value.new(:objkey2)].should == false
|
1017
|
+
sleep 2
|
1018
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1019
|
+
store['longlive_key'].should == 'longlive_value'
|
1020
|
+
end
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
#################### null_objectkey_stringvalue ####################
|
1024
|
+
|
1025
|
+
shared_examples_for 'null_objectkey_stringvalue' do
|
1026
|
+
it "reads from keys that are Objects like a Hash" do
|
1027
|
+
store[Value.new(:objkey1)].should == nil
|
1028
|
+
store.load(Value.new(:objkey1)).should == nil
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
it "guarantees that the same String value is returned when setting a Object key" do
|
1032
|
+
value = "strval1"
|
1033
|
+
(store[Value.new(:objkey1)] = value).should equal(value)
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
it "returns false from key? if a Object key is not available" do
|
1037
|
+
store.key?(Value.new(:objkey1)).should == false
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
it "returns nil from delete if an element for a Object key does not exist" do
|
1041
|
+
store.delete(Value.new(:objkey1)).should == nil
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
it "removes all Object keys from the store with clear" do
|
1045
|
+
store[Value.new(:objkey1)] = "strval1"
|
1046
|
+
store[Value.new(:objkey2)] = "strval2"
|
1047
|
+
store.clear.should equal(store)
|
1048
|
+
store.key?(Value.new(:objkey1)).should_not == true
|
1049
|
+
store.key?(Value.new(:objkey2)).should_not == true
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
it "fetches a Object key with a default value with fetch, if the key is not available" do
|
1053
|
+
store.fetch(Value.new(:objkey1), "strval1").should == "strval1"
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
it "fetches a Object key with a block with fetch, if the key is not available" do
|
1057
|
+
key = Value.new(:objkey1)
|
1058
|
+
value = "strval1"
|
1059
|
+
store.fetch(key) do |k|
|
1060
|
+
k.should equal(key)
|
1061
|
+
value
|
1062
|
+
end.should equal(value)
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
it 'should accept options' do
|
1066
|
+
store.key?(Value.new(:objkey1), :option1 => 1).should == false
|
1067
|
+
store.load(Value.new(:objkey1), :option2 => 2).should == nil
|
1068
|
+
store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
|
1069
|
+
store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
|
1070
|
+
store.delete(Value.new(:objkey1), :option4 => 4).should == nil
|
1071
|
+
store.clear(:option5 => 5).should equal(store)
|
1072
|
+
store.store(Value.new(:objkey1), "strval1", :option6 => 6).should == "strval1"
|
1073
|
+
end
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
#################### store_objectkey_stringvalue ####################
|
1077
|
+
|
1078
|
+
shared_examples_for 'store_objectkey_stringvalue' do
|
1079
|
+
it "writes String values to keys that are Objects like a Hash" do
|
1080
|
+
store[Value.new(:objkey1)] = "strval1"
|
1081
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1082
|
+
store.load(Value.new(:objkey1)).should == "strval1"
|
1083
|
+
end
|
1084
|
+
|
1085
|
+
it "returns true from key? if a Object key is available" do
|
1086
|
+
store[Value.new(:objkey1)] = "strval1"
|
1087
|
+
store.key?(Value.new(:objkey1)).should == true
|
1088
|
+
store[Value.new(:objkey2)] = "strval2"
|
1089
|
+
store.key?(Value.new(:objkey2)).should == true
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
it "stores String values with Object keys with #store" do
|
1093
|
+
value = "strval1"
|
1094
|
+
store.store(Value.new(:objkey1), value).should equal(value)
|
1095
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1096
|
+
store.load(Value.new(:objkey1)).should == "strval1"
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
it "stores Object after clear" do
|
1100
|
+
store[Value.new(:objkey1)] = "strval1"
|
1101
|
+
store[Value.new(:objkey2)] = "strval2"
|
1102
|
+
store.clear.should equal(store)
|
1103
|
+
store[Value.new(:objkey1)] = "strval1"
|
1104
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1105
|
+
store[Value.new(:objkey2)].should be_nil
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
it "removes and returns a String element with a Object key from the backing store via delete if it exists" do
|
1109
|
+
store[Value.new(:objkey1)] = "strval1"
|
1110
|
+
store.delete(Value.new(:objkey1)).should == "strval1"
|
1111
|
+
store.key?(Value.new(:objkey1)).should == false
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
it "overwrites existing String values with Object" do
|
1115
|
+
store[Value.new(:objkey1)] = "strval1"
|
1116
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1117
|
+
store[Value.new(:objkey1)] = "strval2"
|
1118
|
+
store[Value.new(:objkey1)].should == "strval2"
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
it "does not run the block if the Object key is available" do
|
1122
|
+
store[Value.new(:objkey1)] = "strval1"
|
1123
|
+
unaltered = "unaltered"
|
1124
|
+
store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
|
1125
|
+
unaltered.should == "unaltered"
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
it "fetches a Object key with a default value with fetch, if the key is available" do
|
1129
|
+
store[Value.new(:objkey1)] = "strval1"
|
1130
|
+
store.fetch(Value.new(:objkey1), "strval2").should == "strval1"
|
1131
|
+
end
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
#################### returndifferent_objectkey_stringvalue ####################
|
1135
|
+
|
1136
|
+
shared_examples_for 'returndifferent_objectkey_stringvalue' do
|
1137
|
+
it "guarantees that a different String value is retrieved from the Object key" do
|
1138
|
+
value = "strval1"
|
1139
|
+
store[Value.new(:objkey1)] = "strval1"
|
1140
|
+
store[Value.new(:objkey1)].should_not be_equal("strval1")
|
1141
|
+
end
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
#################### expires_objectkey_stringvalue ####################
|
1145
|
+
|
1146
|
+
shared_examples_for 'expires_objectkey_stringvalue' do
|
1147
|
+
it 'should support expires on store and #[]' do
|
1148
|
+
store.store(Value.new(:objkey1), "strval1", :expires => 2)
|
1149
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1150
|
+
sleep 1
|
1151
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1152
|
+
sleep 2
|
1153
|
+
store[Value.new(:objkey1)].should == nil
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
it 'should support expires on store and load' do
|
1157
|
+
store.store(Value.new(:objkey1), "strval1", :expires => 2)
|
1158
|
+
store.load(Value.new(:objkey1)).should == "strval1"
|
1159
|
+
sleep 1
|
1160
|
+
store.load(Value.new(:objkey1)).should == "strval1"
|
1161
|
+
sleep 2
|
1162
|
+
store.load(Value.new(:objkey1)).should == nil
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
it 'should support expires on store and key?' do
|
1166
|
+
store.store(Value.new(:objkey1), "strval1", :expires => 2)
|
1167
|
+
store.key?(Value.new(:objkey1)).should == true
|
1168
|
+
sleep 1
|
1169
|
+
store.key?(Value.new(:objkey1)).should == true
|
1170
|
+
sleep 2
|
1171
|
+
store.key?(Value.new(:objkey1)).should == false
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
it 'should support updating the expiration time in load' do
|
1175
|
+
store.store(Value.new(:objkey2), "strval2", :expires => 2)
|
1176
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1177
|
+
sleep 1
|
1178
|
+
store.load(Value.new(:objkey2), :expires => 3).should == "strval2"
|
1179
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1180
|
+
sleep 1
|
1181
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1182
|
+
sleep 3
|
1183
|
+
store[Value.new(:objkey2)].should == nil
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
it 'should support updating the expiration time in key?' do
|
1187
|
+
store.store(Value.new(:objkey2), "strval2", :expires => 2)
|
1188
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1189
|
+
sleep 1
|
1190
|
+
store.key?(Value.new(:objkey2), :expires => 3).should be_true
|
1191
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1192
|
+
sleep 1
|
1193
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1194
|
+
sleep 3
|
1195
|
+
store[Value.new(:objkey2)].should == nil
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
it 'should support updating the expiration time in fetch' do
|
1199
|
+
store.store(Value.new(:objkey1), "strval1", :expires => 2)
|
1200
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1201
|
+
sleep 1
|
1202
|
+
store.fetch(Value.new(:objkey1), nil, :expires => 3).should == "strval1"
|
1203
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1204
|
+
sleep 1
|
1205
|
+
store[Value.new(:objkey1)].should == "strval1"
|
1206
|
+
sleep 3
|
1207
|
+
store[Value.new(:objkey1)].should == nil
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
it 'should respect expires in delete' do
|
1211
|
+
store.store(Value.new(:objkey2), "strval2", :expires => 2)
|
1212
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1213
|
+
sleep 1
|
1214
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1215
|
+
sleep 2
|
1216
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
it 'should support the #expires syntactic sugar' do
|
1220
|
+
store['longlive_key'] = 'longlive_value'
|
1221
|
+
store.expires(2).store(Value.new(:objkey2), "strval2")
|
1222
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1223
|
+
sleep 1
|
1224
|
+
store[Value.new(:objkey2)].should == "strval2"
|
1225
|
+
sleep 2
|
1226
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1227
|
+
store['longlive_key'].should == 'longlive_value'
|
1228
|
+
end
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
#################### null_objectkey_hashvalue ####################
|
1232
|
+
|
1233
|
+
shared_examples_for 'null_objectkey_hashvalue' do
|
1234
|
+
it "reads from keys that are Objects like a Hash" do
|
1235
|
+
store[Value.new(:objkey1)].should == nil
|
1236
|
+
store.load(Value.new(:objkey1)).should == nil
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
it "guarantees that the same Hash value is returned when setting a Object key" do
|
1240
|
+
value = {"hashval1"=>["array1", 1]}
|
1241
|
+
(store[Value.new(:objkey1)] = value).should equal(value)
|
1242
|
+
end
|
1243
|
+
|
1244
|
+
it "returns false from key? if a Object key is not available" do
|
1245
|
+
store.key?(Value.new(:objkey1)).should == false
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
it "returns nil from delete if an element for a Object key does not exist" do
|
1249
|
+
store.delete(Value.new(:objkey1)).should == nil
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
it "removes all Object keys from the store with clear" do
|
1253
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1254
|
+
store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1255
|
+
store.clear.should equal(store)
|
1256
|
+
store.key?(Value.new(:objkey1)).should_not == true
|
1257
|
+
store.key?(Value.new(:objkey2)).should_not == true
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
it "fetches a Object key with a default value with fetch, if the key is not available" do
|
1261
|
+
store.fetch(Value.new(:objkey1), {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
it "fetches a Object key with a block with fetch, if the key is not available" do
|
1265
|
+
key = Value.new(:objkey1)
|
1266
|
+
value = {"hashval1"=>["array1", 1]}
|
1267
|
+
store.fetch(key) do |k|
|
1268
|
+
k.should equal(key)
|
1269
|
+
value
|
1270
|
+
end.should equal(value)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
it 'should accept options' do
|
1274
|
+
store.key?(Value.new(:objkey1), :option1 => 1).should == false
|
1275
|
+
store.load(Value.new(:objkey1), :option2 => 2).should == nil
|
1276
|
+
store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
|
1277
|
+
store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
|
1278
|
+
store.delete(Value.new(:objkey1), :option4 => 4).should == nil
|
1279
|
+
store.clear(:option5 => 5).should equal(store)
|
1280
|
+
store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
|
1281
|
+
end
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
#################### store_objectkey_hashvalue ####################
|
1285
|
+
|
1286
|
+
shared_examples_for 'store_objectkey_hashvalue' do
|
1287
|
+
it "writes Hash values to keys that are Objects like a Hash" do
|
1288
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1289
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1290
|
+
store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
it "returns true from key? if a Object key is available" do
|
1294
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1295
|
+
store.key?(Value.new(:objkey1)).should == true
|
1296
|
+
store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1297
|
+
store.key?(Value.new(:objkey2)).should == true
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
it "stores Hash values with Object keys with #store" do
|
1301
|
+
value = {"hashval1"=>["array1", 1]}
|
1302
|
+
store.store(Value.new(:objkey1), value).should equal(value)
|
1303
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1304
|
+
store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
|
1305
|
+
end
|
1306
|
+
|
1307
|
+
it "stores Object after clear" do
|
1308
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1309
|
+
store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1310
|
+
store.clear.should equal(store)
|
1311
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1312
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1313
|
+
store[Value.new(:objkey2)].should be_nil
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
it "removes and returns a Hash element with a Object key from the backing store via delete if it exists" do
|
1317
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1318
|
+
store.delete(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
|
1319
|
+
store.key?(Value.new(:objkey1)).should == false
|
1320
|
+
end
|
1321
|
+
|
1322
|
+
it "overwrites existing Hash values with Object" do
|
1323
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1324
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1325
|
+
store[Value.new(:objkey1)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1326
|
+
store[Value.new(:objkey1)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
it "does not run the block if the Object key is available" do
|
1330
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1331
|
+
unaltered = "unaltered"
|
1332
|
+
store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
|
1333
|
+
unaltered.should == "unaltered"
|
1334
|
+
end
|
1335
|
+
|
1336
|
+
it "fetches a Object key with a default value with fetch, if the key is available" do
|
1337
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1338
|
+
store.fetch(Value.new(:objkey1), {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
|
1339
|
+
end
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
#################### returndifferent_objectkey_hashvalue ####################
|
1343
|
+
|
1344
|
+
shared_examples_for 'returndifferent_objectkey_hashvalue' do
|
1345
|
+
it "guarantees that a different Hash value is retrieved from the Object key" do
|
1346
|
+
value = {"hashval1"=>["array1", 1]}
|
1347
|
+
store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
|
1348
|
+
store[Value.new(:objkey1)].should_not be_equal({"hashval1"=>["array1", 1]})
|
1349
|
+
end
|
1350
|
+
end
|
1351
|
+
|
1352
|
+
#################### expires_objectkey_hashvalue ####################
|
1353
|
+
|
1354
|
+
shared_examples_for 'expires_objectkey_hashvalue' do
|
1355
|
+
it 'should support expires on store and #[]' do
|
1356
|
+
store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
|
1357
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1358
|
+
sleep 1
|
1359
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1360
|
+
sleep 2
|
1361
|
+
store[Value.new(:objkey1)].should == nil
|
1362
|
+
end
|
1363
|
+
|
1364
|
+
it 'should support expires on store and load' do
|
1365
|
+
store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
|
1366
|
+
store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
|
1367
|
+
sleep 1
|
1368
|
+
store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
|
1369
|
+
sleep 2
|
1370
|
+
store.load(Value.new(:objkey1)).should == nil
|
1371
|
+
end
|
1372
|
+
|
1373
|
+
it 'should support expires on store and key?' do
|
1374
|
+
store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
|
1375
|
+
store.key?(Value.new(:objkey1)).should == true
|
1376
|
+
sleep 1
|
1377
|
+
store.key?(Value.new(:objkey1)).should == true
|
1378
|
+
sleep 2
|
1379
|
+
store.key?(Value.new(:objkey1)).should == false
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
it 'should support updating the expiration time in load' do
|
1383
|
+
store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
1384
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1385
|
+
sleep 1
|
1386
|
+
store.load(Value.new(:objkey2), :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1387
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1388
|
+
sleep 1
|
1389
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1390
|
+
sleep 3
|
1391
|
+
store[Value.new(:objkey2)].should == nil
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
it 'should support updating the expiration time in key?' do
|
1395
|
+
store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
1396
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1397
|
+
sleep 1
|
1398
|
+
store.key?(Value.new(:objkey2), :expires => 3).should be_true
|
1399
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1400
|
+
sleep 1
|
1401
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1402
|
+
sleep 3
|
1403
|
+
store[Value.new(:objkey2)].should == nil
|
1404
|
+
end
|
1405
|
+
|
1406
|
+
it 'should support updating the expiration time in fetch' do
|
1407
|
+
store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
|
1408
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1409
|
+
sleep 1
|
1410
|
+
store.fetch(Value.new(:objkey1), nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
|
1411
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1412
|
+
sleep 1
|
1413
|
+
store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
|
1414
|
+
sleep 3
|
1415
|
+
store[Value.new(:objkey1)].should == nil
|
1416
|
+
end
|
1417
|
+
|
1418
|
+
it 'should respect expires in delete' do
|
1419
|
+
store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
1420
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1421
|
+
sleep 1
|
1422
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1423
|
+
sleep 2
|
1424
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
it 'should support the #expires syntactic sugar' do
|
1428
|
+
store['longlive_key'] = 'longlive_value'
|
1429
|
+
store.expires(2).store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]})
|
1430
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1431
|
+
sleep 1
|
1432
|
+
store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
1433
|
+
sleep 2
|
1434
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1435
|
+
store['longlive_key'].should == 'longlive_value'
|
1436
|
+
end
|
1437
|
+
end
|
1438
|
+
|
1439
|
+
#################### null_objectkey_objectvalue ####################
|
1440
|
+
|
1441
|
+
shared_examples_for 'null_objectkey_objectvalue' do
|
1442
|
+
it "reads from keys that are Objects like a Hash" do
|
1443
|
+
store[Value.new(:objkey1)].should == nil
|
1444
|
+
store.load(Value.new(:objkey1)).should == nil
|
1445
|
+
end
|
1446
|
+
|
1447
|
+
it "guarantees that the same Object value is returned when setting a Object key" do
|
1448
|
+
value = Value.new(:objval1)
|
1449
|
+
(store[Value.new(:objkey1)] = value).should equal(value)
|
1450
|
+
end
|
1451
|
+
|
1452
|
+
it "returns false from key? if a Object key is not available" do
|
1453
|
+
store.key?(Value.new(:objkey1)).should == false
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
it "returns nil from delete if an element for a Object key does not exist" do
|
1457
|
+
store.delete(Value.new(:objkey1)).should == nil
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
it "removes all Object keys from the store with clear" do
|
1461
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1462
|
+
store[Value.new(:objkey2)] = Value.new(:objval2)
|
1463
|
+
store.clear.should equal(store)
|
1464
|
+
store.key?(Value.new(:objkey1)).should_not == true
|
1465
|
+
store.key?(Value.new(:objkey2)).should_not == true
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
it "fetches a Object key with a default value with fetch, if the key is not available" do
|
1469
|
+
store.fetch(Value.new(:objkey1), Value.new(:objval1)).should == Value.new(:objval1)
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
it "fetches a Object key with a block with fetch, if the key is not available" do
|
1473
|
+
key = Value.new(:objkey1)
|
1474
|
+
value = Value.new(:objval1)
|
1475
|
+
store.fetch(key) do |k|
|
1476
|
+
k.should equal(key)
|
1477
|
+
value
|
1478
|
+
end.should equal(value)
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
it 'should accept options' do
|
1482
|
+
store.key?(Value.new(:objkey1), :option1 => 1).should == false
|
1483
|
+
store.load(Value.new(:objkey1), :option2 => 2).should == nil
|
1484
|
+
store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
|
1485
|
+
store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
|
1486
|
+
store.delete(Value.new(:objkey1), :option4 => 4).should == nil
|
1487
|
+
store.clear(:option5 => 5).should equal(store)
|
1488
|
+
store.store(Value.new(:objkey1), Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
|
1489
|
+
end
|
1490
|
+
end
|
1491
|
+
|
1492
|
+
#################### store_objectkey_objectvalue ####################
|
1493
|
+
|
1494
|
+
shared_examples_for 'store_objectkey_objectvalue' do
|
1495
|
+
it "writes Object values to keys that are Objects like a Hash" do
|
1496
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1497
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1498
|
+
store.load(Value.new(:objkey1)).should == Value.new(:objval1)
|
1499
|
+
end
|
1500
|
+
|
1501
|
+
it "returns true from key? if a Object key is available" do
|
1502
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1503
|
+
store.key?(Value.new(:objkey1)).should == true
|
1504
|
+
store[Value.new(:objkey2)] = Value.new(:objval2)
|
1505
|
+
store.key?(Value.new(:objkey2)).should == true
|
1506
|
+
end
|
1507
|
+
|
1508
|
+
it "stores Object values with Object keys with #store" do
|
1509
|
+
value = Value.new(:objval1)
|
1510
|
+
store.store(Value.new(:objkey1), value).should equal(value)
|
1511
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1512
|
+
store.load(Value.new(:objkey1)).should == Value.new(:objval1)
|
1513
|
+
end
|
1514
|
+
|
1515
|
+
it "stores Object after clear" do
|
1516
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1517
|
+
store[Value.new(:objkey2)] = Value.new(:objval2)
|
1518
|
+
store.clear.should equal(store)
|
1519
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1520
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1521
|
+
store[Value.new(:objkey2)].should be_nil
|
1522
|
+
end
|
1523
|
+
|
1524
|
+
it "removes and returns a Object element with a Object key from the backing store via delete if it exists" do
|
1525
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1526
|
+
store.delete(Value.new(:objkey1)).should == Value.new(:objval1)
|
1527
|
+
store.key?(Value.new(:objkey1)).should == false
|
1528
|
+
end
|
1529
|
+
|
1530
|
+
it "overwrites existing Object values with Object" do
|
1531
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1532
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1533
|
+
store[Value.new(:objkey1)] = Value.new(:objval2)
|
1534
|
+
store[Value.new(:objkey1)].should == Value.new(:objval2)
|
1535
|
+
end
|
1536
|
+
|
1537
|
+
it "does not run the block if the Object key is available" do
|
1538
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1539
|
+
unaltered = "unaltered"
|
1540
|
+
store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
|
1541
|
+
unaltered.should == "unaltered"
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
it "fetches a Object key with a default value with fetch, if the key is available" do
|
1545
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1546
|
+
store.fetch(Value.new(:objkey1), Value.new(:objval2)).should == Value.new(:objval1)
|
1547
|
+
end
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
#################### returndifferent_objectkey_objectvalue ####################
|
1551
|
+
|
1552
|
+
shared_examples_for 'returndifferent_objectkey_objectvalue' do
|
1553
|
+
it "guarantees that a different Object value is retrieved from the Object key" do
|
1554
|
+
value = Value.new(:objval1)
|
1555
|
+
store[Value.new(:objkey1)] = Value.new(:objval1)
|
1556
|
+
store[Value.new(:objkey1)].should_not be_equal(Value.new(:objval1))
|
1557
|
+
end
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
#################### expires_objectkey_objectvalue ####################
|
1561
|
+
|
1562
|
+
shared_examples_for 'expires_objectkey_objectvalue' do
|
1563
|
+
it 'should support expires on store and #[]' do
|
1564
|
+
store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
|
1565
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1566
|
+
sleep 1
|
1567
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1568
|
+
sleep 2
|
1569
|
+
store[Value.new(:objkey1)].should == nil
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
it 'should support expires on store and load' do
|
1573
|
+
store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
|
1574
|
+
store.load(Value.new(:objkey1)).should == Value.new(:objval1)
|
1575
|
+
sleep 1
|
1576
|
+
store.load(Value.new(:objkey1)).should == Value.new(:objval1)
|
1577
|
+
sleep 2
|
1578
|
+
store.load(Value.new(:objkey1)).should == nil
|
1579
|
+
end
|
1580
|
+
|
1581
|
+
it 'should support expires on store and key?' do
|
1582
|
+
store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
|
1583
|
+
store.key?(Value.new(:objkey1)).should == true
|
1584
|
+
sleep 1
|
1585
|
+
store.key?(Value.new(:objkey1)).should == true
|
1586
|
+
sleep 2
|
1587
|
+
store.key?(Value.new(:objkey1)).should == false
|
1588
|
+
end
|
1589
|
+
|
1590
|
+
it 'should support updating the expiration time in load' do
|
1591
|
+
store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
|
1592
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1593
|
+
sleep 1
|
1594
|
+
store.load(Value.new(:objkey2), :expires => 3).should == Value.new(:objval2)
|
1595
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1596
|
+
sleep 1
|
1597
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1598
|
+
sleep 3
|
1599
|
+
store[Value.new(:objkey2)].should == nil
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
it 'should support updating the expiration time in key?' do
|
1603
|
+
store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
|
1604
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1605
|
+
sleep 1
|
1606
|
+
store.key?(Value.new(:objkey2), :expires => 3).should be_true
|
1607
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1608
|
+
sleep 1
|
1609
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1610
|
+
sleep 3
|
1611
|
+
store[Value.new(:objkey2)].should == nil
|
1612
|
+
end
|
1613
|
+
|
1614
|
+
it 'should support updating the expiration time in fetch' do
|
1615
|
+
store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
|
1616
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1617
|
+
sleep 1
|
1618
|
+
store.fetch(Value.new(:objkey1), nil, :expires => 3).should == Value.new(:objval1)
|
1619
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1620
|
+
sleep 1
|
1621
|
+
store[Value.new(:objkey1)].should == Value.new(:objval1)
|
1622
|
+
sleep 3
|
1623
|
+
store[Value.new(:objkey1)].should == nil
|
1624
|
+
end
|
1625
|
+
|
1626
|
+
it 'should respect expires in delete' do
|
1627
|
+
store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
|
1628
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1629
|
+
sleep 1
|
1630
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1631
|
+
sleep 2
|
1632
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1633
|
+
end
|
1634
|
+
|
1635
|
+
it 'should support the #expires syntactic sugar' do
|
1636
|
+
store['longlive_key'] = 'longlive_value'
|
1637
|
+
store.expires(2).store(Value.new(:objkey2), Value.new(:objval2))
|
1638
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1639
|
+
sleep 1
|
1640
|
+
store[Value.new(:objkey2)].should == Value.new(:objval2)
|
1641
|
+
sleep 2
|
1642
|
+
store.delete(Value.new(:objkey2)).should == nil
|
1643
|
+
store['longlive_key'].should == 'longlive_value'
|
1644
|
+
end
|
1645
|
+
end
|
1646
|
+
|
1647
|
+
#################### null_hashkey_booleanvalue ####################
|
1648
|
+
|
1649
|
+
shared_examples_for 'null_hashkey_booleanvalue' do
|
1650
|
+
it "reads from keys that are Hashs like a Hash" do
|
1651
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
1652
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
1653
|
+
end
|
1654
|
+
|
1655
|
+
it "guarantees that the same Boolean value is returned when setting a Hash key" do
|
1656
|
+
value = true
|
1657
|
+
(store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
|
1658
|
+
end
|
1659
|
+
|
1660
|
+
it "returns false from key? if a Hash key is not available" do
|
1661
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1662
|
+
end
|
1663
|
+
|
1664
|
+
it "returns nil from delete if an element for a Hash key does not exist" do
|
1665
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == nil
|
1666
|
+
end
|
1667
|
+
|
1668
|
+
it "removes all Hash keys from the store with clear" do
|
1669
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1670
|
+
store[{"hashkey3"=>"hashkey4"}] = false
|
1671
|
+
store.clear.should equal(store)
|
1672
|
+
store.key?({"hashkey1"=>"hashkey2"}).should_not == true
|
1673
|
+
store.key?({"hashkey3"=>"hashkey4"}).should_not == true
|
1674
|
+
end
|
1675
|
+
|
1676
|
+
it "fetches a Hash key with a default value with fetch, if the key is not available" do
|
1677
|
+
store.fetch({"hashkey1"=>"hashkey2"}, true).should == true
|
1678
|
+
end
|
1679
|
+
|
1680
|
+
it "fetches a Hash key with a block with fetch, if the key is not available" do
|
1681
|
+
key = {"hashkey1"=>"hashkey2"}
|
1682
|
+
value = true
|
1683
|
+
store.fetch(key) do |k|
|
1684
|
+
k.should equal(key)
|
1685
|
+
value
|
1686
|
+
end.should equal(value)
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
it 'should accept options' do
|
1690
|
+
store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
|
1691
|
+
store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
|
1692
|
+
store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
|
1693
|
+
store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
|
1694
|
+
store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
|
1695
|
+
store.clear(:option5 => 5).should equal(store)
|
1696
|
+
store.store({"hashkey1"=>"hashkey2"}, true, :option6 => 6).should == true
|
1697
|
+
end
|
1698
|
+
end
|
1699
|
+
|
1700
|
+
#################### store_hashkey_booleanvalue ####################
|
1701
|
+
|
1702
|
+
shared_examples_for 'store_hashkey_booleanvalue' do
|
1703
|
+
it "writes Boolean values to keys that are Hashs like a Hash" do
|
1704
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1705
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1706
|
+
store.load({"hashkey1"=>"hashkey2"}).should == true
|
1707
|
+
end
|
1708
|
+
|
1709
|
+
it "returns true from key? if a Hash key is available" do
|
1710
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1711
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1712
|
+
store[{"hashkey3"=>"hashkey4"}] = false
|
1713
|
+
store.key?({"hashkey3"=>"hashkey4"}).should == true
|
1714
|
+
end
|
1715
|
+
|
1716
|
+
it "stores Boolean values with Hash keys with #store" do
|
1717
|
+
value = true
|
1718
|
+
store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
|
1719
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1720
|
+
store.load({"hashkey1"=>"hashkey2"}).should == true
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
it "stores Hash after clear" do
|
1724
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1725
|
+
store[{"hashkey3"=>"hashkey4"}] = false
|
1726
|
+
store.clear.should equal(store)
|
1727
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1728
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1729
|
+
store[{"hashkey3"=>"hashkey4"}].should be_nil
|
1730
|
+
end
|
1731
|
+
|
1732
|
+
it "removes and returns a Boolean element with a Hash key from the backing store via delete if it exists" do
|
1733
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1734
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == true
|
1735
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
it "overwrites existing Boolean values with Hash" do
|
1739
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1740
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1741
|
+
store[{"hashkey1"=>"hashkey2"}] = false
|
1742
|
+
store[{"hashkey1"=>"hashkey2"}].should == false
|
1743
|
+
end
|
1744
|
+
|
1745
|
+
it "does not run the block if the Hash key is available" do
|
1746
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1747
|
+
unaltered = "unaltered"
|
1748
|
+
store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
|
1749
|
+
unaltered.should == "unaltered"
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
it "fetches a Hash key with a default value with fetch, if the key is available" do
|
1753
|
+
store[{"hashkey1"=>"hashkey2"}] = true
|
1754
|
+
store.fetch({"hashkey1"=>"hashkey2"}, false).should == true
|
1755
|
+
end
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
#################### expires_hashkey_booleanvalue ####################
|
1759
|
+
|
1760
|
+
shared_examples_for 'expires_hashkey_booleanvalue' do
|
1761
|
+
it 'should support expires on store and #[]' do
|
1762
|
+
store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
|
1763
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1764
|
+
sleep 1
|
1765
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1766
|
+
sleep 2
|
1767
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
1768
|
+
end
|
1769
|
+
|
1770
|
+
it 'should support expires on store and load' do
|
1771
|
+
store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
|
1772
|
+
store.load({"hashkey1"=>"hashkey2"}).should == true
|
1773
|
+
sleep 1
|
1774
|
+
store.load({"hashkey1"=>"hashkey2"}).should == true
|
1775
|
+
sleep 2
|
1776
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
1777
|
+
end
|
1778
|
+
|
1779
|
+
it 'should support expires on store and key?' do
|
1780
|
+
store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
|
1781
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1782
|
+
sleep 1
|
1783
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1784
|
+
sleep 2
|
1785
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
it 'should support updating the expiration time in load' do
|
1789
|
+
store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
|
1790
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1791
|
+
sleep 1
|
1792
|
+
store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == false
|
1793
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1794
|
+
sleep 1
|
1795
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1796
|
+
sleep 3
|
1797
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
1798
|
+
end
|
1799
|
+
|
1800
|
+
it 'should support updating the expiration time in key?' do
|
1801
|
+
store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
|
1802
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1803
|
+
sleep 1
|
1804
|
+
store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
|
1805
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1806
|
+
sleep 1
|
1807
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1808
|
+
sleep 3
|
1809
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
1810
|
+
end
|
1811
|
+
|
1812
|
+
it 'should support updating the expiration time in fetch' do
|
1813
|
+
store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
|
1814
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1815
|
+
sleep 1
|
1816
|
+
store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == true
|
1817
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1818
|
+
sleep 1
|
1819
|
+
store[{"hashkey1"=>"hashkey2"}].should == true
|
1820
|
+
sleep 3
|
1821
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
it 'should respect expires in delete' do
|
1825
|
+
store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
|
1826
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1827
|
+
sleep 1
|
1828
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1829
|
+
sleep 2
|
1830
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
1831
|
+
end
|
1832
|
+
|
1833
|
+
it 'should support the #expires syntactic sugar' do
|
1834
|
+
store['longlive_key'] = 'longlive_value'
|
1835
|
+
store.expires(2).store({"hashkey3"=>"hashkey4"}, false)
|
1836
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1837
|
+
sleep 1
|
1838
|
+
store[{"hashkey3"=>"hashkey4"}].should == false
|
1839
|
+
sleep 2
|
1840
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
1841
|
+
store['longlive_key'].should == 'longlive_value'
|
1842
|
+
end
|
1843
|
+
end
|
1844
|
+
|
1845
|
+
#################### null_hashkey_stringvalue ####################
|
1846
|
+
|
1847
|
+
shared_examples_for 'null_hashkey_stringvalue' do
|
1848
|
+
it "reads from keys that are Hashs like a Hash" do
|
1849
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
1850
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
1851
|
+
end
|
1852
|
+
|
1853
|
+
it "guarantees that the same String value is returned when setting a Hash key" do
|
1854
|
+
value = "strval1"
|
1855
|
+
(store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
|
1856
|
+
end
|
1857
|
+
|
1858
|
+
it "returns false from key? if a Hash key is not available" do
|
1859
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1860
|
+
end
|
1861
|
+
|
1862
|
+
it "returns nil from delete if an element for a Hash key does not exist" do
|
1863
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == nil
|
1864
|
+
end
|
1865
|
+
|
1866
|
+
it "removes all Hash keys from the store with clear" do
|
1867
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1868
|
+
store[{"hashkey3"=>"hashkey4"}] = "strval2"
|
1869
|
+
store.clear.should equal(store)
|
1870
|
+
store.key?({"hashkey1"=>"hashkey2"}).should_not == true
|
1871
|
+
store.key?({"hashkey3"=>"hashkey4"}).should_not == true
|
1872
|
+
end
|
1873
|
+
|
1874
|
+
it "fetches a Hash key with a default value with fetch, if the key is not available" do
|
1875
|
+
store.fetch({"hashkey1"=>"hashkey2"}, "strval1").should == "strval1"
|
1876
|
+
end
|
1877
|
+
|
1878
|
+
it "fetches a Hash key with a block with fetch, if the key is not available" do
|
1879
|
+
key = {"hashkey1"=>"hashkey2"}
|
1880
|
+
value = "strval1"
|
1881
|
+
store.fetch(key) do |k|
|
1882
|
+
k.should equal(key)
|
1883
|
+
value
|
1884
|
+
end.should equal(value)
|
1885
|
+
end
|
1886
|
+
|
1887
|
+
it 'should accept options' do
|
1888
|
+
store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
|
1889
|
+
store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
|
1890
|
+
store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
|
1891
|
+
store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
|
1892
|
+
store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
|
1893
|
+
store.clear(:option5 => 5).should equal(store)
|
1894
|
+
store.store({"hashkey1"=>"hashkey2"}, "strval1", :option6 => 6).should == "strval1"
|
1895
|
+
end
|
1896
|
+
end
|
1897
|
+
|
1898
|
+
#################### store_hashkey_stringvalue ####################
|
1899
|
+
|
1900
|
+
shared_examples_for 'store_hashkey_stringvalue' do
|
1901
|
+
it "writes String values to keys that are Hashs like a Hash" do
|
1902
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1903
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1904
|
+
store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
|
1905
|
+
end
|
1906
|
+
|
1907
|
+
it "returns true from key? if a Hash key is available" do
|
1908
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1909
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1910
|
+
store[{"hashkey3"=>"hashkey4"}] = "strval2"
|
1911
|
+
store.key?({"hashkey3"=>"hashkey4"}).should == true
|
1912
|
+
end
|
1913
|
+
|
1914
|
+
it "stores String values with Hash keys with #store" do
|
1915
|
+
value = "strval1"
|
1916
|
+
store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
|
1917
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1918
|
+
store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
|
1919
|
+
end
|
1920
|
+
|
1921
|
+
it "stores Hash after clear" do
|
1922
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1923
|
+
store[{"hashkey3"=>"hashkey4"}] = "strval2"
|
1924
|
+
store.clear.should equal(store)
|
1925
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1926
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1927
|
+
store[{"hashkey3"=>"hashkey4"}].should be_nil
|
1928
|
+
end
|
1929
|
+
|
1930
|
+
it "removes and returns a String element with a Hash key from the backing store via delete if it exists" do
|
1931
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1932
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == "strval1"
|
1933
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1934
|
+
end
|
1935
|
+
|
1936
|
+
it "overwrites existing String values with Hash" do
|
1937
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1938
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1939
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval2"
|
1940
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval2"
|
1941
|
+
end
|
1942
|
+
|
1943
|
+
it "does not run the block if the Hash key is available" do
|
1944
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1945
|
+
unaltered = "unaltered"
|
1946
|
+
store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
|
1947
|
+
unaltered.should == "unaltered"
|
1948
|
+
end
|
1949
|
+
|
1950
|
+
it "fetches a Hash key with a default value with fetch, if the key is available" do
|
1951
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1952
|
+
store.fetch({"hashkey1"=>"hashkey2"}, "strval2").should == "strval1"
|
1953
|
+
end
|
1954
|
+
end
|
1955
|
+
|
1956
|
+
#################### returndifferent_hashkey_stringvalue ####################
|
1957
|
+
|
1958
|
+
shared_examples_for 'returndifferent_hashkey_stringvalue' do
|
1959
|
+
it "guarantees that a different String value is retrieved from the Hash key" do
|
1960
|
+
value = "strval1"
|
1961
|
+
store[{"hashkey1"=>"hashkey2"}] = "strval1"
|
1962
|
+
store[{"hashkey1"=>"hashkey2"}].should_not be_equal("strval1")
|
1963
|
+
end
|
1964
|
+
end
|
1965
|
+
|
1966
|
+
#################### expires_hashkey_stringvalue ####################
|
1967
|
+
|
1968
|
+
shared_examples_for 'expires_hashkey_stringvalue' do
|
1969
|
+
it 'should support expires on store and #[]' do
|
1970
|
+
store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
|
1971
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1972
|
+
sleep 1
|
1973
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
1974
|
+
sleep 2
|
1975
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
1976
|
+
end
|
1977
|
+
|
1978
|
+
it 'should support expires on store and load' do
|
1979
|
+
store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
|
1980
|
+
store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
|
1981
|
+
sleep 1
|
1982
|
+
store.load({"hashkey1"=>"hashkey2"}).should == "strval1"
|
1983
|
+
sleep 2
|
1984
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
1985
|
+
end
|
1986
|
+
|
1987
|
+
it 'should support expires on store and key?' do
|
1988
|
+
store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
|
1989
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1990
|
+
sleep 1
|
1991
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
1992
|
+
sleep 2
|
1993
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
1994
|
+
end
|
1995
|
+
|
1996
|
+
it 'should support updating the expiration time in load' do
|
1997
|
+
store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
|
1998
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
1999
|
+
sleep 1
|
2000
|
+
store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == "strval2"
|
2001
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2002
|
+
sleep 1
|
2003
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2004
|
+
sleep 3
|
2005
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2006
|
+
end
|
2007
|
+
|
2008
|
+
it 'should support updating the expiration time in key?' do
|
2009
|
+
store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
|
2010
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2011
|
+
sleep 1
|
2012
|
+
store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
|
2013
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2014
|
+
sleep 1
|
2015
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2016
|
+
sleep 3
|
2017
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2018
|
+
end
|
2019
|
+
|
2020
|
+
it 'should support updating the expiration time in fetch' do
|
2021
|
+
store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
|
2022
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
2023
|
+
sleep 1
|
2024
|
+
store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == "strval1"
|
2025
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
2026
|
+
sleep 1
|
2027
|
+
store[{"hashkey1"=>"hashkey2"}].should == "strval1"
|
2028
|
+
sleep 3
|
2029
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2030
|
+
end
|
2031
|
+
|
2032
|
+
it 'should respect expires in delete' do
|
2033
|
+
store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
|
2034
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2035
|
+
sleep 1
|
2036
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2037
|
+
sleep 2
|
2038
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2039
|
+
end
|
2040
|
+
|
2041
|
+
it 'should support the #expires syntactic sugar' do
|
2042
|
+
store['longlive_key'] = 'longlive_value'
|
2043
|
+
store.expires(2).store({"hashkey3"=>"hashkey4"}, "strval2")
|
2044
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2045
|
+
sleep 1
|
2046
|
+
store[{"hashkey3"=>"hashkey4"}].should == "strval2"
|
2047
|
+
sleep 2
|
2048
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2049
|
+
store['longlive_key'].should == 'longlive_value'
|
2050
|
+
end
|
2051
|
+
end
|
2052
|
+
|
2053
|
+
#################### null_hashkey_hashvalue ####################
|
2054
|
+
|
2055
|
+
shared_examples_for 'null_hashkey_hashvalue' do
|
2056
|
+
it "reads from keys that are Hashs like a Hash" do
|
2057
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2058
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
2059
|
+
end
|
2060
|
+
|
2061
|
+
it "guarantees that the same Hash value is returned when setting a Hash key" do
|
2062
|
+
value = {"hashval1"=>["array1", 1]}
|
2063
|
+
(store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
|
2064
|
+
end
|
2065
|
+
|
2066
|
+
it "returns false from key? if a Hash key is not available" do
|
2067
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2068
|
+
end
|
2069
|
+
|
2070
|
+
it "returns nil from delete if an element for a Hash key does not exist" do
|
2071
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == nil
|
2072
|
+
end
|
2073
|
+
|
2074
|
+
it "removes all Hash keys from the store with clear" do
|
2075
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2076
|
+
store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2077
|
+
store.clear.should equal(store)
|
2078
|
+
store.key?({"hashkey1"=>"hashkey2"}).should_not == true
|
2079
|
+
store.key?({"hashkey3"=>"hashkey4"}).should_not == true
|
2080
|
+
end
|
2081
|
+
|
2082
|
+
it "fetches a Hash key with a default value with fetch, if the key is not available" do
|
2083
|
+
store.fetch({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
|
2084
|
+
end
|
2085
|
+
|
2086
|
+
it "fetches a Hash key with a block with fetch, if the key is not available" do
|
2087
|
+
key = {"hashkey1"=>"hashkey2"}
|
2088
|
+
value = {"hashval1"=>["array1", 1]}
|
2089
|
+
store.fetch(key) do |k|
|
2090
|
+
k.should equal(key)
|
2091
|
+
value
|
2092
|
+
end.should equal(value)
|
2093
|
+
end
|
2094
|
+
|
2095
|
+
it 'should accept options' do
|
2096
|
+
store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
|
2097
|
+
store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
|
2098
|
+
store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
|
2099
|
+
store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
|
2100
|
+
store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
|
2101
|
+
store.clear(:option5 => 5).should equal(store)
|
2102
|
+
store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
|
2103
|
+
end
|
2104
|
+
end
|
2105
|
+
|
2106
|
+
#################### store_hashkey_hashvalue ####################
|
2107
|
+
|
2108
|
+
shared_examples_for 'store_hashkey_hashvalue' do
|
2109
|
+
it "writes Hash values to keys that are Hashs like a Hash" do
|
2110
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2111
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2112
|
+
store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
|
2113
|
+
end
|
2114
|
+
|
2115
|
+
it "returns true from key? if a Hash key is available" do
|
2116
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2117
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2118
|
+
store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2119
|
+
store.key?({"hashkey3"=>"hashkey4"}).should == true
|
2120
|
+
end
|
2121
|
+
|
2122
|
+
it "stores Hash values with Hash keys with #store" do
|
2123
|
+
value = {"hashval1"=>["array1", 1]}
|
2124
|
+
store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
|
2125
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2126
|
+
store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
|
2127
|
+
end
|
2128
|
+
|
2129
|
+
it "stores Hash after clear" do
|
2130
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2131
|
+
store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2132
|
+
store.clear.should equal(store)
|
2133
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2134
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2135
|
+
store[{"hashkey3"=>"hashkey4"}].should be_nil
|
2136
|
+
end
|
2137
|
+
|
2138
|
+
it "removes and returns a Hash element with a Hash key from the backing store via delete if it exists" do
|
2139
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2140
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
|
2141
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2142
|
+
end
|
2143
|
+
|
2144
|
+
it "overwrites existing Hash values with Hash" do
|
2145
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2146
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2147
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2148
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2149
|
+
end
|
2150
|
+
|
2151
|
+
it "does not run the block if the Hash key is available" do
|
2152
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2153
|
+
unaltered = "unaltered"
|
2154
|
+
store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
|
2155
|
+
unaltered.should == "unaltered"
|
2156
|
+
end
|
2157
|
+
|
2158
|
+
it "fetches a Hash key with a default value with fetch, if the key is available" do
|
2159
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2160
|
+
store.fetch({"hashkey1"=>"hashkey2"}, {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
|
2161
|
+
end
|
2162
|
+
end
|
2163
|
+
|
2164
|
+
#################### returndifferent_hashkey_hashvalue ####################
|
2165
|
+
|
2166
|
+
shared_examples_for 'returndifferent_hashkey_hashvalue' do
|
2167
|
+
it "guarantees that a different Hash value is retrieved from the Hash key" do
|
2168
|
+
value = {"hashval1"=>["array1", 1]}
|
2169
|
+
store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
|
2170
|
+
store[{"hashkey1"=>"hashkey2"}].should_not be_equal({"hashval1"=>["array1", 1]})
|
2171
|
+
end
|
2172
|
+
end
|
2173
|
+
|
2174
|
+
#################### expires_hashkey_hashvalue ####################
|
2175
|
+
|
2176
|
+
shared_examples_for 'expires_hashkey_hashvalue' do
|
2177
|
+
it 'should support expires on store and #[]' do
|
2178
|
+
store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
|
2179
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2180
|
+
sleep 1
|
2181
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2182
|
+
sleep 2
|
2183
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2184
|
+
end
|
2185
|
+
|
2186
|
+
it 'should support expires on store and load' do
|
2187
|
+
store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
|
2188
|
+
store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
|
2189
|
+
sleep 1
|
2190
|
+
store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
|
2191
|
+
sleep 2
|
2192
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
2193
|
+
end
|
2194
|
+
|
2195
|
+
it 'should support expires on store and key?' do
|
2196
|
+
store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
|
2197
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2198
|
+
sleep 1
|
2199
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2200
|
+
sleep 2
|
2201
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2202
|
+
end
|
2203
|
+
|
2204
|
+
it 'should support updating the expiration time in load' do
|
2205
|
+
store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
2206
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2207
|
+
sleep 1
|
2208
|
+
store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2209
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2210
|
+
sleep 1
|
2211
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2212
|
+
sleep 3
|
2213
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2214
|
+
end
|
2215
|
+
|
2216
|
+
it 'should support updating the expiration time in key?' do
|
2217
|
+
store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
2218
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2219
|
+
sleep 1
|
2220
|
+
store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
|
2221
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2222
|
+
sleep 1
|
2223
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2224
|
+
sleep 3
|
2225
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2226
|
+
end
|
2227
|
+
|
2228
|
+
it 'should support updating the expiration time in fetch' do
|
2229
|
+
store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
|
2230
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2231
|
+
sleep 1
|
2232
|
+
store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
|
2233
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2234
|
+
sleep 1
|
2235
|
+
store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
|
2236
|
+
sleep 3
|
2237
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2238
|
+
end
|
2239
|
+
|
2240
|
+
it 'should respect expires in delete' do
|
2241
|
+
store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
|
2242
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2243
|
+
sleep 1
|
2244
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2245
|
+
sleep 2
|
2246
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2247
|
+
end
|
2248
|
+
|
2249
|
+
it 'should support the #expires syntactic sugar' do
|
2250
|
+
store['longlive_key'] = 'longlive_value'
|
2251
|
+
store.expires(2).store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]})
|
2252
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2253
|
+
sleep 1
|
2254
|
+
store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
|
2255
|
+
sleep 2
|
2256
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2257
|
+
store['longlive_key'].should == 'longlive_value'
|
2258
|
+
end
|
2259
|
+
end
|
2260
|
+
|
2261
|
+
#################### null_hashkey_objectvalue ####################
|
2262
|
+
|
2263
|
+
shared_examples_for 'null_hashkey_objectvalue' do
|
2264
|
+
it "reads from keys that are Hashs like a Hash" do
|
2265
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2266
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
2267
|
+
end
|
2268
|
+
|
2269
|
+
it "guarantees that the same Object value is returned when setting a Hash key" do
|
2270
|
+
value = Value.new(:objval1)
|
2271
|
+
(store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
|
2272
|
+
end
|
2273
|
+
|
2274
|
+
it "returns false from key? if a Hash key is not available" do
|
2275
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2276
|
+
end
|
2277
|
+
|
2278
|
+
it "returns nil from delete if an element for a Hash key does not exist" do
|
2279
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == nil
|
2280
|
+
end
|
2281
|
+
|
2282
|
+
it "removes all Hash keys from the store with clear" do
|
2283
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2284
|
+
store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
|
2285
|
+
store.clear.should equal(store)
|
2286
|
+
store.key?({"hashkey1"=>"hashkey2"}).should_not == true
|
2287
|
+
store.key?({"hashkey3"=>"hashkey4"}).should_not == true
|
2288
|
+
end
|
2289
|
+
|
2290
|
+
it "fetches a Hash key with a default value with fetch, if the key is not available" do
|
2291
|
+
store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval1)).should == Value.new(:objval1)
|
2292
|
+
end
|
2293
|
+
|
2294
|
+
it "fetches a Hash key with a block with fetch, if the key is not available" do
|
2295
|
+
key = {"hashkey1"=>"hashkey2"}
|
2296
|
+
value = Value.new(:objval1)
|
2297
|
+
store.fetch(key) do |k|
|
2298
|
+
k.should equal(key)
|
2299
|
+
value
|
2300
|
+
end.should equal(value)
|
2301
|
+
end
|
2302
|
+
|
2303
|
+
it 'should accept options' do
|
2304
|
+
store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
|
2305
|
+
store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
|
2306
|
+
store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
|
2307
|
+
store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
|
2308
|
+
store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
|
2309
|
+
store.clear(:option5 => 5).should equal(store)
|
2310
|
+
store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
|
2311
|
+
end
|
2312
|
+
end
|
2313
|
+
|
2314
|
+
#################### store_hashkey_objectvalue ####################
|
2315
|
+
|
2316
|
+
shared_examples_for 'store_hashkey_objectvalue' do
|
2317
|
+
it "writes Object values to keys that are Hashs like a Hash" do
|
2318
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2319
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2320
|
+
store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
|
2321
|
+
end
|
2322
|
+
|
2323
|
+
it "returns true from key? if a Hash key is available" do
|
2324
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2325
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2326
|
+
store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
|
2327
|
+
store.key?({"hashkey3"=>"hashkey4"}).should == true
|
2328
|
+
end
|
2329
|
+
|
2330
|
+
it "stores Object values with Hash keys with #store" do
|
2331
|
+
value = Value.new(:objval1)
|
2332
|
+
store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
|
2333
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2334
|
+
store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
|
2335
|
+
end
|
2336
|
+
|
2337
|
+
it "stores Hash after clear" do
|
2338
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2339
|
+
store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
|
2340
|
+
store.clear.should equal(store)
|
2341
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2342
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2343
|
+
store[{"hashkey3"=>"hashkey4"}].should be_nil
|
2344
|
+
end
|
2345
|
+
|
2346
|
+
it "removes and returns a Object element with a Hash key from the backing store via delete if it exists" do
|
2347
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2348
|
+
store.delete({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
|
2349
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2350
|
+
end
|
2351
|
+
|
2352
|
+
it "overwrites existing Object values with Hash" do
|
2353
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2354
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2355
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval2)
|
2356
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval2)
|
2357
|
+
end
|
2358
|
+
|
2359
|
+
it "does not run the block if the Hash key is available" do
|
2360
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2361
|
+
unaltered = "unaltered"
|
2362
|
+
store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
|
2363
|
+
unaltered.should == "unaltered"
|
2364
|
+
end
|
2365
|
+
|
2366
|
+
it "fetches a Hash key with a default value with fetch, if the key is available" do
|
2367
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2368
|
+
store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval2)).should == Value.new(:objval1)
|
2369
|
+
end
|
2370
|
+
end
|
2371
|
+
|
2372
|
+
#################### returndifferent_hashkey_objectvalue ####################
|
2373
|
+
|
2374
|
+
shared_examples_for 'returndifferent_hashkey_objectvalue' do
|
2375
|
+
it "guarantees that a different Object value is retrieved from the Hash key" do
|
2376
|
+
value = Value.new(:objval1)
|
2377
|
+
store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
|
2378
|
+
store[{"hashkey1"=>"hashkey2"}].should_not be_equal(Value.new(:objval1))
|
2379
|
+
end
|
2380
|
+
end
|
2381
|
+
|
2382
|
+
#################### expires_hashkey_objectvalue ####################
|
2383
|
+
|
2384
|
+
shared_examples_for 'expires_hashkey_objectvalue' do
|
2385
|
+
it 'should support expires on store and #[]' do
|
2386
|
+
store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
|
2387
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2388
|
+
sleep 1
|
2389
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2390
|
+
sleep 2
|
2391
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2392
|
+
end
|
2393
|
+
|
2394
|
+
it 'should support expires on store and load' do
|
2395
|
+
store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
|
2396
|
+
store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
|
2397
|
+
sleep 1
|
2398
|
+
store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
|
2399
|
+
sleep 2
|
2400
|
+
store.load({"hashkey1"=>"hashkey2"}).should == nil
|
2401
|
+
end
|
2402
|
+
|
2403
|
+
it 'should support expires on store and key?' do
|
2404
|
+
store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
|
2405
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2406
|
+
sleep 1
|
2407
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == true
|
2408
|
+
sleep 2
|
2409
|
+
store.key?({"hashkey1"=>"hashkey2"}).should == false
|
2410
|
+
end
|
2411
|
+
|
2412
|
+
it 'should support updating the expiration time in load' do
|
2413
|
+
store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
|
2414
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2415
|
+
sleep 1
|
2416
|
+
store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == Value.new(:objval2)
|
2417
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2418
|
+
sleep 1
|
2419
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2420
|
+
sleep 3
|
2421
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2422
|
+
end
|
2423
|
+
|
2424
|
+
it 'should support updating the expiration time in key?' do
|
2425
|
+
store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
|
2426
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2427
|
+
sleep 1
|
2428
|
+
store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
|
2429
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2430
|
+
sleep 1
|
2431
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2432
|
+
sleep 3
|
2433
|
+
store[{"hashkey3"=>"hashkey4"}].should == nil
|
2434
|
+
end
|
2435
|
+
|
2436
|
+
it 'should support updating the expiration time in fetch' do
|
2437
|
+
store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
|
2438
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2439
|
+
sleep 1
|
2440
|
+
store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == Value.new(:objval1)
|
2441
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2442
|
+
sleep 1
|
2443
|
+
store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
|
2444
|
+
sleep 3
|
2445
|
+
store[{"hashkey1"=>"hashkey2"}].should == nil
|
2446
|
+
end
|
2447
|
+
|
2448
|
+
it 'should respect expires in delete' do
|
2449
|
+
store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
|
2450
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2451
|
+
sleep 1
|
2452
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2453
|
+
sleep 2
|
2454
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2455
|
+
end
|
2456
|
+
|
2457
|
+
it 'should support the #expires syntactic sugar' do
|
2458
|
+
store['longlive_key'] = 'longlive_value'
|
2459
|
+
store.expires(2).store({"hashkey3"=>"hashkey4"}, Value.new(:objval2))
|
2460
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2461
|
+
sleep 1
|
2462
|
+
store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
|
2463
|
+
sleep 2
|
2464
|
+
store.delete({"hashkey3"=>"hashkey4"}).should == nil
|
2465
|
+
store['longlive_key'].should == 'longlive_value'
|
2466
|
+
end
|
2467
|
+
end
|
2468
|
+
|
2469
|
+
#################### not_increment ####################
|
2470
|
+
|
2471
|
+
shared_examples_for 'not_increment' do
|
2472
|
+
it 'should not support increment' do
|
2473
|
+
expect do
|
2474
|
+
store.increment('inckey')
|
2475
|
+
end.to raise_error(NotImplementedError)
|
2476
|
+
end
|
2477
|
+
end
|
2478
|
+
|
2479
|
+
#################### increment ####################
|
2480
|
+
|
2481
|
+
shared_examples_for 'increment' do
|
2482
|
+
it 'should initialize in increment with 1' do
|
2483
|
+
store.key?('inckey').should be_false
|
2484
|
+
store.increment('inckey').should == 1
|
2485
|
+
store.key?('inckey').should be_true
|
2486
|
+
store.raw['inckey'].should == '1'
|
2487
|
+
store.raw.load('inckey').should == '1'
|
2488
|
+
store.load('inckey', :raw => true).should == '1'
|
2489
|
+
store['inckey'].should == '1'
|
2490
|
+
|
2491
|
+
store.delete('inckey', :raw => true).should == '1'
|
2492
|
+
store.key?('inckey').should be_false
|
2493
|
+
end
|
2494
|
+
|
2495
|
+
it 'should initialize in increment with higher value' do
|
2496
|
+
store.increment('inckey', 42).should == 42
|
2497
|
+
store.key?('inckey').should be_true
|
2498
|
+
store.raw['inckey'].should == '42'
|
2499
|
+
store['inckey'].should == '42'
|
2500
|
+
store.delete('inckey', :raw => true).should == '42'
|
2501
|
+
end
|
2502
|
+
|
2503
|
+
it 'should initialize in increment with 0' do
|
2504
|
+
store.increment('inckey', 0).should == 0
|
2505
|
+
store.key?('inckey').should be_true
|
2506
|
+
store.raw['inckey'].should == '0'
|
2507
|
+
store['inckey'].should == '0'
|
2508
|
+
store.delete('inckey', :raw => true).should == '0'
|
2509
|
+
end
|
2510
|
+
|
2511
|
+
it 'should support incrementing existing value by value' do
|
2512
|
+
store.increment('inckey').should == 1
|
2513
|
+
store.increment('inckey', 42).should == 43
|
2514
|
+
store.raw['inckey'].should == '43'
|
2515
|
+
end
|
2516
|
+
|
2517
|
+
it 'should support incrementing existing value by 0' do
|
2518
|
+
store.increment('inckey').should == 1
|
2519
|
+
store.increment('inckey', 0).should == 1
|
2520
|
+
store.raw['inckey'].should == '1'
|
2521
|
+
end
|
2522
|
+
|
2523
|
+
it 'should support deleting integer value' do
|
2524
|
+
store.increment('inckey').should == 1
|
2525
|
+
store.delete('inckey').should == '1'
|
2526
|
+
store.key?('inckey').should be_false
|
2527
|
+
end
|
2528
|
+
|
2529
|
+
it 'should support decrementing existing value' do
|
2530
|
+
store.increment('inckey', 10).should == 10
|
2531
|
+
store.increment('inckey', -5).should == 5
|
2532
|
+
store.raw['inckey'].should == '5'
|
2533
|
+
store.increment('inckey', -5).should == 0
|
2534
|
+
store.raw['inckey'].should == '0'
|
2535
|
+
end
|
2536
|
+
|
2537
|
+
it 'interpret raw value as integer' do
|
2538
|
+
store.store('inckey', '42', :raw => true)
|
2539
|
+
store.increment('inckey').should == 43
|
2540
|
+
store.raw['inckey'].should == '43'
|
2541
|
+
end
|
2542
|
+
|
2543
|
+
it 'should raise error on non integer value' do
|
2544
|
+
store['strkey'] = 'value'
|
2545
|
+
expect do
|
2546
|
+
store.increment('strkey')
|
2547
|
+
end.to raise_error
|
2548
|
+
end
|
2549
|
+
end
|
2550
|
+
|
2551
|
+
#################### marshallable_key ####################
|
2552
|
+
|
2553
|
+
shared_examples_for 'marshallable_key' do
|
2554
|
+
it 'refuses to #[] from keys that cannot be marshalled' do
|
2555
|
+
expect do
|
2556
|
+
store[Struct.new(:foo).new(:bar)]
|
2557
|
+
end.to raise_error(marshal_error)
|
2558
|
+
end
|
2559
|
+
|
2560
|
+
it 'refuses to load from keys that cannot be marshalled' do
|
2561
|
+
expect do
|
2562
|
+
store.load(Struct.new(:foo).new(:bar))
|
2563
|
+
end.to raise_error(marshal_error)
|
2564
|
+
end
|
2565
|
+
|
2566
|
+
it 'refuses to fetch from keys that cannot be marshalled' do
|
2567
|
+
expect do
|
2568
|
+
store.fetch(Struct.new(:foo).new(:bar), true)
|
2569
|
+
end.to raise_error(marshal_error)
|
2570
|
+
end
|
2571
|
+
|
2572
|
+
it 'refuses to #[]= to keys that cannot be marshalled' do
|
2573
|
+
expect do
|
2574
|
+
store[Struct.new(:foo).new(:bar)] = 'value'
|
2575
|
+
end.to raise_error(marshal_error)
|
2576
|
+
end
|
2577
|
+
|
2578
|
+
it 'refuses to store to keys that cannot be marshalled' do
|
2579
|
+
expect do
|
2580
|
+
store.store Struct.new(:foo).new(:bar), 'value'
|
2581
|
+
end.to raise_error(marshal_error)
|
2582
|
+
end
|
2583
|
+
|
2584
|
+
it 'refuses to check for key? if the key cannot be marshalled' do
|
2585
|
+
expect do
|
2586
|
+
store.key? Struct.new(:foo).new(:bar)
|
2587
|
+
end.to raise_error(marshal_error)
|
2588
|
+
end
|
2589
|
+
|
2590
|
+
it 'refuses to delete a key if the key cannot be marshalled' do
|
2591
|
+
expect do
|
2592
|
+
store.delete Struct.new(:foo).new(:bar)
|
2593
|
+
end.to raise_error(marshal_error)
|
2594
|
+
end
|
2595
|
+
end
|
2596
|
+
|
2597
|
+
#################### marshallable_value ####################
|
2598
|
+
|
2599
|
+
shared_examples_for 'marshallable_value' do
|
2600
|
+
it 'refuses to store values that cannot be marshalled' do
|
2601
|
+
expect do
|
2602
|
+
store.store 'key', Struct.new(:foo).new(:bar)
|
2603
|
+
end.to raise_error(marshal_error)
|
2604
|
+
end
|
2605
|
+
end
|
2606
|
+
|
2607
|
+
#################### transform_value ####################
|
2608
|
+
|
2609
|
+
shared_examples_for 'transform_value' do
|
2610
|
+
it 'allows to bypass transformer with :raw' do
|
2611
|
+
store['key'] = 'value'
|
2612
|
+
load_value(store.load('key', :raw => true)).should == 'value'
|
2613
|
+
|
2614
|
+
store.store('key', 'value', :raw => true)
|
2615
|
+
store.load('key', :raw => true).should == 'value'
|
2616
|
+
store.delete('key', :raw => true).should == 'value'
|
2617
|
+
end
|
2618
|
+
|
2619
|
+
it 'allows to bypass transformer with raw syntactic sugar' do
|
2620
|
+
store['key'] = 'value'
|
2621
|
+
load_value(store.raw.load('key')).should == 'value'
|
2622
|
+
|
2623
|
+
store.raw.store('key', 'value')
|
2624
|
+
store.raw['key'].should == 'value'
|
2625
|
+
store.raw.load('key').should == 'value'
|
2626
|
+
store.raw.delete('key').should == 'value'
|
2627
|
+
|
2628
|
+
store.raw['key'] = 'value2'
|
2629
|
+
store.raw['key'].should == 'value2'
|
2630
|
+
end
|
2631
|
+
|
2632
|
+
it 'should return unmarshalled value' do
|
2633
|
+
store.store('key', 'unmarshalled value', :raw => true)
|
2634
|
+
store.load('key', :raw => true).should == 'unmarshalled value'
|
2635
|
+
store['key'].should == 'unmarshalled value'
|
2636
|
+
store.delete('key').should == 'unmarshalled value'
|
2637
|
+
end
|
2638
|
+
end
|
2639
|
+
|
2640
|
+
#################### transform_value_with_expires ####################
|
2641
|
+
|
2642
|
+
shared_examples_for 'transform_value_with_expires' do
|
2643
|
+
it 'allows to bypass transformer with :raw' do
|
2644
|
+
store['key'] = 'value'
|
2645
|
+
load_value(store.load('key', :raw => true)).should == ['value']
|
2646
|
+
|
2647
|
+
store.store('key', 'value', :expires => 10)
|
2648
|
+
load_value(store.load('key', :raw => true)).first.should == 'value'
|
2649
|
+
load_value(store.load('key', :raw => true)).last.should respond_to(:to_int)
|
2650
|
+
|
2651
|
+
store.store('key', 'value', :raw => true)
|
2652
|
+
store.load('key', :raw => true).should == 'value'
|
2653
|
+
store.delete('key', :raw => true).should == 'value'
|
2654
|
+
end
|
2655
|
+
|
2656
|
+
it 'should return unmarshalled value' do
|
2657
|
+
store.store('key', 'unmarshalled value', :raw => true)
|
2658
|
+
store.load('key', :raw => true).should == 'unmarshalled value'
|
2659
|
+
store['key'].should == 'unmarshalled value'
|
2660
|
+
store.delete('key').should == 'unmarshalled value'
|
2661
|
+
end
|
2662
|
+
end
|
2663
|
+
|