hoodoo 1.14.0 → 1.15.0

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.
@@ -307,21 +307,42 @@ def spec_helper_http( path:,
307
307
  return http.request( request )
308
308
  end
309
309
 
310
+ # Stub out Memcached with a TransientStore mock client instead. Call via
311
+ # a "before :each" block.
312
+ #
313
+ def spec_helper_use_mock_memcached
314
+ Hoodoo::TransientStore::Mocks::DalliClient.reset()
315
+
316
+ allow( Dalli::Client ).to(
317
+ receive( :new ).
318
+ and_return( Hoodoo::TransientStore::Mocks::DalliClient.new )
319
+ )
320
+ end
321
+
322
+ # Stub out Redis with a TransientStore mock client instead. Call via
323
+ # a "before :each" block.
324
+ #
325
+ def spec_helper_use_mock_redis
326
+ Hoodoo::TransientStore::Mocks::Redis.reset()
327
+
328
+ allow( Redis ).to(
329
+ receive( :new ).
330
+ and_return( Hoodoo::TransientStore::Mocks::Redis.new )
331
+ )
332
+ end
333
+
310
334
  # Add support to count the database queries run within a
311
335
  # given block. Returns the number of queries run.
312
336
  #
313
- def count_database_calls_in( &block )
337
+ def spec_helper_count_database_calls_in( &block )
314
338
  count = 0
339
+ cb = ->( name, start_time, finish_time, id, query ) {
315
340
 
316
- cb = ->(name, start_time, finish_time, id, query) {
317
- # only bump the count if the database call is not to
318
- # CACHE or SCHEMA
319
- unless [ 'CACHE', 'SCHEMA' ].include?( query[:name] )
320
- count += 1
321
- end
341
+ # Only bump the count if the database call is not to CACHE or SCHEMA
342
+ #
343
+ count += 1 unless [ 'CACHE', 'SCHEMA' ].include?( query[ :name ] )
322
344
  }
323
345
 
324
- ActiveSupport::Notifications.subscribed( cb, "sql.active_record", &block )
325
-
326
- count
346
+ ActiveSupport::Notifications.subscribed( cb, 'sql.active_record', &block )
347
+ return count
327
348
  end
@@ -25,19 +25,9 @@ describe Hoodoo::TransientStore::MemcachedRedisMirror do
25
25
 
26
26
  # Use pure mock back-ends behind the Memcached and Redis abstraction
27
27
  # layers; real back-end tests are done for them in their unit tests.
28
-
29
- Hoodoo::TransientStore::Mocks::DalliClient.reset()
30
- Hoodoo::TransientStore::Mocks::Redis.reset()
31
-
32
- allow( Dalli::Client ).to(
33
- receive( :new ).
34
- and_return( Hoodoo::TransientStore::Mocks::DalliClient.new )
35
- )
36
-
37
- allow( Redis ).to(
38
- receive( :new ).
39
- and_return( Hoodoo::TransientStore::Mocks::Redis.new )
40
- )
28
+ #
29
+ spec_helper_use_mock_memcached()
30
+ spec_helper_use_mock_redis()
41
31
 
42
32
  @instance = Hoodoo::TransientStore::MemcachedRedisMirror.new(
43
33
  storage_host_uri: @storage_engine_uri,
@@ -138,6 +138,21 @@ describe Hoodoo::TransientStore::Memcached do
138
138
  @ttl = 120
139
139
  end
140
140
 
141
+ context '#client' do
142
+ it 'returns the Dalli::Client in use' do
143
+ expect( [
144
+ @mock_dalli_client_instance.class,
145
+ ::Dalli::Client
146
+ ] ).to include( @instance.client.class )
147
+ end
148
+
149
+ it 'sets the Dalli::Client in use' do
150
+ new_client = Hoodoo::TransientStore::Mocks::DalliClient.new
151
+ @instance.client = new_client
152
+ expect( @instance.client ).to eq( new_client )
153
+ end
154
+ end
155
+
141
156
  context '#set' do
142
157
  it 'sets' do
143
158
  expect_dalli_client( backend ).to receive( :set ).with( @key, @payload, @ttl ).and_call_original()
@@ -300,7 +300,7 @@ describe Hoodoo::TransientStore do
300
300
  expect( @store.get( key: random_key ) ).to be_nil
301
301
  end
302
302
 
303
- it 'consumes exceptions' do
303
+ it 'consumes exceptions by default' do
304
304
  expect_any_instance_of( TestTransientStore ).to receive( :get ) do
305
305
  raise 'Hello world'
306
306
  end
@@ -308,6 +308,16 @@ describe Hoodoo::TransientStore do
308
308
  expect( @store.get( key: @key ) ).to be_nil
309
309
  end
310
310
 
311
+ it 'throws exceptions if asked' do
312
+ expect_any_instance_of( TestTransientStore ).to receive( :get ) do
313
+ raise 'Hello world'
314
+ end
315
+
316
+ expect {
317
+ @store.get( key: @key, allow_throw: true )
318
+ }.to raise_error( RuntimeError, 'Hello world' )
319
+ end
320
+
311
321
  context 'key normalisation' do
312
322
  it 'normalises the key' do
313
323
  key = :some_symbol
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli