frivol 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/frivol.gemspec +1 -1
- data/test/fake_redis.rb +7 -2
- data/test/test_frivol.rb +16 -3
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.2
|
data/frivol.gemspec
CHANGED
data/test/fake_redis.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
class Redis
|
|
2
2
|
def initialize(config)
|
|
3
3
|
@storage = {}
|
|
4
|
+
@expires = Hash.new(nil)
|
|
4
5
|
end
|
|
5
6
|
|
|
6
7
|
def [](key)
|
|
7
8
|
# puts "retrieve #{key}"
|
|
9
|
+
return nil if !@expires[key].nil? && @expires[key] < Time.now
|
|
8
10
|
@storage[key]
|
|
9
11
|
end
|
|
10
12
|
|
|
@@ -14,7 +16,10 @@ class Redis
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def expire(key, time)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
@expires[key] = Time.now + time
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def flush_db
|
|
23
|
+
@storage = {}
|
|
19
24
|
end
|
|
20
25
|
end
|
data/test/test_frivol.rb
CHANGED
|
@@ -2,8 +2,12 @@ require 'helper'
|
|
|
2
2
|
|
|
3
3
|
class TestFrivol < Test::Unit::TestCase
|
|
4
4
|
def setup
|
|
5
|
-
fake_redis
|
|
6
|
-
Frivol::Config.redis_config = {}
|
|
5
|
+
fake_redis # Comment out this line to test against a real live Redis
|
|
6
|
+
Frivol::Config.redis_config = {} # This will connect to a default Redis setup, otherwise set to { :host => "localhost", :port => 6379 }, for example
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def teardown
|
|
10
|
+
Frivol::Config.redis.flush_db
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
should "have a default storage key made up of the class name and id" do
|
|
@@ -51,7 +55,7 @@ class TestFrivol < Test::Unit::TestCase
|
|
|
51
55
|
|
|
52
56
|
t = DefaultsTestClass.new
|
|
53
57
|
t.save
|
|
54
|
-
assert_equal [ "value", "value2" ], t.load
|
|
58
|
+
assert_equal [ "value", "value2" ], t.load.sort
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
should "be able to override the key method" do
|
|
@@ -95,6 +99,15 @@ class TestFrivol < Test::Unit::TestCase
|
|
|
95
99
|
t.save
|
|
96
100
|
end
|
|
97
101
|
|
|
102
|
+
should "expires should not throw nasty errors" do
|
|
103
|
+
t = TestClass.new
|
|
104
|
+
t.save
|
|
105
|
+
t.expire_storage 0.5
|
|
106
|
+
sleep 1
|
|
107
|
+
t = TestClass.new # Get a fresh instance so that the @frivol_hash is empty
|
|
108
|
+
assert_equal "junk", t.load
|
|
109
|
+
end
|
|
110
|
+
|
|
98
111
|
should "be able to include in other classes with storage expiry" do
|
|
99
112
|
class BlankTestClass
|
|
100
113
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: frivol
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.1.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Marc Heiligers
|