lookout-rack-utils 3.8.0.39 → 4.0.0.44
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/lookout/rack/utils/version.rb +1 -1
- data/lookout-rack-utils.gemspec +3 -3
- data/spec/graphite_spec.rb +10 -4
- data/spec/i18n_spec.rb +6 -16
- data/spec/log_spec.rb +21 -19
- data/spec/request_spec.rb +7 -7
- data/spec/subroute_spec.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8d885772670c69b20f26cad8eafdf9a09414556
|
4
|
+
data.tar.gz: 5dff0ce7ee50afd78f03766167f6983cb26984d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ace2cb4663df9464a78ad5d34611f1c64ac2d26dfc162ebf5e0aa88a876d6bc914aac86dcb5cf1d7c3ceecb80fea6166078e8ce15c4d004305e7f454bc9c9f
|
7
|
+
data.tar.gz: 5ed83519a13bd1f937c0a46f7d5a470feeea95c4b120a825af32f1c17683df18841f3b1e9a76c26921b2abfc3dd07b79df89bf17128aa51accb8dfc3a6b50299
|
data/.travis.yml
CHANGED
data/lookout-rack-utils.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec", "~>
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
24
|
spec.add_development_dependency "rspec-its"
|
25
25
|
spec.add_development_dependency "rack-test"
|
26
26
|
spec.add_development_dependency "sinatra"
|
@@ -28,9 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_runtime_dependency "i18n"
|
30
30
|
|
31
|
-
spec.add_dependency "rack"
|
31
|
+
spec.add_dependency "rack"
|
32
32
|
spec.add_dependency "rack-graphite", '~> 1.3'
|
33
|
-
spec.add_dependency "configatron"
|
33
|
+
spec.add_dependency "configatron"
|
34
34
|
spec.add_dependency "log4r"
|
35
35
|
spec.add_dependency "lookout-statsd", '~> 3.1'
|
36
36
|
end
|
data/spec/graphite_spec.rb
CHANGED
@@ -5,8 +5,14 @@ describe Lookout::Rack::Utils::Graphite do
|
|
5
5
|
let(:statsd_instance) { nil }
|
6
6
|
subject(:graphite) { described_class }
|
7
7
|
|
8
|
+
around :each do |example|
|
9
|
+
configatron.temp do
|
10
|
+
configatron.statsd.prefix = 'test'
|
11
|
+
example.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
before :each do
|
9
|
-
configatron.statsd.stub(:prefix).and_return('test')
|
10
16
|
Lookout::Statsd.clear_instance
|
11
17
|
described_class.clear_instance
|
12
18
|
Lookout::Statsd.set_instance(statsd_instance)
|
@@ -28,21 +34,21 @@ describe Lookout::Rack::Utils::Graphite do
|
|
28
34
|
end
|
29
35
|
|
30
36
|
it 'should delegate to statsd' do
|
31
|
-
Lookout::
|
37
|
+
expect_any_instance_of(Lookout::StatsdClient).to receive(:increment).once.with('device.associated')
|
32
38
|
Lookout::Rack::Utils::Graphite.increment('device.associated')
|
33
39
|
end
|
34
40
|
|
35
41
|
describe '#time' do
|
36
42
|
it 'should delegate the block to statsd' do
|
37
43
|
expect { |block|
|
38
|
-
Lookout::
|
44
|
+
expect_any_instance_of(Lookout::StatsdClient).to receive(:time).once.with('device.became_aware', &block)
|
39
45
|
Lookout::Rack::Utils::Graphite.time('device.became_aware', &block)
|
40
46
|
}.to yield_control
|
41
47
|
end
|
42
48
|
|
43
49
|
it 'should delegate the sample rate and block to statsd' do
|
44
50
|
expect { |block|
|
45
|
-
Lookout::
|
51
|
+
expect_any_instance_of(Lookout::StatsdClient).to receive(:time).once.with('device.became_aware', 0.05, &block)
|
46
52
|
Lookout::Rack::Utils::Graphite.time('device.became_aware', 0.05, &block)
|
47
53
|
}.to yield_control
|
48
54
|
end
|
data/spec/i18n_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe Lookout::Rack::Utils::I18n do
|
|
19
19
|
let(:args) { double('mock arguments') }
|
20
20
|
|
21
21
|
before :each do
|
22
|
-
::I18n.
|
22
|
+
expect(::I18n).to receive(:t).with(args)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should call out to ::I18n.t' do
|
@@ -32,40 +32,30 @@ describe Lookout::Rack::Utils::I18n do
|
|
32
32
|
|
33
33
|
before :each do
|
34
34
|
helper.request = Object.new
|
35
|
-
helper.request.
|
35
|
+
expect(helper.request).to receive(:env).and_return({'HTTP_ACCEPT_LANGUAGE' => accepted_langs})
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'if HTTP_ACCEPT_LANGUAGE is not set' do
|
39
39
|
let(:accepted_langs) { nil }
|
40
40
|
|
41
|
-
before :each do
|
42
|
-
helper.configatron = Object.new
|
43
|
-
helper.configatron.stub(:locales).and_return([])
|
44
|
-
end
|
45
|
-
|
46
41
|
it { should be_empty }
|
47
42
|
end
|
48
43
|
|
49
44
|
context 'if HTTP_ACCEPT_LANGUAGE is set' do
|
50
45
|
# Example borrowed from http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
|
51
46
|
let(:accepted_langs) { 'da, en-gb;q=0.8, en;q=0.7' }
|
52
|
-
before :each do
|
53
|
-
helper.configatron = Object.new
|
54
|
-
helper.configatron.stub(:locales).and_return(['en'])
|
55
|
-
end
|
56
47
|
|
57
48
|
it { should_not be_empty }
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
61
52
|
describe '.current_locale' do
|
62
|
-
|
63
53
|
let(:target_locale) { 'target locale' }
|
64
54
|
let(:default_locale) { 'default locale' }
|
65
55
|
let(:accepted_langs) { [target_locale] }
|
66
56
|
|
67
57
|
before :each do
|
68
|
-
helper.
|
58
|
+
allow(helper).to receive(:accepted_languages).and_return(accepted_langs)
|
69
59
|
end
|
70
60
|
|
71
61
|
subject (:current_locale) { helper.current_locale }
|
@@ -82,8 +72,8 @@ describe Lookout::Rack::Utils::I18n do
|
|
82
72
|
context 'if configatron does not contain any of the accepted langs' do
|
83
73
|
before :each do
|
84
74
|
helper.configatron = Object.new
|
85
|
-
helper.configatron.
|
86
|
-
helper.configatron.
|
75
|
+
expect(helper.configatron).to receive(:locales).and_return([])
|
76
|
+
expect(helper.configatron).to receive(:default_locale).and_return(default_locale)
|
87
77
|
end
|
88
78
|
|
89
79
|
it { should eql default_locale }
|
@@ -92,7 +82,7 @@ describe Lookout::Rack::Utils::I18n do
|
|
92
82
|
context 'if configatron.locales contains one of the accepted languages' do
|
93
83
|
before :each do
|
94
84
|
helper.configatron = Object.new
|
95
|
-
helper.configatron.
|
85
|
+
expect(helper.configatron).to receive(:locales).and_return([target_locale])
|
96
86
|
end
|
97
87
|
|
98
88
|
it { should eql target_locale }
|
data/spec/log_spec.rb
CHANGED
@@ -5,37 +5,41 @@ require 'configatron'
|
|
5
5
|
|
6
6
|
describe Lookout::Rack::Utils::Log do
|
7
7
|
subject(:log) { described_class.instance }
|
8
|
-
|
8
|
+
let(:log_message) { 'foo' }
|
9
9
|
let(:filename) { "log" }
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
let(:exclude_levels) { [] }
|
11
|
+
|
12
|
+
around :each do |example|
|
13
|
+
configatron.temp do
|
14
|
+
configatron.logging.enabled = true
|
15
|
+
configatron.logging.file = filename
|
16
|
+
configatron.statsd.exclude_levels = exclude_levels
|
17
|
+
example.run
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
describe '.debug' do
|
17
22
|
context 'if debug is in configatron.statsd.exclude_levels' do
|
18
|
-
|
19
|
-
after { configatron.statsd.exclude_levels = [] }
|
23
|
+
let(:exclude_levels) { [:debug] }
|
20
24
|
|
21
25
|
it 'should not log a graphite stat' do
|
22
|
-
Lookout::Rack::Utils::Graphite.
|
26
|
+
expect(Lookout::Rack::Utils::Graphite).not_to receive(:increment).with('log.debug')
|
23
27
|
log.debug log_message
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
31
|
it 'should log a graphite stat' do
|
28
|
-
Lookout::Rack::Utils::Graphite.
|
32
|
+
expect(Lookout::Rack::Utils::Graphite).to receive(:increment).with('log.debug')
|
29
33
|
log.debug log_message
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
[:debug, :info, :warn, :error, :fatal].each do |method|
|
34
38
|
describe ".#{method}" do
|
35
|
-
|
36
|
-
Lookout::Rack::Utils::Graphite.should_receive(:increment).with("log.#{method}")
|
39
|
+
before { expect(log.instance_variable_get(:@logger)).to receive(method).with(log_message).and_call_original }
|
37
40
|
|
38
|
-
|
41
|
+
it 'should log a graphite stat' do
|
42
|
+
expect(Lookout::Rack::Utils::Graphite).to receive(:increment).with("log.#{method}")
|
39
43
|
|
40
44
|
processed = false
|
41
45
|
b = Proc.new { processed = true }
|
@@ -45,7 +49,6 @@ describe Lookout::Rack::Utils::Log do
|
|
45
49
|
end
|
46
50
|
|
47
51
|
it 'should invoke the internal logger object with a given block' do
|
48
|
-
log.instance_variable_get(:@logger).should_receive(method).with(log_message).and_call_original
|
49
52
|
processed = false
|
50
53
|
b = Proc.new { processed = true }
|
51
54
|
log.send(method, log_message, &b)
|
@@ -53,7 +56,6 @@ describe Lookout::Rack::Utils::Log do
|
|
53
56
|
end
|
54
57
|
|
55
58
|
it 'should invoke the internal logger object w/o a given block' do
|
56
|
-
log.instance_variable_get(:@logger).should_receive(method).with(log_message).and_call_original
|
57
59
|
log.send(method, log_message)
|
58
60
|
end
|
59
61
|
end
|
@@ -92,8 +94,8 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do
|
|
92
94
|
subject(:formatter) { described_class.new }
|
93
95
|
let(:logger) do
|
94
96
|
logger = double('Mock Logger')
|
95
|
-
logger.
|
96
|
-
logger.
|
97
|
+
expect(logger).to receive(:name).and_return('RSpec Logger')
|
98
|
+
expect(logger).to receive(:fullname).and_return('RSpec Logger')
|
97
99
|
logger
|
98
100
|
end
|
99
101
|
let(:project_name) { 'some_project' }
|
@@ -113,7 +115,7 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do
|
|
113
115
|
|
114
116
|
|
115
117
|
before :each do
|
116
|
-
formatter.
|
118
|
+
allow(formatter).to receive(:basedir).and_return(basedir)
|
117
119
|
end
|
118
120
|
|
119
121
|
|
@@ -121,7 +123,7 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do
|
|
121
123
|
subject(:filename) { formatter.event_filename(tracer[1]) }
|
122
124
|
|
123
125
|
context 'with a normal MRI LogEvent' do
|
124
|
-
it {
|
126
|
+
it { is_expected.to eql('spec/log_spec.rb:9') }
|
125
127
|
end
|
126
128
|
|
127
129
|
# We have slightly different log formats under packaged .jar files
|
@@ -129,7 +131,7 @@ describe Lookout::Rack::Utils::Log::LookoutFormatter do
|
|
129
131
|
let(:tracer) { [nil, "backend/metrics.rb:52:in `runloop'"] }
|
130
132
|
let(:basedir) { 'file:/home/user/source/projects/stuff.jar!/project' }
|
131
133
|
|
132
|
-
it {
|
134
|
+
it { is_expected.to eql('backend/metrics.rb:52') }
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
data/spec/request_spec.rb
CHANGED
@@ -22,26 +22,26 @@ describe Lookout::Rack::Utils::Request do
|
|
22
22
|
|
23
23
|
before :each do
|
24
24
|
helper.request = Object.new
|
25
|
-
helper.request.
|
26
|
-
helper.request.
|
27
|
-
helper.request.body.
|
25
|
+
allow(helper.request).to receive(:env).and_return({'HTTP_CONTENT_ENCODING' => 'gzip'})
|
26
|
+
allow(helper.request).to receive(:body).and_return(double)
|
27
|
+
allow(helper.request.body).to receive(:rewind).and_return(double)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should unzip data zipped data properly' do
|
31
|
-
helper.request.body.
|
31
|
+
expect(helper.request.body).to receive(:read).and_return(zipped_sample_data)
|
32
32
|
expect(helper.gunzipped_body).to eq(sample_data)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should do nothing if encoding is not set' do
|
36
|
-
helper.request.
|
37
|
-
helper.request.body.
|
36
|
+
expect(helper.request).to receive(:env).and_return({})
|
37
|
+
expect(helper.request.body).to receive(:read).and_return(zipped_sample_data)
|
38
38
|
expect(helper.gunzipped_body).to eq(zipped_sample_data)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should halt and throw and 400 when we have badly encoded data' do
|
42
42
|
allow(Lookout::Rack::Utils::Log).to receive(:instance).and_return(log_instance)
|
43
43
|
expect(log_instance).to receive(:warn)
|
44
|
-
helper.request.body.
|
44
|
+
expect(helper.request.body).to receive(:read).and_return(sample_data)
|
45
45
|
expect(helper).to receive(:halt).with(400, "{}")
|
46
46
|
helper.gunzipped_body
|
47
47
|
end
|
data/spec/subroute_spec.rb
CHANGED
@@ -93,7 +93,7 @@ describe Lookout::Rack::Utils::Subroute, :type => :route do
|
|
93
93
|
subject(:subrouted) { subroute!('/test_delete_invalid', :request_path => 'DELATE') }
|
94
94
|
|
95
95
|
it 'should throw an error' do
|
96
|
-
expect { subrouted }.to raise_error
|
96
|
+
expect { subrouted }.to raise_error NoMethodError
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lookout-rack-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0.44
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-its
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,16 +126,16 @@ dependencies:
|
|
126
126
|
name: rack
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rack-graphite
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +154,16 @@ dependencies:
|
|
154
154
|
name: configatron
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '0'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: log4r
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.6.
|
244
|
+
rubygems_version: 2.6.13
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: ''
|