falls_back_on 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ module FallsBackOn
23
23
  end
24
24
 
25
25
  def attrs
26
+ return {} unless Storage.instance[parent].is_a?(::Hash)
26
27
  Storage.instance[parent].inject({}) do |memo, (k, v)|
27
28
  memo[k] = calculate k
28
29
  memo
@@ -1,3 +1,3 @@
1
1
  module FallsBackOn
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -20,12 +20,12 @@ rescue ArgumentError
20
20
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
21
21
  end
22
22
 
23
- my_client = Memcached.new
24
- CacheMethod.config.storage = my_client
25
- LockMethod.config.storage = my_client
23
+ $my_client = Memcached.new
26
24
 
27
25
  class Test::Unit::TestCase
28
26
  def setup
27
+ CacheMethod.config.storage = $my_client
28
+ LockMethod.config.storage = $my_client
29
29
  CacheMethod.config.storage.flush
30
30
  LockMethod.config.storage.flush
31
31
  @old_abort_on_exception = Thread.abort_on_exception
@@ -38,6 +38,13 @@ class Car3
38
38
  falls_back_on :long_running_calculation => lambda { sleep 3 }
39
39
  end
40
40
 
41
+ class Car4
42
+ attr_accessor :fuel
43
+ def ==(other)
44
+ self.fuel == other.fuel
45
+ end
46
+ end
47
+
41
48
  class TestFallsBackOn < Test::Unit::TestCase
42
49
  def test_fallback
43
50
  assert_equal 'gasoline', Car1.fallback.fuel
@@ -96,6 +103,10 @@ class TestFallsBackOn < Test::Unit::TestCase
96
103
  end
97
104
  end
98
105
 
106
+ # 3 seconds every time.
107
+ # start it, wait a second, clear fallbacks (and therefore any locks)
108
+ # you would expect it to completely restart, taking another 3 seconds
109
+ # so it will time out after 4 seconds
99
110
  assert_raises(Timeout::Error) do
100
111
  Timeout.timeout(4) do
101
112
  blocker = Thread.new { Car3.fallback.long_running_calculation }
@@ -105,4 +116,14 @@ class TestFallsBackOn < Test::Unit::TestCase
105
116
  end
106
117
  end
107
118
  end
119
+
120
+ def test_no_memcached
121
+ CacheMethod.config.storage = nil
122
+ LockMethod.config.storage = nil
123
+ assert_equal 5.5, Car2.fallback.efficiency
124
+ end
125
+
126
+ def test_no_definition
127
+ assert_equal Car4.new, Car4.fallback
128
+ end
108
129
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falls_back_on
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere