juno 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/Gemfile +2 -1
  2. data/README.md +9 -4
  3. data/lib/juno.rb +10 -9
  4. data/lib/juno/adapters/activerecord.rb +1 -1
  5. data/lib/juno/adapters/cassandra.rb +8 -1
  6. data/lib/juno/adapters/couch.rb +1 -1
  7. data/lib/juno/adapters/datamapper.rb +3 -3
  8. data/lib/juno/adapters/fog.rb +1 -1
  9. data/lib/juno/adapters/hbase.rb +64 -0
  10. data/lib/juno/adapters/lruhash.rb +69 -5
  11. data/lib/juno/adapters/memcached_dalli.rb +0 -4
  12. data/lib/juno/adapters/memcached_native.rb +0 -7
  13. data/lib/juno/adapters/mongo.rb +0 -4
  14. data/lib/juno/adapters/redis.rb +8 -1
  15. data/lib/juno/adapters/sequel.rb +1 -1
  16. data/lib/juno/adapters/tokyocabinet.rb +0 -4
  17. data/lib/juno/base.rb +10 -0
  18. data/lib/juno/expires.rb +1 -1
  19. data/lib/juno/transformer.rb +1 -0
  20. data/lib/juno/version.rb +1 -1
  21. data/spec/generate.rb +75 -17
  22. data/spec/juno/adapter_datamapper_spec.rb +0 -3
  23. data/spec/juno/adapter_hbase_spec.rb +13 -0
  24. data/spec/juno/adapter_lruhash_spec.rb +14 -16
  25. data/spec/juno/adapter_memory_spec.rb +6 -0
  26. data/spec/juno/expires_file_spec.rb +9 -0
  27. data/spec/juno/expires_memory_spec.rb +9 -0
  28. data/spec/juno/lock_spec.rb +6 -0
  29. data/spec/juno/null_adapter_spec.rb +3 -0
  30. data/spec/juno/proxy_expires_memory_spec.rb +9 -0
  31. data/spec/juno/simple_activerecord_spec.rb +7 -0
  32. data/spec/juno/simple_activerecord_with_expires_spec.rb +7 -0
  33. data/spec/juno/simple_cassandra_spec.rb +7 -0
  34. data/spec/juno/simple_couch_spec.rb +7 -0
  35. data/spec/juno/simple_couch_with_expires_spec.rb +7 -0
  36. data/spec/juno/simple_datamapper_spec.rb +7 -0
  37. data/spec/juno/simple_datamapper_with_expires_spec.rb +7 -0
  38. data/spec/juno/simple_datamapper_with_repository_spec.rb +7 -0
  39. data/spec/juno/simple_dbm_spec.rb +7 -0
  40. data/spec/juno/simple_dbm_with_expires_spec.rb +7 -0
  41. data/spec/juno/simple_file_spec.rb +7 -0
  42. data/spec/juno/simple_file_with_expires_spec.rb +7 -0
  43. data/spec/juno/simple_fog_spec.rb +7 -0
  44. data/spec/juno/simple_fog_with_expires_spec.rb +7 -0
  45. data/spec/juno/simple_gdbm_spec.rb +7 -0
  46. data/spec/juno/simple_gdbm_with_expires_spec.rb +7 -0
  47. data/spec/juno/simple_hashfile_spec.rb +7 -0
  48. data/spec/juno/simple_hashfile_with_expires_spec.rb +7 -0
  49. data/spec/juno/simple_hbase_spec.rb +45 -0
  50. data/spec/juno/simple_hbase_with_expires_spec.rb +46 -0
  51. data/spec/juno/simple_leveldb_spec.rb +7 -0
  52. data/spec/juno/simple_leveldb_with_expires_spec.rb +7 -0
  53. data/spec/juno/simple_localmemcache_spec.rb +7 -0
  54. data/spec/juno/simple_localmemcache_with_expires_spec.rb +7 -0
  55. data/spec/juno/simple_lruhash_spec.rb +7 -0
  56. data/spec/juno/simple_lruhash_with_expires_spec.rb +7 -0
  57. data/spec/juno/simple_memcached_dalli_spec.rb +7 -0
  58. data/spec/juno/simple_memcached_native_spec.rb +7 -0
  59. data/spec/juno/simple_memcached_spec.rb +7 -0
  60. data/spec/juno/simple_memory_spec.rb +7 -0
  61. data/spec/juno/simple_memory_with_compress_spec.rb +7 -0
  62. data/spec/juno/simple_memory_with_expires_spec.rb +7 -0
  63. data/spec/juno/simple_memory_with_json_key_serializer_spec.rb +4 -0
  64. data/spec/juno/simple_memory_with_json_md5_key_serializer_spec.rb +4 -0
  65. data/spec/juno/simple_memory_with_prefix_spec.rb +7 -0
  66. data/spec/juno/simple_memory_with_quicklz_compress_spec.rb +7 -0
  67. data/spec/juno/simple_mongo_spec.rb +7 -0
  68. data/spec/juno/simple_mongo_with_expires_spec.rb +7 -0
  69. data/spec/juno/simple_null_spec.rb +3 -0
  70. data/spec/juno/simple_pstore_spec.rb +7 -0
  71. data/spec/juno/simple_pstore_with_expires_spec.rb +7 -0
  72. data/spec/juno/simple_redis_spec.rb +7 -0
  73. data/spec/juno/simple_riak_spec.rb +7 -0
  74. data/spec/juno/simple_riak_with_expires_spec.rb +7 -0
  75. data/spec/juno/simple_sdbm_spec.rb +7 -0
  76. data/spec/juno/simple_sdbm_with_expires_spec.rb +7 -0
  77. data/spec/juno/simple_sequel_spec.rb +7 -0
  78. data/spec/juno/simple_sequel_with_expires_spec.rb +7 -0
  79. data/spec/juno/simple_sqlite_spec.rb +7 -0
  80. data/spec/juno/simple_sqlite_with_expires_spec.rb +7 -0
  81. data/spec/juno/simple_tokyocabinet_spec.rb +7 -0
  82. data/spec/juno/simple_tokyocabinet_with_expires_spec.rb +7 -0
  83. data/spec/juno/simple_yaml_spec.rb +6 -0
  84. data/spec/juno/simple_yaml_with_expires_spec.rb +6 -0
  85. data/spec/juno/transformer_bzip2_spec.rb +22 -0
  86. data/spec/juno/transformer_marshal_base64_spec.rb +7 -0
  87. data/spec/juno/transformer_marshal_escape_spec.rb +7 -0
  88. data/spec/juno/transformer_marshal_hmac_spec.rb +7 -0
  89. data/spec/juno/transformer_marshal_md5_spec.rb +7 -0
  90. data/spec/juno/transformer_marshal_md5_spread_spec.rb +7 -0
  91. data/spec/juno/transformer_marshal_prefix_spec.rb +7 -0
  92. data/spec/juno/transformer_marshal_rmd160_spec.rb +7 -0
  93. data/spec/juno/transformer_marshal_sha1_spec.rb +7 -0
  94. data/spec/juno/transformer_marshal_sha256_spec.rb +7 -0
  95. data/spec/juno/transformer_marshal_sha384_spec.rb +7 -0
  96. data/spec/juno/transformer_marshal_sha512_spec.rb +7 -0
  97. data/spec/juno/transformer_marshal_uuencode_spec.rb +7 -0
  98. data/spec/juno/transformer_ox_spec.rb +6 -0
  99. data/spec/juno/transformer_yaml_spec.rb +6 -0
  100. data/spec/junospecs.rb +990 -320
  101. metadata +11 -2
data/spec/junospecs.rb CHANGED
@@ -1,5 +1,183 @@
1
1
  # Generated by generate.rb
2
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 "removes and returns a Boolean element with a String key from the backing store via delete if it exists" do
80
+ store["strkey1"] = true
81
+ store.delete("strkey1").should == true
82
+ store.key?("strkey1").should == false
83
+ end
84
+
85
+ it "overwrites existing Boolean values with String" do
86
+ store["strkey1"] = true
87
+ store["strkey1"].should == true
88
+ store["strkey1"] = false
89
+ store["strkey1"].should == false
90
+ end
91
+
92
+ it "does not run the block if the String key is available" do
93
+ store["strkey1"] = true
94
+ unaltered = "unaltered"
95
+ store.fetch("strkey1") { unaltered = "altered" }
96
+ unaltered.should == "unaltered"
97
+ end
98
+
99
+ it "fetches a String key with a default value with fetch, if the key is available" do
100
+ store["strkey1"] = true
101
+ store.fetch("strkey1", false).should == true
102
+ end
103
+ end
104
+
105
+ #################### expires_stringkey_booleanvalue ####################
106
+
107
+ shared_examples_for 'expires_stringkey_booleanvalue' do
108
+ it 'should support expires on store and #[]' do
109
+ store.store("strkey1", true, :expires => 2)
110
+ store["strkey1"].should == true
111
+ sleep 1
112
+ store["strkey1"].should == true
113
+ sleep 2
114
+ store["strkey1"].should == nil
115
+ end
116
+
117
+ it 'should support expires on store and load' do
118
+ store.store("strkey1", true, :expires => 2)
119
+ store.load("strkey1").should == true
120
+ sleep 1
121
+ store.load("strkey1").should == true
122
+ sleep 2
123
+ store.load("strkey1").should == nil
124
+ end
125
+
126
+ it 'should support expires on store and key?' do
127
+ store.store("strkey1", true, :expires => 2)
128
+ store.key?("strkey1").should == true
129
+ sleep 1
130
+ store.key?("strkey1").should == true
131
+ sleep 2
132
+ store.key?("strkey1").should == false
133
+ end
134
+
135
+ it 'should support updating the expiration time in load' do
136
+ store.store("strkey2", false, :expires => 2)
137
+ store["strkey2"].should == false
138
+ sleep 1
139
+ store.load("strkey2", :expires => 3).should == false
140
+ store["strkey2"].should == false
141
+ sleep 1
142
+ store["strkey2"].should == false
143
+ sleep 3
144
+ store["strkey2"].should == nil
145
+ end
146
+
147
+ it 'should support updating the expiration time in key?' do
148
+ store.store("strkey2", false, :expires => 2)
149
+ store["strkey2"].should == false
150
+ sleep 1
151
+ store.key?("strkey2", :expires => 3).should be_true
152
+ store["strkey2"].should == false
153
+ sleep 1
154
+ store["strkey2"].should == false
155
+ sleep 3
156
+ store["strkey2"].should == nil
157
+ end
158
+
159
+ it 'should support updating the expiration time in fetch' do
160
+ store.store("strkey1", true, :expires => 2)
161
+ store["strkey1"].should == true
162
+ sleep 1
163
+ store.fetch("strkey1", nil, :expires => 3).should == true
164
+ store["strkey1"].should == true
165
+ sleep 1
166
+ store["strkey1"].should == true
167
+ sleep 3
168
+ store["strkey1"].should == nil
169
+ end
170
+
171
+ it 'should respect expires in delete' do
172
+ store.store("strkey2", false, :expires => 2)
173
+ store["strkey2"].should == false
174
+ sleep 1
175
+ store["strkey2"].should == false
176
+ sleep 2
177
+ store.delete("strkey2").should == nil
178
+ end
179
+ end
180
+
3
181
  #################### null_stringkey_stringvalue ####################
4
182
 
5
183
  shared_examples_for 'null_stringkey_stringvalue' do
@@ -65,6 +243,8 @@ shared_examples_for 'store_stringkey_stringvalue' do
65
243
  it "returns true from key? if a String key is available" do
66
244
  store["strkey1"] = "strval1"
67
245
  store.key?("strkey1").should == true
246
+ store["strkey2"] = "strval2"
247
+ store.key?("strkey2").should == true
68
248
  end
69
249
 
70
250
  it "stores String values with String keys with #store" do
@@ -152,6 +332,18 @@ shared_examples_for 'expires_stringkey_stringvalue' do
152
332
  store["strkey2"].should == nil
153
333
  end
154
334
 
335
+ it 'should support updating the expiration time in key?' do
336
+ store.store("strkey2", "strval2", :expires => 2)
337
+ store["strkey2"].should == "strval2"
338
+ sleep 1
339
+ store.key?("strkey2", :expires => 3).should be_true
340
+ store["strkey2"].should == "strval2"
341
+ sleep 1
342
+ store["strkey2"].should == "strval2"
343
+ sleep 3
344
+ store["strkey2"].should == nil
345
+ end
346
+
155
347
  it 'should support updating the expiration time in fetch' do
156
348
  store.store("strkey1", "strval1", :expires => 2)
157
349
  store["strkey1"].should == "strval1"
@@ -174,6 +366,194 @@ shared_examples_for 'expires_stringkey_stringvalue' do
174
366
  end
175
367
  end
176
368
 
369
+ #################### null_stringkey_hashvalue ####################
370
+
371
+ shared_examples_for 'null_stringkey_hashvalue' do
372
+ it "reads from keys that are Strings like a Hash" do
373
+ store["strkey1"].should == nil
374
+ store.load("strkey1").should == nil
375
+ end
376
+
377
+ it "guarantees that the same Hash value is returned when setting a String key" do
378
+ value = {"hashval1"=>["array1", 1]}
379
+ (store["strkey1"] = value).should equal(value)
380
+ end
381
+
382
+ it "returns false from key? if a String key is not available" do
383
+ store.key?("strkey1").should == false
384
+ end
385
+
386
+ it "returns nil from delete if an element for a String key does not exist" do
387
+ store.delete("strkey1").should == nil
388
+ end
389
+
390
+ it "removes all String keys from the store with clear" do
391
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
392
+ store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
393
+ store.clear.should equal(store)
394
+ store.key?("strkey1").should_not == true
395
+ store.key?("strkey2").should_not == true
396
+ end
397
+
398
+ it "fetches a String key with a default value with fetch, if the key is not available" do
399
+ store.fetch("strkey1", {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
400
+ end
401
+
402
+ it "fetches a String key with a block with fetch, if the key is not available" do
403
+ key = "strkey1"
404
+ value = {"hashval1"=>["array1", 1]}
405
+ store.fetch(key) do |k|
406
+ k.should equal(key)
407
+ value
408
+ end.should equal(value)
409
+ end
410
+
411
+ it 'should accept options' do
412
+ store.key?("strkey1", :option1 => 1).should == false
413
+ store.load("strkey1", :option2 => 2).should == nil
414
+ store.fetch("strkey1", 42, :option3 => 3).should == 42
415
+ store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
416
+ store.delete("strkey1", :option4 => 4).should == nil
417
+ store.clear(:option5 => 5).should equal(store)
418
+ store.store("strkey1", {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
419
+ end
420
+ end
421
+
422
+ #################### store_stringkey_hashvalue ####################
423
+
424
+ shared_examples_for 'store_stringkey_hashvalue' do
425
+ it "writes Hash values to keys that are Strings like a Hash" do
426
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
427
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
428
+ store.load("strkey1").should == {"hashval1"=>["array1", 1]}
429
+ end
430
+
431
+ it "returns true from key? if a String key is available" do
432
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
433
+ store.key?("strkey1").should == true
434
+ store["strkey2"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
435
+ store.key?("strkey2").should == true
436
+ end
437
+
438
+ it "stores Hash values with String keys with #store" do
439
+ value = {"hashval1"=>["array1", 1]}
440
+ store.store("strkey1", value).should equal(value)
441
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
442
+ store.load("strkey1").should == {"hashval1"=>["array1", 1]}
443
+ end
444
+
445
+ it "removes and returns a Hash element with a String key from the backing store via delete if it exists" do
446
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
447
+ store.delete("strkey1").should == {"hashval1"=>["array1", 1]}
448
+ store.key?("strkey1").should == false
449
+ end
450
+
451
+ it "overwrites existing Hash values with String" do
452
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
453
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
454
+ store["strkey1"] = {"hashval3"=>["array2", {"hashval4"=>42}]}
455
+ store["strkey1"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
456
+ end
457
+
458
+ it "does not run the block if the String key is available" do
459
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
460
+ unaltered = "unaltered"
461
+ store.fetch("strkey1") { unaltered = "altered" }
462
+ unaltered.should == "unaltered"
463
+ end
464
+
465
+ it "fetches a String key with a default value with fetch, if the key is available" do
466
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
467
+ store.fetch("strkey1", {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
468
+ end
469
+ end
470
+
471
+ #################### returndifferent_stringkey_hashvalue ####################
472
+
473
+ shared_examples_for 'returndifferent_stringkey_hashvalue' do
474
+ it "guarantees that a different Hash value is retrieved from the String key" do
475
+ value = {"hashval1"=>["array1", 1]}
476
+ store["strkey1"] = {"hashval1"=>["array1", 1]}
477
+ store["strkey1"].should_not be_equal({"hashval1"=>["array1", 1]})
478
+ end
479
+ end
480
+
481
+ #################### expires_stringkey_hashvalue ####################
482
+
483
+ shared_examples_for 'expires_stringkey_hashvalue' do
484
+ it 'should support expires on store and #[]' do
485
+ store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
486
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
487
+ sleep 1
488
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
489
+ sleep 2
490
+ store["strkey1"].should == nil
491
+ end
492
+
493
+ it 'should support expires on store and load' do
494
+ store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
495
+ store.load("strkey1").should == {"hashval1"=>["array1", 1]}
496
+ sleep 1
497
+ store.load("strkey1").should == {"hashval1"=>["array1", 1]}
498
+ sleep 2
499
+ store.load("strkey1").should == nil
500
+ end
501
+
502
+ it 'should support expires on store and key?' do
503
+ store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
504
+ store.key?("strkey1").should == true
505
+ sleep 1
506
+ store.key?("strkey1").should == true
507
+ sleep 2
508
+ store.key?("strkey1").should == false
509
+ end
510
+
511
+ it 'should support updating the expiration time in load' do
512
+ store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
513
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
514
+ sleep 1
515
+ store.load("strkey2", :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
516
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
517
+ sleep 1
518
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
519
+ sleep 3
520
+ store["strkey2"].should == nil
521
+ end
522
+
523
+ it 'should support updating the expiration time in key?' do
524
+ store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
525
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
526
+ sleep 1
527
+ store.key?("strkey2", :expires => 3).should be_true
528
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
529
+ sleep 1
530
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
531
+ sleep 3
532
+ store["strkey2"].should == nil
533
+ end
534
+
535
+ it 'should support updating the expiration time in fetch' do
536
+ store.store("strkey1", {"hashval1"=>["array1", 1]}, :expires => 2)
537
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
538
+ sleep 1
539
+ store.fetch("strkey1", nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
540
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
541
+ sleep 1
542
+ store["strkey1"].should == {"hashval1"=>["array1", 1]}
543
+ sleep 3
544
+ store["strkey1"].should == nil
545
+ end
546
+
547
+ it 'should respect expires in delete' do
548
+ store.store("strkey2", {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
549
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
550
+ sleep 1
551
+ store["strkey2"].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
552
+ sleep 2
553
+ store.delete("strkey2").should == nil
554
+ end
555
+ end
556
+
177
557
  #################### null_stringkey_objectvalue ####################
178
558
 
179
559
  shared_examples_for 'null_stringkey_objectvalue' do
@@ -239,6 +619,8 @@ shared_examples_for 'store_stringkey_objectvalue' do
239
619
  it "returns true from key? if a String key is available" do
240
620
  store["strkey1"] = Value.new(:objval1)
241
621
  store.key?("strkey1").should == true
622
+ store["strkey2"] = Value.new(:objval2)
623
+ store.key?("strkey2").should == true
242
624
  end
243
625
 
244
626
  it "stores Object values with String keys with #store" do
@@ -326,6 +708,18 @@ shared_examples_for 'expires_stringkey_objectvalue' do
326
708
  store["strkey2"].should == nil
327
709
  end
328
710
 
711
+ it 'should support updating the expiration time in key?' do
712
+ store.store("strkey2", Value.new(:objval2), :expires => 2)
713
+ store["strkey2"].should == Value.new(:objval2)
714
+ sleep 1
715
+ store.key?("strkey2", :expires => 3).should be_true
716
+ store["strkey2"].should == Value.new(:objval2)
717
+ sleep 1
718
+ store["strkey2"].should == Value.new(:objval2)
719
+ sleep 3
720
+ store["strkey2"].should == nil
721
+ end
722
+
329
723
  it 'should support updating the expiration time in fetch' do
330
724
  store.store("strkey1", Value.new(:objval1), :expires => 2)
331
725
  store["strkey1"].should == Value.new(:objval1)
@@ -348,42 +742,42 @@ shared_examples_for 'expires_stringkey_objectvalue' do
348
742
  end
349
743
  end
350
744
 
351
- #################### null_stringkey_hashvalue ####################
745
+ #################### null_objectkey_booleanvalue ####################
352
746
 
353
- shared_examples_for 'null_stringkey_hashvalue' do
354
- it "reads from keys that are Strings like a Hash" do
355
- store["strkey1"].should == nil
356
- store.load("strkey1").should == nil
747
+ shared_examples_for 'null_objectkey_booleanvalue' do
748
+ it "reads from keys that are Objects like a Hash" do
749
+ store[Value.new(:objkey1)].should == nil
750
+ store.load(Value.new(:objkey1)).should == nil
357
751
  end
358
752
 
359
- it "guarantees that the same Hash value is returned when setting a String key" do
360
- value = {"hashval1"=>"hashval2"}
361
- (store["strkey1"] = value).should equal(value)
753
+ it "guarantees that the same Boolean value is returned when setting a Object key" do
754
+ value = true
755
+ (store[Value.new(:objkey1)] = value).should equal(value)
362
756
  end
363
757
 
364
- it "returns false from key? if a String key is not available" do
365
- store.key?("strkey1").should == false
758
+ it "returns false from key? if a Object key is not available" do
759
+ store.key?(Value.new(:objkey1)).should == false
366
760
  end
367
761
 
368
- it "returns nil from delete if an element for a String key does not exist" do
369
- store.delete("strkey1").should == nil
762
+ it "returns nil from delete if an element for a Object key does not exist" do
763
+ store.delete(Value.new(:objkey1)).should == nil
370
764
  end
371
765
 
372
- it "removes all String keys from the store with clear" do
373
- store["strkey1"] = {"hashval1"=>"hashval2"}
374
- store["strkey2"] = {"hashval3"=>"hashval4"}
766
+ it "removes all Object keys from the store with clear" do
767
+ store[Value.new(:objkey1)] = true
768
+ store[Value.new(:objkey2)] = false
375
769
  store.clear.should equal(store)
376
- store.key?("strkey1").should_not == true
377
- store.key?("strkey2").should_not == true
770
+ store.key?(Value.new(:objkey1)).should_not == true
771
+ store.key?(Value.new(:objkey2)).should_not == true
378
772
  end
379
773
 
380
- it "fetches a String key with a default value with fetch, if the key is not available" do
381
- store.fetch("strkey1", {"hashval1"=>"hashval2"}).should == {"hashval1"=>"hashval2"}
774
+ it "fetches a Object key with a default value with fetch, if the key is not available" do
775
+ store.fetch(Value.new(:objkey1), true).should == true
382
776
  end
383
777
 
384
- it "fetches a String key with a block with fetch, if the key is not available" do
385
- key = "strkey1"
386
- value = {"hashval1"=>"hashval2"}
778
+ it "fetches a Object key with a block with fetch, if the key is not available" do
779
+ key = Value.new(:objkey1)
780
+ value = true
387
781
  store.fetch(key) do |k|
388
782
  k.should equal(key)
389
783
  value
@@ -391,134 +785,138 @@ shared_examples_for 'null_stringkey_hashvalue' do
391
785
  end
392
786
 
393
787
  it 'should accept options' do
394
- store.key?("strkey1", :option1 => 1).should == false
395
- store.load("strkey1", :option2 => 2).should == nil
396
- store.fetch("strkey1", 42, :option3 => 3).should == 42
397
- store.fetch("strkey1", :option3 => 3) { 42 }.should == 42
398
- store.delete("strkey1", :option4 => 4).should == nil
788
+ store.key?(Value.new(:objkey1), :option1 => 1).should == false
789
+ store.load(Value.new(:objkey1), :option2 => 2).should == nil
790
+ store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
791
+ store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
792
+ store.delete(Value.new(:objkey1), :option4 => 4).should == nil
399
793
  store.clear(:option5 => 5).should equal(store)
400
- store.store("strkey1", {"hashval1"=>"hashval2"}, :option6 => 6).should == {"hashval1"=>"hashval2"}
794
+ store.store(Value.new(:objkey1), true, :option6 => 6).should == true
401
795
  end
402
796
  end
403
797
 
404
- #################### store_stringkey_hashvalue ####################
798
+ #################### store_objectkey_booleanvalue ####################
405
799
 
406
- shared_examples_for 'store_stringkey_hashvalue' do
407
- it "writes Hash values to keys that are Strings like a Hash" do
408
- store["strkey1"] = {"hashval1"=>"hashval2"}
409
- store["strkey1"].should == {"hashval1"=>"hashval2"}
410
- store.load("strkey1").should == {"hashval1"=>"hashval2"}
800
+ shared_examples_for 'store_objectkey_booleanvalue' do
801
+ it "writes Boolean values to keys that are Objects like a Hash" do
802
+ store[Value.new(:objkey1)] = true
803
+ store[Value.new(:objkey1)].should == true
804
+ store.load(Value.new(:objkey1)).should == true
411
805
  end
412
806
 
413
- it "returns true from key? if a String key is available" do
414
- store["strkey1"] = {"hashval1"=>"hashval2"}
415
- store.key?("strkey1").should == true
807
+ it "returns true from key? if a Object key is available" do
808
+ store[Value.new(:objkey1)] = true
809
+ store.key?(Value.new(:objkey1)).should == true
810
+ store[Value.new(:objkey2)] = false
811
+ store.key?(Value.new(:objkey2)).should == true
416
812
  end
417
813
 
418
- it "stores Hash values with String keys with #store" do
419
- value = {"hashval1"=>"hashval2"}
420
- store.store("strkey1", value).should equal(value)
421
- store["strkey1"].should == {"hashval1"=>"hashval2"}
422
- store.load("strkey1").should == {"hashval1"=>"hashval2"}
814
+ it "stores Boolean values with Object keys with #store" do
815
+ value = true
816
+ store.store(Value.new(:objkey1), value).should equal(value)
817
+ store[Value.new(:objkey1)].should == true
818
+ store.load(Value.new(:objkey1)).should == true
423
819
  end
424
820
 
425
- it "removes and returns a Hash element with a String key from the backing store via delete if it exists" do
426
- store["strkey1"] = {"hashval1"=>"hashval2"}
427
- store.delete("strkey1").should == {"hashval1"=>"hashval2"}
428
- store.key?("strkey1").should == false
821
+ it "removes and returns a Boolean element with a Object key from the backing store via delete if it exists" do
822
+ store[Value.new(:objkey1)] = true
823
+ store.delete(Value.new(:objkey1)).should == true
824
+ store.key?(Value.new(:objkey1)).should == false
429
825
  end
430
826
 
431
- it "overwrites existing Hash values with String" do
432
- store["strkey1"] = {"hashval1"=>"hashval2"}
433
- store["strkey1"].should == {"hashval1"=>"hashval2"}
434
- store["strkey1"] = {"hashval3"=>"hashval4"}
435
- store["strkey1"].should == {"hashval3"=>"hashval4"}
827
+ it "overwrites existing Boolean values with Object" do
828
+ store[Value.new(:objkey1)] = true
829
+ store[Value.new(:objkey1)].should == true
830
+ store[Value.new(:objkey1)] = false
831
+ store[Value.new(:objkey1)].should == false
436
832
  end
437
833
 
438
- it "does not run the block if the String key is available" do
439
- store["strkey1"] = {"hashval1"=>"hashval2"}
834
+ it "does not run the block if the Object key is available" do
835
+ store[Value.new(:objkey1)] = true
440
836
  unaltered = "unaltered"
441
- store.fetch("strkey1") { unaltered = "altered" }
837
+ store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
442
838
  unaltered.should == "unaltered"
443
839
  end
444
840
 
445
- it "fetches a String key with a default value with fetch, if the key is available" do
446
- store["strkey1"] = {"hashval1"=>"hashval2"}
447
- store.fetch("strkey1", {"hashval3"=>"hashval4"}).should == {"hashval1"=>"hashval2"}
448
- end
449
- end
450
-
451
- #################### returndifferent_stringkey_hashvalue ####################
452
-
453
- shared_examples_for 'returndifferent_stringkey_hashvalue' do
454
- it "guarantees that a different Hash value is retrieved from the String key" do
455
- value = {"hashval1"=>"hashval2"}
456
- store["strkey1"] = {"hashval1"=>"hashval2"}
457
- store["strkey1"].should_not be_equal({"hashval1"=>"hashval2"})
841
+ it "fetches a Object key with a default value with fetch, if the key is available" do
842
+ store[Value.new(:objkey1)] = true
843
+ store.fetch(Value.new(:objkey1), false).should == true
458
844
  end
459
845
  end
460
846
 
461
- #################### expires_stringkey_hashvalue ####################
847
+ #################### expires_objectkey_booleanvalue ####################
462
848
 
463
- shared_examples_for 'expires_stringkey_hashvalue' do
849
+ shared_examples_for 'expires_objectkey_booleanvalue' do
464
850
  it 'should support expires on store and #[]' do
465
- store.store("strkey1", {"hashval1"=>"hashval2"}, :expires => 2)
466
- store["strkey1"].should == {"hashval1"=>"hashval2"}
851
+ store.store(Value.new(:objkey1), true, :expires => 2)
852
+ store[Value.new(:objkey1)].should == true
467
853
  sleep 1
468
- store["strkey1"].should == {"hashval1"=>"hashval2"}
854
+ store[Value.new(:objkey1)].should == true
469
855
  sleep 2
470
- store["strkey1"].should == nil
856
+ store[Value.new(:objkey1)].should == nil
471
857
  end
472
858
 
473
859
  it 'should support expires on store and load' do
474
- store.store("strkey1", {"hashval1"=>"hashval2"}, :expires => 2)
475
- store.load("strkey1").should == {"hashval1"=>"hashval2"}
860
+ store.store(Value.new(:objkey1), true, :expires => 2)
861
+ store.load(Value.new(:objkey1)).should == true
476
862
  sleep 1
477
- store.load("strkey1").should == {"hashval1"=>"hashval2"}
863
+ store.load(Value.new(:objkey1)).should == true
478
864
  sleep 2
479
- store.load("strkey1").should == nil
865
+ store.load(Value.new(:objkey1)).should == nil
480
866
  end
481
867
 
482
868
  it 'should support expires on store and key?' do
483
- store.store("strkey1", {"hashval1"=>"hashval2"}, :expires => 2)
484
- store.key?("strkey1").should == true
869
+ store.store(Value.new(:objkey1), true, :expires => 2)
870
+ store.key?(Value.new(:objkey1)).should == true
485
871
  sleep 1
486
- store.key?("strkey1").should == true
872
+ store.key?(Value.new(:objkey1)).should == true
487
873
  sleep 2
488
- store.key?("strkey1").should == false
874
+ store.key?(Value.new(:objkey1)).should == false
489
875
  end
490
876
 
491
877
  it 'should support updating the expiration time in load' do
492
- store.store("strkey2", {"hashval3"=>"hashval4"}, :expires => 2)
493
- store["strkey2"].should == {"hashval3"=>"hashval4"}
878
+ store.store(Value.new(:objkey2), false, :expires => 2)
879
+ store[Value.new(:objkey2)].should == false
494
880
  sleep 1
495
- store.load("strkey2", :expires => 3).should == {"hashval3"=>"hashval4"}
496
- store["strkey2"].should == {"hashval3"=>"hashval4"}
881
+ store.load(Value.new(:objkey2), :expires => 3).should == false
882
+ store[Value.new(:objkey2)].should == false
497
883
  sleep 1
498
- store["strkey2"].should == {"hashval3"=>"hashval4"}
884
+ store[Value.new(:objkey2)].should == false
499
885
  sleep 3
500
- store["strkey2"].should == nil
886
+ store[Value.new(:objkey2)].should == nil
887
+ end
888
+
889
+ it 'should support updating the expiration time in key?' do
890
+ store.store(Value.new(:objkey2), false, :expires => 2)
891
+ store[Value.new(:objkey2)].should == false
892
+ sleep 1
893
+ store.key?(Value.new(:objkey2), :expires => 3).should be_true
894
+ store[Value.new(:objkey2)].should == false
895
+ sleep 1
896
+ store[Value.new(:objkey2)].should == false
897
+ sleep 3
898
+ store[Value.new(:objkey2)].should == nil
501
899
  end
502
900
 
503
901
  it 'should support updating the expiration time in fetch' do
504
- store.store("strkey1", {"hashval1"=>"hashval2"}, :expires => 2)
505
- store["strkey1"].should == {"hashval1"=>"hashval2"}
902
+ store.store(Value.new(:objkey1), true, :expires => 2)
903
+ store[Value.new(:objkey1)].should == true
506
904
  sleep 1
507
- store.fetch("strkey1", nil, :expires => 3).should == {"hashval1"=>"hashval2"}
508
- store["strkey1"].should == {"hashval1"=>"hashval2"}
905
+ store.fetch(Value.new(:objkey1), nil, :expires => 3).should == true
906
+ store[Value.new(:objkey1)].should == true
509
907
  sleep 1
510
- store["strkey1"].should == {"hashval1"=>"hashval2"}
908
+ store[Value.new(:objkey1)].should == true
511
909
  sleep 3
512
- store["strkey1"].should == nil
910
+ store[Value.new(:objkey1)].should == nil
513
911
  end
514
912
 
515
913
  it 'should respect expires in delete' do
516
- store.store("strkey2", {"hashval3"=>"hashval4"}, :expires => 2)
517
- store["strkey2"].should == {"hashval3"=>"hashval4"}
914
+ store.store(Value.new(:objkey2), false, :expires => 2)
915
+ store[Value.new(:objkey2)].should == false
518
916
  sleep 1
519
- store["strkey2"].should == {"hashval3"=>"hashval4"}
917
+ store[Value.new(:objkey2)].should == false
520
918
  sleep 2
521
- store.delete("strkey2").should == nil
919
+ store.delete(Value.new(:objkey2)).should == nil
522
920
  end
523
921
  end
524
922
 
@@ -587,6 +985,8 @@ shared_examples_for 'store_objectkey_stringvalue' do
587
985
  it "returns true from key? if a Object key is available" do
588
986
  store[Value.new(:objkey1)] = "strval1"
589
987
  store.key?(Value.new(:objkey1)).should == true
988
+ store[Value.new(:objkey2)] = "strval2"
989
+ store.key?(Value.new(:objkey2)).should == true
590
990
  end
591
991
 
592
992
  it "stores String values with Object keys with #store" do
@@ -674,6 +1074,18 @@ shared_examples_for 'expires_objectkey_stringvalue' do
674
1074
  store[Value.new(:objkey2)].should == nil
675
1075
  end
676
1076
 
1077
+ it 'should support updating the expiration time in key?' do
1078
+ store.store(Value.new(:objkey2), "strval2", :expires => 2)
1079
+ store[Value.new(:objkey2)].should == "strval2"
1080
+ sleep 1
1081
+ store.key?(Value.new(:objkey2), :expires => 3).should be_true
1082
+ store[Value.new(:objkey2)].should == "strval2"
1083
+ sleep 1
1084
+ store[Value.new(:objkey2)].should == "strval2"
1085
+ sleep 3
1086
+ store[Value.new(:objkey2)].should == nil
1087
+ end
1088
+
677
1089
  it 'should support updating the expiration time in fetch' do
678
1090
  store.store(Value.new(:objkey1), "strval1", :expires => 2)
679
1091
  store[Value.new(:objkey1)].should == "strval1"
@@ -696,6 +1108,194 @@ shared_examples_for 'expires_objectkey_stringvalue' do
696
1108
  end
697
1109
  end
698
1110
 
1111
+ #################### null_objectkey_hashvalue ####################
1112
+
1113
+ shared_examples_for 'null_objectkey_hashvalue' do
1114
+ it "reads from keys that are Objects like a Hash" do
1115
+ store[Value.new(:objkey1)].should == nil
1116
+ store.load(Value.new(:objkey1)).should == nil
1117
+ end
1118
+
1119
+ it "guarantees that the same Hash value is returned when setting a Object key" do
1120
+ value = {"hashval1"=>["array1", 1]}
1121
+ (store[Value.new(:objkey1)] = value).should equal(value)
1122
+ end
1123
+
1124
+ it "returns false from key? if a Object key is not available" do
1125
+ store.key?(Value.new(:objkey1)).should == false
1126
+ end
1127
+
1128
+ it "returns nil from delete if an element for a Object key does not exist" do
1129
+ store.delete(Value.new(:objkey1)).should == nil
1130
+ end
1131
+
1132
+ it "removes all Object keys from the store with clear" do
1133
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1134
+ store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1135
+ store.clear.should equal(store)
1136
+ store.key?(Value.new(:objkey1)).should_not == true
1137
+ store.key?(Value.new(:objkey2)).should_not == true
1138
+ end
1139
+
1140
+ it "fetches a Object key with a default value with fetch, if the key is not available" do
1141
+ store.fetch(Value.new(:objkey1), {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
1142
+ end
1143
+
1144
+ it "fetches a Object key with a block with fetch, if the key is not available" do
1145
+ key = Value.new(:objkey1)
1146
+ value = {"hashval1"=>["array1", 1]}
1147
+ store.fetch(key) do |k|
1148
+ k.should equal(key)
1149
+ value
1150
+ end.should equal(value)
1151
+ end
1152
+
1153
+ it 'should accept options' do
1154
+ store.key?(Value.new(:objkey1), :option1 => 1).should == false
1155
+ store.load(Value.new(:objkey1), :option2 => 2).should == nil
1156
+ store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
1157
+ store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
1158
+ store.delete(Value.new(:objkey1), :option4 => 4).should == nil
1159
+ store.clear(:option5 => 5).should equal(store)
1160
+ store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
1161
+ end
1162
+ end
1163
+
1164
+ #################### store_objectkey_hashvalue ####################
1165
+
1166
+ shared_examples_for 'store_objectkey_hashvalue' do
1167
+ it "writes Hash values to keys that are Objects like a Hash" do
1168
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1169
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1170
+ store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1171
+ end
1172
+
1173
+ it "returns true from key? if a Object key is available" do
1174
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1175
+ store.key?(Value.new(:objkey1)).should == true
1176
+ store[Value.new(:objkey2)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1177
+ store.key?(Value.new(:objkey2)).should == true
1178
+ end
1179
+
1180
+ it "stores Hash values with Object keys with #store" do
1181
+ value = {"hashval1"=>["array1", 1]}
1182
+ store.store(Value.new(:objkey1), value).should equal(value)
1183
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1184
+ store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1185
+ end
1186
+
1187
+ it "removes and returns a Hash element with a Object key from the backing store via delete if it exists" do
1188
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1189
+ store.delete(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1190
+ store.key?(Value.new(:objkey1)).should == false
1191
+ end
1192
+
1193
+ it "overwrites existing Hash values with Object" do
1194
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1195
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1196
+ store[Value.new(:objkey1)] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1197
+ store[Value.new(:objkey1)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1198
+ end
1199
+
1200
+ it "does not run the block if the Object key is available" do
1201
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1202
+ unaltered = "unaltered"
1203
+ store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
1204
+ unaltered.should == "unaltered"
1205
+ end
1206
+
1207
+ it "fetches a Object key with a default value with fetch, if the key is available" do
1208
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1209
+ store.fetch(Value.new(:objkey1), {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
1210
+ end
1211
+ end
1212
+
1213
+ #################### returndifferent_objectkey_hashvalue ####################
1214
+
1215
+ shared_examples_for 'returndifferent_objectkey_hashvalue' do
1216
+ it "guarantees that a different Hash value is retrieved from the Object key" do
1217
+ value = {"hashval1"=>["array1", 1]}
1218
+ store[Value.new(:objkey1)] = {"hashval1"=>["array1", 1]}
1219
+ store[Value.new(:objkey1)].should_not be_equal({"hashval1"=>["array1", 1]})
1220
+ end
1221
+ end
1222
+
1223
+ #################### expires_objectkey_hashvalue ####################
1224
+
1225
+ shared_examples_for 'expires_objectkey_hashvalue' do
1226
+ it 'should support expires on store and #[]' do
1227
+ store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1228
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1229
+ sleep 1
1230
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1231
+ sleep 2
1232
+ store[Value.new(:objkey1)].should == nil
1233
+ end
1234
+
1235
+ it 'should support expires on store and load' do
1236
+ store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1237
+ store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1238
+ sleep 1
1239
+ store.load(Value.new(:objkey1)).should == {"hashval1"=>["array1", 1]}
1240
+ sleep 2
1241
+ store.load(Value.new(:objkey1)).should == nil
1242
+ end
1243
+
1244
+ it 'should support expires on store and key?' do
1245
+ store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1246
+ store.key?(Value.new(:objkey1)).should == true
1247
+ sleep 1
1248
+ store.key?(Value.new(:objkey1)).should == true
1249
+ sleep 2
1250
+ store.key?(Value.new(:objkey1)).should == false
1251
+ end
1252
+
1253
+ it 'should support updating the expiration time in load' do
1254
+ store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1255
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1256
+ sleep 1
1257
+ store.load(Value.new(:objkey2), :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1258
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1259
+ sleep 1
1260
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1261
+ sleep 3
1262
+ store[Value.new(:objkey2)].should == nil
1263
+ end
1264
+
1265
+ it 'should support updating the expiration time in key?' do
1266
+ store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1267
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1268
+ sleep 1
1269
+ store.key?(Value.new(:objkey2), :expires => 3).should be_true
1270
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1271
+ sleep 1
1272
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1273
+ sleep 3
1274
+ store[Value.new(:objkey2)].should == nil
1275
+ end
1276
+
1277
+ it 'should support updating the expiration time in fetch' do
1278
+ store.store(Value.new(:objkey1), {"hashval1"=>["array1", 1]}, :expires => 2)
1279
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1280
+ sleep 1
1281
+ store.fetch(Value.new(:objkey1), nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
1282
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1283
+ sleep 1
1284
+ store[Value.new(:objkey1)].should == {"hashval1"=>["array1", 1]}
1285
+ sleep 3
1286
+ store[Value.new(:objkey1)].should == nil
1287
+ end
1288
+
1289
+ it 'should respect expires in delete' do
1290
+ store.store(Value.new(:objkey2), {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1291
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1292
+ sleep 1
1293
+ store[Value.new(:objkey2)].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1294
+ sleep 2
1295
+ store.delete(Value.new(:objkey2)).should == nil
1296
+ end
1297
+ end
1298
+
699
1299
  #################### null_objectkey_objectvalue ####################
700
1300
 
701
1301
  shared_examples_for 'null_objectkey_objectvalue' do
@@ -761,6 +1361,8 @@ shared_examples_for 'store_objectkey_objectvalue' do
761
1361
  it "returns true from key? if a Object key is available" do
762
1362
  store[Value.new(:objkey1)] = Value.new(:objval1)
763
1363
  store.key?(Value.new(:objkey1)).should == true
1364
+ store[Value.new(:objkey2)] = Value.new(:objval2)
1365
+ store.key?(Value.new(:objkey2)).should == true
764
1366
  end
765
1367
 
766
1368
  it "stores Object values with Object keys with #store" do
@@ -848,6 +1450,18 @@ shared_examples_for 'expires_objectkey_objectvalue' do
848
1450
  store[Value.new(:objkey2)].should == nil
849
1451
  end
850
1452
 
1453
+ it 'should support updating the expiration time in key?' do
1454
+ store.store(Value.new(:objkey2), Value.new(:objval2), :expires => 2)
1455
+ store[Value.new(:objkey2)].should == Value.new(:objval2)
1456
+ sleep 1
1457
+ store.key?(Value.new(:objkey2), :expires => 3).should be_true
1458
+ store[Value.new(:objkey2)].should == Value.new(:objval2)
1459
+ sleep 1
1460
+ store[Value.new(:objkey2)].should == Value.new(:objval2)
1461
+ sleep 3
1462
+ store[Value.new(:objkey2)].should == nil
1463
+ end
1464
+
851
1465
  it 'should support updating the expiration time in fetch' do
852
1466
  store.store(Value.new(:objkey1), Value.new(:objval1), :expires => 2)
853
1467
  store[Value.new(:objkey1)].should == Value.new(:objval1)
@@ -870,42 +1484,42 @@ shared_examples_for 'expires_objectkey_objectvalue' do
870
1484
  end
871
1485
  end
872
1486
 
873
- #################### null_objectkey_hashvalue ####################
1487
+ #################### null_hashkey_booleanvalue ####################
874
1488
 
875
- shared_examples_for 'null_objectkey_hashvalue' do
876
- it "reads from keys that are Objects like a Hash" do
877
- store[Value.new(:objkey1)].should == nil
878
- store.load(Value.new(:objkey1)).should == nil
1489
+ shared_examples_for 'null_hashkey_booleanvalue' do
1490
+ it "reads from keys that are Hashs like a Hash" do
1491
+ store[{"hashkey1"=>"hashkey2"}].should == nil
1492
+ store.load({"hashkey1"=>"hashkey2"}).should == nil
879
1493
  end
880
1494
 
881
- it "guarantees that the same Hash value is returned when setting a Object key" do
882
- value = {"hashval1"=>"hashval2"}
883
- (store[Value.new(:objkey1)] = value).should equal(value)
1495
+ it "guarantees that the same Boolean value is returned when setting a Hash key" do
1496
+ value = true
1497
+ (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
884
1498
  end
885
1499
 
886
- it "returns false from key? if a Object key is not available" do
887
- store.key?(Value.new(:objkey1)).should == false
1500
+ it "returns false from key? if a Hash key is not available" do
1501
+ store.key?({"hashkey1"=>"hashkey2"}).should == false
888
1502
  end
889
-
890
- it "returns nil from delete if an element for a Object key does not exist" do
891
- store.delete(Value.new(:objkey1)).should == nil
1503
+
1504
+ it "returns nil from delete if an element for a Hash key does not exist" do
1505
+ store.delete({"hashkey1"=>"hashkey2"}).should == nil
892
1506
  end
893
1507
 
894
- it "removes all Object keys from the store with clear" do
895
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
896
- store[Value.new(:objkey2)] = {"hashval3"=>"hashval4"}
1508
+ it "removes all Hash keys from the store with clear" do
1509
+ store[{"hashkey1"=>"hashkey2"}] = true
1510
+ store[{"hashkey3"=>"hashkey4"}] = false
897
1511
  store.clear.should equal(store)
898
- store.key?(Value.new(:objkey1)).should_not == true
899
- store.key?(Value.new(:objkey2)).should_not == true
1512
+ store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1513
+ store.key?({"hashkey3"=>"hashkey4"}).should_not == true
900
1514
  end
901
1515
 
902
- it "fetches a Object key with a default value with fetch, if the key is not available" do
903
- store.fetch(Value.new(:objkey1), {"hashval1"=>"hashval2"}).should == {"hashval1"=>"hashval2"}
1516
+ it "fetches a Hash key with a default value with fetch, if the key is not available" do
1517
+ store.fetch({"hashkey1"=>"hashkey2"}, true).should == true
904
1518
  end
905
1519
 
906
- it "fetches a Object key with a block with fetch, if the key is not available" do
907
- key = Value.new(:objkey1)
908
- value = {"hashval1"=>"hashval2"}
1520
+ it "fetches a Hash key with a block with fetch, if the key is not available" do
1521
+ key = {"hashkey1"=>"hashkey2"}
1522
+ value = true
909
1523
  store.fetch(key) do |k|
910
1524
  k.should equal(key)
911
1525
  value
@@ -913,134 +1527,138 @@ shared_examples_for 'null_objectkey_hashvalue' do
913
1527
  end
914
1528
 
915
1529
  it 'should accept options' do
916
- store.key?(Value.new(:objkey1), :option1 => 1).should == false
917
- store.load(Value.new(:objkey1), :option2 => 2).should == nil
918
- store.fetch(Value.new(:objkey1), 42, :option3 => 3).should == 42
919
- store.fetch(Value.new(:objkey1), :option3 => 3) { 42 }.should == 42
920
- store.delete(Value.new(:objkey1), :option4 => 4).should == nil
1530
+ store.key?({"hashkey1"=>"hashkey2"}, :option1 => 1).should == false
1531
+ store.load({"hashkey1"=>"hashkey2"}, :option2 => 2).should == nil
1532
+ store.fetch({"hashkey1"=>"hashkey2"}, 42, :option3 => 3).should == 42
1533
+ store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1534
+ store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
921
1535
  store.clear(:option5 => 5).should equal(store)
922
- store.store(Value.new(:objkey1), {"hashval1"=>"hashval2"}, :option6 => 6).should == {"hashval1"=>"hashval2"}
1536
+ store.store({"hashkey1"=>"hashkey2"}, true, :option6 => 6).should == true
923
1537
  end
924
1538
  end
925
1539
 
926
- #################### store_objectkey_hashvalue ####################
1540
+ #################### store_hashkey_booleanvalue ####################
927
1541
 
928
- shared_examples_for 'store_objectkey_hashvalue' do
929
- it "writes Hash values to keys that are Objects like a Hash" do
930
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
931
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
932
- store.load(Value.new(:objkey1)).should == {"hashval1"=>"hashval2"}
1542
+ shared_examples_for 'store_hashkey_booleanvalue' do
1543
+ it "writes Boolean values to keys that are Hashs like a Hash" do
1544
+ store[{"hashkey1"=>"hashkey2"}] = true
1545
+ store[{"hashkey1"=>"hashkey2"}].should == true
1546
+ store.load({"hashkey1"=>"hashkey2"}).should == true
933
1547
  end
934
1548
 
935
- it "returns true from key? if a Object key is available" do
936
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
937
- store.key?(Value.new(:objkey1)).should == true
1549
+ it "returns true from key? if a Hash key is available" do
1550
+ store[{"hashkey1"=>"hashkey2"}] = true
1551
+ store.key?({"hashkey1"=>"hashkey2"}).should == true
1552
+ store[{"hashkey3"=>"hashkey4"}] = false
1553
+ store.key?({"hashkey3"=>"hashkey4"}).should == true
938
1554
  end
939
1555
 
940
- it "stores Hash values with Object keys with #store" do
941
- value = {"hashval1"=>"hashval2"}
942
- store.store(Value.new(:objkey1), value).should equal(value)
943
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
944
- store.load(Value.new(:objkey1)).should == {"hashval1"=>"hashval2"}
1556
+ it "stores Boolean values with Hash keys with #store" do
1557
+ value = true
1558
+ store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1559
+ store[{"hashkey1"=>"hashkey2"}].should == true
1560
+ store.load({"hashkey1"=>"hashkey2"}).should == true
945
1561
  end
946
1562
 
947
- it "removes and returns a Hash element with a Object key from the backing store via delete if it exists" do
948
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
949
- store.delete(Value.new(:objkey1)).should == {"hashval1"=>"hashval2"}
950
- store.key?(Value.new(:objkey1)).should == false
1563
+ it "removes and returns a Boolean element with a Hash key from the backing store via delete if it exists" do
1564
+ store[{"hashkey1"=>"hashkey2"}] = true
1565
+ store.delete({"hashkey1"=>"hashkey2"}).should == true
1566
+ store.key?({"hashkey1"=>"hashkey2"}).should == false
951
1567
  end
952
1568
 
953
- it "overwrites existing Hash values with Object" do
954
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
955
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
956
- store[Value.new(:objkey1)] = {"hashval3"=>"hashval4"}
957
- store[Value.new(:objkey1)].should == {"hashval3"=>"hashval4"}
1569
+ it "overwrites existing Boolean values with Hash" do
1570
+ store[{"hashkey1"=>"hashkey2"}] = true
1571
+ store[{"hashkey1"=>"hashkey2"}].should == true
1572
+ store[{"hashkey1"=>"hashkey2"}] = false
1573
+ store[{"hashkey1"=>"hashkey2"}].should == false
958
1574
  end
959
1575
 
960
- it "does not run the block if the Object key is available" do
961
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
1576
+ it "does not run the block if the Hash key is available" do
1577
+ store[{"hashkey1"=>"hashkey2"}] = true
962
1578
  unaltered = "unaltered"
963
- store.fetch(Value.new(:objkey1)) { unaltered = "altered" }
1579
+ store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
964
1580
  unaltered.should == "unaltered"
965
1581
  end
966
1582
 
967
- it "fetches a Object key with a default value with fetch, if the key is available" do
968
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
969
- store.fetch(Value.new(:objkey1), {"hashval3"=>"hashval4"}).should == {"hashval1"=>"hashval2"}
970
- end
971
- end
972
-
973
- #################### returndifferent_objectkey_hashvalue ####################
974
-
975
- shared_examples_for 'returndifferent_objectkey_hashvalue' do
976
- it "guarantees that a different Hash value is retrieved from the Object key" do
977
- value = {"hashval1"=>"hashval2"}
978
- store[Value.new(:objkey1)] = {"hashval1"=>"hashval2"}
979
- store[Value.new(:objkey1)].should_not be_equal({"hashval1"=>"hashval2"})
1583
+ it "fetches a Hash key with a default value with fetch, if the key is available" do
1584
+ store[{"hashkey1"=>"hashkey2"}] = true
1585
+ store.fetch({"hashkey1"=>"hashkey2"}, false).should == true
980
1586
  end
981
1587
  end
982
1588
 
983
- #################### expires_objectkey_hashvalue ####################
1589
+ #################### expires_hashkey_booleanvalue ####################
984
1590
 
985
- shared_examples_for 'expires_objectkey_hashvalue' do
1591
+ shared_examples_for 'expires_hashkey_booleanvalue' do
986
1592
  it 'should support expires on store and #[]' do
987
- store.store(Value.new(:objkey1), {"hashval1"=>"hashval2"}, :expires => 2)
988
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
1593
+ store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1594
+ store[{"hashkey1"=>"hashkey2"}].should == true
989
1595
  sleep 1
990
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
1596
+ store[{"hashkey1"=>"hashkey2"}].should == true
991
1597
  sleep 2
992
- store[Value.new(:objkey1)].should == nil
1598
+ store[{"hashkey1"=>"hashkey2"}].should == nil
993
1599
  end
994
1600
 
995
1601
  it 'should support expires on store and load' do
996
- store.store(Value.new(:objkey1), {"hashval1"=>"hashval2"}, :expires => 2)
997
- store.load(Value.new(:objkey1)).should == {"hashval1"=>"hashval2"}
1602
+ store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1603
+ store.load({"hashkey1"=>"hashkey2"}).should == true
998
1604
  sleep 1
999
- store.load(Value.new(:objkey1)).should == {"hashval1"=>"hashval2"}
1605
+ store.load({"hashkey1"=>"hashkey2"}).should == true
1000
1606
  sleep 2
1001
- store.load(Value.new(:objkey1)).should == nil
1607
+ store.load({"hashkey1"=>"hashkey2"}).should == nil
1002
1608
  end
1003
1609
 
1004
1610
  it 'should support expires on store and key?' do
1005
- store.store(Value.new(:objkey1), {"hashval1"=>"hashval2"}, :expires => 2)
1006
- store.key?(Value.new(:objkey1)).should == true
1611
+ store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1612
+ store.key?({"hashkey1"=>"hashkey2"}).should == true
1007
1613
  sleep 1
1008
- store.key?(Value.new(:objkey1)).should == true
1614
+ store.key?({"hashkey1"=>"hashkey2"}).should == true
1009
1615
  sleep 2
1010
- store.key?(Value.new(:objkey1)).should == false
1616
+ store.key?({"hashkey1"=>"hashkey2"}).should == false
1011
1617
  end
1012
1618
 
1013
1619
  it 'should support updating the expiration time in load' do
1014
- store.store(Value.new(:objkey2), {"hashval3"=>"hashval4"}, :expires => 2)
1015
- store[Value.new(:objkey2)].should == {"hashval3"=>"hashval4"}
1620
+ store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1621
+ store[{"hashkey3"=>"hashkey4"}].should == false
1016
1622
  sleep 1
1017
- store.load(Value.new(:objkey2), :expires => 3).should == {"hashval3"=>"hashval4"}
1018
- store[Value.new(:objkey2)].should == {"hashval3"=>"hashval4"}
1623
+ store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == false
1624
+ store[{"hashkey3"=>"hashkey4"}].should == false
1019
1625
  sleep 1
1020
- store[Value.new(:objkey2)].should == {"hashval3"=>"hashval4"}
1626
+ store[{"hashkey3"=>"hashkey4"}].should == false
1021
1627
  sleep 3
1022
- store[Value.new(:objkey2)].should == nil
1628
+ store[{"hashkey3"=>"hashkey4"}].should == nil
1629
+ end
1630
+
1631
+ it 'should support updating the expiration time in key?' do
1632
+ store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1633
+ store[{"hashkey3"=>"hashkey4"}].should == false
1634
+ sleep 1
1635
+ store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
1636
+ store[{"hashkey3"=>"hashkey4"}].should == false
1637
+ sleep 1
1638
+ store[{"hashkey3"=>"hashkey4"}].should == false
1639
+ sleep 3
1640
+ store[{"hashkey3"=>"hashkey4"}].should == nil
1023
1641
  end
1024
1642
 
1025
1643
  it 'should support updating the expiration time in fetch' do
1026
- store.store(Value.new(:objkey1), {"hashval1"=>"hashval2"}, :expires => 2)
1027
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
1644
+ store.store({"hashkey1"=>"hashkey2"}, true, :expires => 2)
1645
+ store[{"hashkey1"=>"hashkey2"}].should == true
1028
1646
  sleep 1
1029
- store.fetch(Value.new(:objkey1), nil, :expires => 3).should == {"hashval1"=>"hashval2"}
1030
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
1647
+ store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == true
1648
+ store[{"hashkey1"=>"hashkey2"}].should == true
1031
1649
  sleep 1
1032
- store[Value.new(:objkey1)].should == {"hashval1"=>"hashval2"}
1650
+ store[{"hashkey1"=>"hashkey2"}].should == true
1033
1651
  sleep 3
1034
- store[Value.new(:objkey1)].should == nil
1652
+ store[{"hashkey1"=>"hashkey2"}].should == nil
1035
1653
  end
1036
1654
 
1037
1655
  it 'should respect expires in delete' do
1038
- store.store(Value.new(:objkey2), {"hashval3"=>"hashval4"}, :expires => 2)
1039
- store[Value.new(:objkey2)].should == {"hashval3"=>"hashval4"}
1656
+ store.store({"hashkey3"=>"hashkey4"}, false, :expires => 2)
1657
+ store[{"hashkey3"=>"hashkey4"}].should == false
1040
1658
  sleep 1
1041
- store[Value.new(:objkey2)].should == {"hashval3"=>"hashval4"}
1659
+ store[{"hashkey3"=>"hashkey4"}].should == false
1042
1660
  sleep 2
1043
- store.delete(Value.new(:objkey2)).should == nil
1661
+ store.delete({"hashkey3"=>"hashkey4"}).should == nil
1044
1662
  end
1045
1663
  end
1046
1664
 
@@ -1109,6 +1727,8 @@ shared_examples_for 'store_hashkey_stringvalue' do
1109
1727
  it "returns true from key? if a Hash key is available" do
1110
1728
  store[{"hashkey1"=>"hashkey2"}] = "strval1"
1111
1729
  store.key?({"hashkey1"=>"hashkey2"}).should == true
1730
+ store[{"hashkey3"=>"hashkey4"}] = "strval2"
1731
+ store.key?({"hashkey3"=>"hashkey4"}).should == true
1112
1732
  end
1113
1733
 
1114
1734
  it "stores String values with Hash keys with #store" do
@@ -1196,6 +1816,18 @@ shared_examples_for 'expires_hashkey_stringvalue' do
1196
1816
  store[{"hashkey3"=>"hashkey4"}].should == nil
1197
1817
  end
1198
1818
 
1819
+ it 'should support updating the expiration time in key?' do
1820
+ store.store({"hashkey3"=>"hashkey4"}, "strval2", :expires => 2)
1821
+ store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1822
+ sleep 1
1823
+ store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
1824
+ store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1825
+ sleep 1
1826
+ store[{"hashkey3"=>"hashkey4"}].should == "strval2"
1827
+ sleep 3
1828
+ store[{"hashkey3"=>"hashkey4"}].should == nil
1829
+ end
1830
+
1199
1831
  it 'should support updating the expiration time in fetch' do
1200
1832
  store.store({"hashkey1"=>"hashkey2"}, "strval1", :expires => 2)
1201
1833
  store[{"hashkey1"=>"hashkey2"}].should == "strval1"
@@ -1218,16 +1850,16 @@ shared_examples_for 'expires_hashkey_stringvalue' do
1218
1850
  end
1219
1851
  end
1220
1852
 
1221
- #################### null_hashkey_objectvalue ####################
1853
+ #################### null_hashkey_hashvalue ####################
1222
1854
 
1223
- shared_examples_for 'null_hashkey_objectvalue' do
1855
+ shared_examples_for 'null_hashkey_hashvalue' do
1224
1856
  it "reads from keys that are Hashs like a Hash" do
1225
1857
  store[{"hashkey1"=>"hashkey2"}].should == nil
1226
1858
  store.load({"hashkey1"=>"hashkey2"}).should == nil
1227
1859
  end
1228
1860
 
1229
- it "guarantees that the same Object value is returned when setting a Hash key" do
1230
- value = Value.new(:objval1)
1861
+ it "guarantees that the same Hash value is returned when setting a Hash key" do
1862
+ value = {"hashval1"=>["array1", 1]}
1231
1863
  (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
1232
1864
  end
1233
1865
 
@@ -1240,20 +1872,20 @@ shared_examples_for 'null_hashkey_objectvalue' do
1240
1872
  end
1241
1873
 
1242
1874
  it "removes all Hash keys from the store with clear" do
1243
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1244
- store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
1875
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1876
+ store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1245
1877
  store.clear.should equal(store)
1246
1878
  store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1247
1879
  store.key?({"hashkey3"=>"hashkey4"}).should_not == true
1248
1880
  end
1249
1881
 
1250
1882
  it "fetches a Hash key with a default value with fetch, if the key is not available" do
1251
- store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval1)).should == Value.new(:objval1)
1883
+ store.fetch({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}).should == {"hashval1"=>["array1", 1]}
1252
1884
  end
1253
1885
 
1254
1886
  it "fetches a Hash key with a block with fetch, if the key is not available" do
1255
1887
  key = {"hashkey1"=>"hashkey2"}
1256
- value = Value.new(:objval1)
1888
+ value = {"hashval1"=>["array1", 1]}
1257
1889
  store.fetch(key) do |k|
1258
1890
  k.should equal(key)
1259
1891
  value
@@ -1267,90 +1899,92 @@ shared_examples_for 'null_hashkey_objectvalue' do
1267
1899
  store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1268
1900
  store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
1269
1901
  store.clear(:option5 => 5).should equal(store)
1270
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
1902
+ store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :option6 => 6).should == {"hashval1"=>["array1", 1]}
1271
1903
  end
1272
1904
  end
1273
1905
 
1274
- #################### store_hashkey_objectvalue ####################
1906
+ #################### store_hashkey_hashvalue ####################
1275
1907
 
1276
- shared_examples_for 'store_hashkey_objectvalue' do
1277
- it "writes Object values to keys that are Hashs like a Hash" do
1278
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1279
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1280
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1908
+ shared_examples_for 'store_hashkey_hashvalue' do
1909
+ it "writes Hash values to keys that are Hashs like a Hash" do
1910
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1911
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1912
+ store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1281
1913
  end
1282
1914
 
1283
1915
  it "returns true from key? if a Hash key is available" do
1284
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1916
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1285
1917
  store.key?({"hashkey1"=>"hashkey2"}).should == true
1918
+ store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1919
+ store.key?({"hashkey3"=>"hashkey4"}).should == true
1286
1920
  end
1287
1921
 
1288
- it "stores Object values with Hash keys with #store" do
1289
- value = Value.new(:objval1)
1922
+ it "stores Hash values with Hash keys with #store" do
1923
+ value = {"hashval1"=>["array1", 1]}
1290
1924
  store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1291
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1292
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1925
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1926
+ store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1293
1927
  end
1294
1928
 
1295
- it "removes and returns a Object element with a Hash key from the backing store via delete if it exists" do
1296
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1297
- store.delete({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1929
+ it "removes and returns a Hash element with a Hash key from the backing store via delete if it exists" do
1930
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1931
+ store.delete({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1298
1932
  store.key?({"hashkey1"=>"hashkey2"}).should == false
1299
1933
  end
1300
1934
 
1301
- it "overwrites existing Object values with Hash" do
1302
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1303
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1304
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval2)
1305
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval2)
1935
+ it "overwrites existing Hash values with Hash" do
1936
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1937
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1938
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval3"=>["array2", {"hashval4"=>42}]}
1939
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1306
1940
  end
1307
1941
 
1308
1942
  it "does not run the block if the Hash key is available" do
1309
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1943
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1310
1944
  unaltered = "unaltered"
1311
1945
  store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
1312
1946
  unaltered.should == "unaltered"
1313
1947
  end
1314
1948
 
1315
1949
  it "fetches a Hash key with a default value with fetch, if the key is available" do
1316
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1317
- store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval2)).should == Value.new(:objval1)
1950
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1951
+ store.fetch({"hashkey1"=>"hashkey2"}, {"hashval3"=>["array2", {"hashval4"=>42}]}).should == {"hashval1"=>["array1", 1]}
1318
1952
  end
1319
1953
  end
1320
1954
 
1321
- #################### returndifferent_hashkey_objectvalue ####################
1955
+ #################### returndifferent_hashkey_hashvalue ####################
1322
1956
 
1323
- shared_examples_for 'returndifferent_hashkey_objectvalue' do
1324
- it "guarantees that a different Object value is retrieved from the Hash key" do
1325
- value = Value.new(:objval1)
1326
- store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1327
- store[{"hashkey1"=>"hashkey2"}].should_not be_equal(Value.new(:objval1))
1957
+ shared_examples_for 'returndifferent_hashkey_hashvalue' do
1958
+ it "guarantees that a different Hash value is retrieved from the Hash key" do
1959
+ value = {"hashval1"=>["array1", 1]}
1960
+ store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>["array1", 1]}
1961
+ store[{"hashkey1"=>"hashkey2"}].should_not be_equal({"hashval1"=>["array1", 1]})
1328
1962
  end
1329
1963
  end
1330
1964
 
1331
- #################### expires_hashkey_objectvalue ####################
1965
+ #################### expires_hashkey_hashvalue ####################
1332
1966
 
1333
- shared_examples_for 'expires_hashkey_objectvalue' do
1967
+ shared_examples_for 'expires_hashkey_hashvalue' do
1334
1968
  it 'should support expires on store and #[]' do
1335
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
1336
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1969
+ store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1970
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1337
1971
  sleep 1
1338
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1972
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1339
1973
  sleep 2
1340
1974
  store[{"hashkey1"=>"hashkey2"}].should == nil
1341
1975
  end
1342
1976
 
1343
1977
  it 'should support expires on store and load' do
1344
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
1345
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1978
+ store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1979
+ store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1346
1980
  sleep 1
1347
- store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1981
+ store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>["array1", 1]}
1348
1982
  sleep 2
1349
1983
  store.load({"hashkey1"=>"hashkey2"}).should == nil
1350
1984
  end
1351
1985
 
1352
1986
  it 'should support expires on store and key?' do
1353
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
1987
+ store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
1354
1988
  store.key?({"hashkey1"=>"hashkey2"}).should == true
1355
1989
  sleep 1
1356
1990
  store.key?({"hashkey1"=>"hashkey2"}).should == true
@@ -1359,49 +1993,61 @@ shared_examples_for 'expires_hashkey_objectvalue' do
1359
1993
  end
1360
1994
 
1361
1995
  it 'should support updating the expiration time in load' do
1362
- store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
1363
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1996
+ store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
1997
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1364
1998
  sleep 1
1365
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == Value.new(:objval2)
1366
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1999
+ store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2000
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1367
2001
  sleep 1
1368
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2002
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2003
+ sleep 3
2004
+ store[{"hashkey3"=>"hashkey4"}].should == nil
2005
+ end
2006
+
2007
+ it 'should support updating the expiration time in key?' do
2008
+ store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
2009
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2010
+ sleep 1
2011
+ store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
2012
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
2013
+ sleep 1
2014
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1369
2015
  sleep 3
1370
2016
  store[{"hashkey3"=>"hashkey4"}].should == nil
1371
2017
  end
1372
2018
 
1373
2019
  it 'should support updating the expiration time in fetch' do
1374
- store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
1375
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2020
+ store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>["array1", 1]}, :expires => 2)
2021
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1376
2022
  sleep 1
1377
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == Value.new(:objval1)
1378
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2023
+ store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == {"hashval1"=>["array1", 1]}
2024
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1379
2025
  sleep 1
1380
- store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2026
+ store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>["array1", 1]}
1381
2027
  sleep 3
1382
2028
  store[{"hashkey1"=>"hashkey2"}].should == nil
1383
2029
  end
1384
2030
 
1385
2031
  it 'should respect expires in delete' do
1386
- store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
1387
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2032
+ store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>["array2", {"hashval4"=>42}]}, :expires => 2)
2033
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1388
2034
  sleep 1
1389
- store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2035
+ store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>["array2", {"hashval4"=>42}]}
1390
2036
  sleep 2
1391
2037
  store.delete({"hashkey3"=>"hashkey4"}).should == nil
1392
2038
  end
1393
2039
  end
1394
2040
 
1395
- #################### null_hashkey_hashvalue ####################
2041
+ #################### null_hashkey_objectvalue ####################
1396
2042
 
1397
- shared_examples_for 'null_hashkey_hashvalue' do
2043
+ shared_examples_for 'null_hashkey_objectvalue' do
1398
2044
  it "reads from keys that are Hashs like a Hash" do
1399
2045
  store[{"hashkey1"=>"hashkey2"}].should == nil
1400
2046
  store.load({"hashkey1"=>"hashkey2"}).should == nil
1401
2047
  end
1402
2048
 
1403
- it "guarantees that the same Hash value is returned when setting a Hash key" do
1404
- value = {"hashval1"=>"hashval2"}
2049
+ it "guarantees that the same Object value is returned when setting a Hash key" do
2050
+ value = Value.new(:objval1)
1405
2051
  (store[{"hashkey1"=>"hashkey2"}] = value).should equal(value)
1406
2052
  end
1407
2053
 
@@ -1414,20 +2060,20 @@ shared_examples_for 'null_hashkey_hashvalue' do
1414
2060
  end
1415
2061
 
1416
2062
  it "removes all Hash keys from the store with clear" do
1417
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1418
- store[{"hashkey3"=>"hashkey4"}] = {"hashval3"=>"hashval4"}
2063
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2064
+ store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
1419
2065
  store.clear.should equal(store)
1420
2066
  store.key?({"hashkey1"=>"hashkey2"}).should_not == true
1421
2067
  store.key?({"hashkey3"=>"hashkey4"}).should_not == true
1422
2068
  end
1423
2069
 
1424
2070
  it "fetches a Hash key with a default value with fetch, if the key is not available" do
1425
- store.fetch({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}).should == {"hashval1"=>"hashval2"}
2071
+ store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval1)).should == Value.new(:objval1)
1426
2072
  end
1427
2073
 
1428
2074
  it "fetches a Hash key with a block with fetch, if the key is not available" do
1429
2075
  key = {"hashkey1"=>"hashkey2"}
1430
- value = {"hashval1"=>"hashval2"}
2076
+ value = Value.new(:objval1)
1431
2077
  store.fetch(key) do |k|
1432
2078
  k.should equal(key)
1433
2079
  value
@@ -1441,90 +2087,92 @@ shared_examples_for 'null_hashkey_hashvalue' do
1441
2087
  store.fetch({"hashkey1"=>"hashkey2"}, :option3 => 3) { 42 }.should == 42
1442
2088
  store.delete({"hashkey1"=>"hashkey2"}, :option4 => 4).should == nil
1443
2089
  store.clear(:option5 => 5).should equal(store)
1444
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}, :option6 => 6).should == {"hashval1"=>"hashval2"}
2090
+ store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :option6 => 6).should == Value.new(:objval1)
1445
2091
  end
1446
2092
  end
1447
2093
 
1448
- #################### store_hashkey_hashvalue ####################
2094
+ #################### store_hashkey_objectvalue ####################
1449
2095
 
1450
- shared_examples_for 'store_hashkey_hashvalue' do
1451
- it "writes Hash values to keys that are Hashs like a Hash" do
1452
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1453
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
1454
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>"hashval2"}
2096
+ shared_examples_for 'store_hashkey_objectvalue' do
2097
+ it "writes Object values to keys that are Hashs like a Hash" do
2098
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2099
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2100
+ store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1455
2101
  end
1456
2102
 
1457
2103
  it "returns true from key? if a Hash key is available" do
1458
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
2104
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1459
2105
  store.key?({"hashkey1"=>"hashkey2"}).should == true
2106
+ store[{"hashkey3"=>"hashkey4"}] = Value.new(:objval2)
2107
+ store.key?({"hashkey3"=>"hashkey4"}).should == true
1460
2108
  end
1461
2109
 
1462
- it "stores Hash values with Hash keys with #store" do
1463
- value = {"hashval1"=>"hashval2"}
2110
+ it "stores Object values with Hash keys with #store" do
2111
+ value = Value.new(:objval1)
1464
2112
  store.store({"hashkey1"=>"hashkey2"}, value).should equal(value)
1465
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
1466
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>"hashval2"}
2113
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2114
+ store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1467
2115
  end
1468
2116
 
1469
- it "removes and returns a Hash element with a Hash key from the backing store via delete if it exists" do
1470
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1471
- store.delete({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>"hashval2"}
2117
+ it "removes and returns a Object element with a Hash key from the backing store via delete if it exists" do
2118
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2119
+ store.delete({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1472
2120
  store.key?({"hashkey1"=>"hashkey2"}).should == false
1473
2121
  end
1474
2122
 
1475
- it "overwrites existing Hash values with Hash" do
1476
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1477
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
1478
- store[{"hashkey1"=>"hashkey2"}] = {"hashval3"=>"hashval4"}
1479
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval3"=>"hashval4"}
2123
+ it "overwrites existing Object values with Hash" do
2124
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2125
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
2126
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval2)
2127
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval2)
1480
2128
  end
1481
2129
 
1482
2130
  it "does not run the block if the Hash key is available" do
1483
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
2131
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
1484
2132
  unaltered = "unaltered"
1485
2133
  store.fetch({"hashkey1"=>"hashkey2"}) { unaltered = "altered" }
1486
2134
  unaltered.should == "unaltered"
1487
2135
  end
1488
2136
 
1489
2137
  it "fetches a Hash key with a default value with fetch, if the key is available" do
1490
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1491
- store.fetch({"hashkey1"=>"hashkey2"}, {"hashval3"=>"hashval4"}).should == {"hashval1"=>"hashval2"}
2138
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2139
+ store.fetch({"hashkey1"=>"hashkey2"}, Value.new(:objval2)).should == Value.new(:objval1)
1492
2140
  end
1493
2141
  end
1494
2142
 
1495
- #################### returndifferent_hashkey_hashvalue ####################
2143
+ #################### returndifferent_hashkey_objectvalue ####################
1496
2144
 
1497
- shared_examples_for 'returndifferent_hashkey_hashvalue' do
1498
- it "guarantees that a different Hash value is retrieved from the Hash key" do
1499
- value = {"hashval1"=>"hashval2"}
1500
- store[{"hashkey1"=>"hashkey2"}] = {"hashval1"=>"hashval2"}
1501
- store[{"hashkey1"=>"hashkey2"}].should_not be_equal({"hashval1"=>"hashval2"})
2145
+ shared_examples_for 'returndifferent_hashkey_objectvalue' do
2146
+ it "guarantees that a different Object value is retrieved from the Hash key" do
2147
+ value = Value.new(:objval1)
2148
+ store[{"hashkey1"=>"hashkey2"}] = Value.new(:objval1)
2149
+ store[{"hashkey1"=>"hashkey2"}].should_not be_equal(Value.new(:objval1))
1502
2150
  end
1503
2151
  end
1504
2152
 
1505
- #################### expires_hashkey_hashvalue ####################
2153
+ #################### expires_hashkey_objectvalue ####################
1506
2154
 
1507
- shared_examples_for 'expires_hashkey_hashvalue' do
2155
+ shared_examples_for 'expires_hashkey_objectvalue' do
1508
2156
  it 'should support expires on store and #[]' do
1509
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}, :expires => 2)
1510
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
2157
+ store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2158
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1511
2159
  sleep 1
1512
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
2160
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1513
2161
  sleep 2
1514
2162
  store[{"hashkey1"=>"hashkey2"}].should == nil
1515
2163
  end
1516
2164
 
1517
2165
  it 'should support expires on store and load' do
1518
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}, :expires => 2)
1519
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>"hashval2"}
2166
+ store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2167
+ store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1520
2168
  sleep 1
1521
- store.load({"hashkey1"=>"hashkey2"}).should == {"hashval1"=>"hashval2"}
2169
+ store.load({"hashkey1"=>"hashkey2"}).should == Value.new(:objval1)
1522
2170
  sleep 2
1523
2171
  store.load({"hashkey1"=>"hashkey2"}).should == nil
1524
2172
  end
1525
2173
 
1526
2174
  it 'should support expires on store and key?' do
1527
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}, :expires => 2)
2175
+ store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
1528
2176
  store.key?({"hashkey1"=>"hashkey2"}).should == true
1529
2177
  sleep 1
1530
2178
  store.key?({"hashkey1"=>"hashkey2"}).should == true
@@ -1533,34 +2181,46 @@ shared_examples_for 'expires_hashkey_hashvalue' do
1533
2181
  end
1534
2182
 
1535
2183
  it 'should support updating the expiration time in load' do
1536
- store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>"hashval4"}, :expires => 2)
1537
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>"hashval4"}
2184
+ store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2185
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2186
+ sleep 1
2187
+ store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == Value.new(:objval2)
2188
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2189
+ sleep 1
2190
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
2191
+ sleep 3
2192
+ store[{"hashkey3"=>"hashkey4"}].should == nil
2193
+ end
2194
+
2195
+ it 'should support updating the expiration time in key?' do
2196
+ store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2197
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1538
2198
  sleep 1
1539
- store.load({"hashkey3"=>"hashkey4"}, :expires => 3).should == {"hashval3"=>"hashval4"}
1540
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>"hashval4"}
2199
+ store.key?({"hashkey3"=>"hashkey4"}, :expires => 3).should be_true
2200
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1541
2201
  sleep 1
1542
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>"hashval4"}
2202
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1543
2203
  sleep 3
1544
2204
  store[{"hashkey3"=>"hashkey4"}].should == nil
1545
2205
  end
1546
2206
 
1547
2207
  it 'should support updating the expiration time in fetch' do
1548
- store.store({"hashkey1"=>"hashkey2"}, {"hashval1"=>"hashval2"}, :expires => 2)
1549
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
2208
+ store.store({"hashkey1"=>"hashkey2"}, Value.new(:objval1), :expires => 2)
2209
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1550
2210
  sleep 1
1551
- store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == {"hashval1"=>"hashval2"}
1552
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
2211
+ store.fetch({"hashkey1"=>"hashkey2"}, nil, :expires => 3).should == Value.new(:objval1)
2212
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1553
2213
  sleep 1
1554
- store[{"hashkey1"=>"hashkey2"}].should == {"hashval1"=>"hashval2"}
2214
+ store[{"hashkey1"=>"hashkey2"}].should == Value.new(:objval1)
1555
2215
  sleep 3
1556
2216
  store[{"hashkey1"=>"hashkey2"}].should == nil
1557
2217
  end
1558
2218
 
1559
2219
  it 'should respect expires in delete' do
1560
- store.store({"hashkey3"=>"hashkey4"}, {"hashval3"=>"hashval4"}, :expires => 2)
1561
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>"hashval4"}
2220
+ store.store({"hashkey3"=>"hashkey4"}, Value.new(:objval2), :expires => 2)
2221
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1562
2222
  sleep 1
1563
- store[{"hashkey3"=>"hashkey4"}].should == {"hashval3"=>"hashval4"}
2223
+ store[{"hashkey3"=>"hashkey4"}].should == Value.new(:objval2)
1564
2224
  sleep 2
1565
2225
  store.delete({"hashkey3"=>"hashkey4"}).should == nil
1566
2226
  end
@@ -1569,46 +2229,56 @@ end
1569
2229
  #################### marshallable_key ####################
1570
2230
 
1571
2231
  shared_examples_for 'marshallable_key' do
1572
- it "refuses to #[] from keys that cannot be marshalled" do
2232
+ it 'refuses to #[] from keys that cannot be marshalled' do
1573
2233
  expect do
1574
2234
  store[Struct.new(:foo).new(:bar)]
1575
2235
  end.to raise_error(marshal_error)
1576
2236
  end
1577
2237
 
1578
- it "refuses to load from keys that cannot be marshalled" do
2238
+ it 'refuses to load from keys that cannot be marshalled' do
1579
2239
  expect do
1580
2240
  store.load(Struct.new(:foo).new(:bar))
1581
2241
  end.to raise_error(marshal_error)
1582
2242
  end
1583
2243
 
1584
- it "refuses to fetch from keys that cannot be marshalled" do
2244
+ it 'refuses to fetch from keys that cannot be marshalled' do
1585
2245
  expect do
1586
2246
  store.fetch(Struct.new(:foo).new(:bar), true)
1587
2247
  end.to raise_error(marshal_error)
1588
2248
  end
1589
2249
 
1590
- it "refuses to #[]= to keys that cannot be marshalled" do
2250
+ it 'refuses to #[]= to keys that cannot be marshalled' do
1591
2251
  expect do
1592
2252
  store[Struct.new(:foo).new(:bar)] = 'value'
1593
2253
  end.to raise_error(marshal_error)
1594
2254
  end
1595
2255
 
1596
- it "refuses to store to keys that cannot be marshalled" do
2256
+ it 'refuses to store to keys that cannot be marshalled' do
1597
2257
  expect do
1598
2258
  store.store Struct.new(:foo).new(:bar), 'value'
1599
2259
  end.to raise_error(marshal_error)
1600
2260
  end
1601
2261
 
1602
- it "refuses to check for key? if the key cannot be marshalled" do
2262
+ it 'refuses to check for key? if the key cannot be marshalled' do
1603
2263
  expect do
1604
2264
  store.key? Struct.new(:foo).new(:bar)
1605
2265
  end.to raise_error(marshal_error)
1606
2266
  end
1607
2267
 
1608
- it "refuses to delete a key if the key cannot be marshalled" do
2268
+ it 'refuses to delete a key if the key cannot be marshalled' do
1609
2269
  expect do
1610
2270
  store.delete Struct.new(:foo).new(:bar)
1611
2271
  end.to raise_error(marshal_error)
1612
2272
  end
1613
2273
  end
1614
2274
 
2275
+ #################### marshallable_value ####################
2276
+
2277
+ shared_examples_for 'marshallable_value' do
2278
+ it 'refuses to store values that cannot be marshalled' do
2279
+ expect do
2280
+ store.store 'key', Struct.new(:foo).new(:bar)
2281
+ end.to raise_error(marshal_error)
2282
+ end
2283
+ end
2284
+