macmillan-utils 1.0.22 → 1.0.23
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42d0f124530989afb7adc2d6f009fc4a0c597e35
|
4
|
+
data.tar.gz: 3ea996731cb2a41a629a776027eb32c9f6184d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d6b78bd871148f5373b17fa53887abcd9045e41d5ab9de1784d0d1c9dbe55056650a8ae57bb0981dcd7caddd2e2be7cf6bef8d54e11d448839ac4e190d28a28
|
7
|
+
data.tar.gz: 4bdbe4cd33a6a30308bcca4750c3f594136f80f28956f665fe840f800a477f1a2f28e5d2f32ca9d738638b8c093fe3e2390a2f3ad37325273b3424f79d563fb9
|
@@ -7,17 +7,12 @@ module Macmillan
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def lookup(key)
|
10
|
-
value = nil
|
11
|
-
|
12
10
|
@backends.each do |backend|
|
13
|
-
break if value
|
14
11
|
result = backend.get(key)
|
15
|
-
|
12
|
+
return result.value unless result.is_a?(KeyNotFound)
|
16
13
|
end
|
17
14
|
|
18
|
-
fail KeyNotFoundError.new("Cannot find a settings value for #{key}")
|
19
|
-
|
20
|
-
value
|
15
|
+
fail KeyNotFoundError.new("Cannot find a settings value for #{key}")
|
21
16
|
end
|
22
17
|
|
23
18
|
# Backwards compatibility: in the past this has been used like a Hash
|
@@ -32,7 +32,9 @@ describe Macmillan::Utils::Logger::Factory do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'allows you to configure the log target' do
|
35
|
-
|
35
|
+
logger = double('logger').as_null_object
|
36
|
+
expect(Logger).to receive(:new).with('foo.log').and_return(logger)
|
37
|
+
|
36
38
|
Macmillan::Utils::Logger::Factory.build_logger(:logger, target: 'foo.log')
|
37
39
|
end
|
38
40
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Macmillan::Utils::Settings::Lookup do
|
4
|
+
let(:backend1) { double('Backend One') }
|
5
|
+
let(:backend2) { double('Backend Two') }
|
6
|
+
|
7
|
+
subject { described_class.new([backend1, backend2]) }
|
8
|
+
|
9
|
+
it 'returns the first value it finds' do
|
10
|
+
true_value = Macmillan::Utils::Settings::Value.new('is_craigw_trolling_us', true, backend1, 'is_craigw_trolling_us')
|
11
|
+
allow(backend1).to receive(:get).with('is_craigw_trolling_us').and_return(true_value)
|
12
|
+
|
13
|
+
expect(backend2).to_not receive(:get)
|
14
|
+
expect(subject.lookup('is_craigw_trolling_us')).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'tries successive backends' do
|
18
|
+
not_found_value = Macmillan::Utils::Settings::KeyNotFound.new('is_craigw_trolling_us', backend1, 'is_craigw_trolling_us')
|
19
|
+
true_value = Macmillan::Utils::Settings::Value.new('is_craigw_trolling_us', true, backend2, 'is_craigw_trolling_us')
|
20
|
+
|
21
|
+
allow(backend1).to receive(:get).with('is_craigw_trolling_us').and_return(not_found_value)
|
22
|
+
allow(backend2).to receive(:get).with('is_craigw_trolling_us').and_return(true_value)
|
23
|
+
|
24
|
+
expect(subject.lookup('is_craigw_trolling_us')).to eq(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns a falsey value if it is actually set' do
|
28
|
+
not_found_value = Macmillan::Utils::Settings::KeyNotFound.new('is_it_good_code', backend1, 'is_it_good_code')
|
29
|
+
false_value = Macmillan::Utils::Settings::Value.new('is_it_good_code', false, backend2, 'is_it_good_code')
|
30
|
+
|
31
|
+
allow(backend1).to receive(:get).with('is_it_good_code').and_return(not_found_value)
|
32
|
+
allow(backend2).to receive(:get).with('is_it_good_code').and_return(false_value)
|
33
|
+
|
34
|
+
expect(subject.lookup('is_it_good_code')).to eq(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises an error if it cannot find a value in any backend' do
|
38
|
+
not_found_value1 = Macmillan::Utils::Settings::KeyNotFound.new('not_found', backend1, 'not_found')
|
39
|
+
not_found_value2 = Macmillan::Utils::Settings::KeyNotFound.new('not_found', backend2, 'not_found')
|
40
|
+
|
41
|
+
allow(backend1).to receive(:get).with('not_found').and_return(not_found_value1)
|
42
|
+
allow(backend2).to receive(:get).with('not_found').and_return(not_found_value2)
|
43
|
+
|
44
|
+
expect { subject.lookup('not_found') }.to raise_error(Macmillan::Utils::Settings::KeyNotFoundError)
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: macmillan-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Macmillan Science and Education (New Publsihing Platforms)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- spec/lib/macmillan/utils/logger/formatter_spec.rb
|
246
246
|
- spec/lib/macmillan/utils/middleware/uuid_spec.rb
|
247
247
|
- spec/lib/macmillan/utils/middleware/weak_etags_spec.rb
|
248
|
+
- spec/lib/macmillan/utils/settings/lookup_spec.rb
|
248
249
|
- spec/lib/macmillan/utils/settings_spec.rb
|
249
250
|
- spec/lib/macmillan/utils/statsd_controller_helper_spec.rb
|
250
251
|
- spec/lib/macmillan/utils/statsd_decorator_spec.rb
|
@@ -283,6 +284,7 @@ test_files:
|
|
283
284
|
- spec/lib/macmillan/utils/logger/formatter_spec.rb
|
284
285
|
- spec/lib/macmillan/utils/middleware/uuid_spec.rb
|
285
286
|
- spec/lib/macmillan/utils/middleware/weak_etags_spec.rb
|
287
|
+
- spec/lib/macmillan/utils/settings/lookup_spec.rb
|
286
288
|
- spec/lib/macmillan/utils/settings_spec.rb
|
287
289
|
- spec/lib/macmillan/utils/statsd_controller_helper_spec.rb
|
288
290
|
- spec/lib/macmillan/utils/statsd_decorator_spec.rb
|