rollbar 2.7.1 → 2.8.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.
@@ -39,7 +39,7 @@ describe Rollbar do
39
39
  end
40
40
 
41
41
  context 'Notifier' do
42
- context 'log' do
42
+ describe '#log' do
43
43
  let(:exception) do
44
44
  begin
45
45
  foo = bar
@@ -50,7 +50,7 @@ describe Rollbar do
50
50
 
51
51
  let(:configuration) { Rollbar.configuration }
52
52
 
53
- context 'executing a Thread before Rollbar is configured', :skip_dummy_rollbar => true do
53
+ context 'executing a Thread before Rollbar is configured' do
54
54
  before do
55
55
  Rollbar.reset_notifier!
56
56
  Rollbar.unconfigure
@@ -104,6 +104,236 @@ describe Rollbar do
104
104
  end
105
105
  end
106
106
 
107
+ context 'with before_process handlers in configuration' do
108
+ let!(:notifier) { Rollbar::Notifier.new }
109
+ let(:scope) { { :bar => :foo } }
110
+ let(:configuration) do
111
+ config = Rollbar::Configuration.new
112
+ config.enabled = true
113
+ config
114
+ end
115
+ let(:message) { 'message' }
116
+ let(:exception) { Exception.new }
117
+ let(:extra) { {:foo => :bar } }
118
+ let(:level) { 'error' }
119
+
120
+ before do
121
+ notifier.configuration = configuration
122
+ notifier.scope!(scope)
123
+ end
124
+
125
+ context 'without raise Rollbar::Ignore' do
126
+ let(:handler) do
127
+ proc do |options|
128
+
129
+ end
130
+ end
131
+
132
+ before do
133
+ configuration.before_process = handler
134
+ end
135
+
136
+ it 'calls the handler with the correct options' do
137
+ options = {
138
+ :level => level,
139
+ :scope => Rollbar::LazyStore.new(scope),
140
+ :exception => exception,
141
+ :message => message,
142
+ :extra => extra
143
+ }
144
+
145
+ expect(handler).to receive(:call).with(options)
146
+ expect(notifier).to receive(:report).with(level, message, exception, extra)
147
+
148
+ notifier.log(level, message, exception, extra)
149
+ end
150
+ end
151
+
152
+ context 'raising Rollbar::Ignore in the handler' do
153
+ let(:handler) do
154
+ proc do |options|
155
+ raise Rollbar::Ignore
156
+ end
157
+ end
158
+
159
+ before do
160
+ configuration.before_process = handler
161
+ end
162
+
163
+ it "calls the handler with correct options and doesn't call #report" do
164
+ options = {
165
+ :level => level,
166
+ :scope => Rollbar::LazyStore.new(scope),
167
+ :exception => exception,
168
+ :message => message,
169
+ :extra => extra
170
+ }
171
+ expect(handler).to receive(:call).with(options).and_call_original
172
+ expect(notifier).not_to receive(:report)
173
+
174
+ result = notifier.log(level, message, exception, extra)
175
+
176
+ expect(result).to be_eql('ignored')
177
+ end
178
+ end
179
+
180
+ context 'with 2 handlers, raising Rollbar::Ignore in the first one' do
181
+ let(:handler1) do
182
+ proc do |options|
183
+ raise Rollbar::Ignore
184
+ end
185
+ end
186
+
187
+ let(:handler2) do
188
+ proc do |options|
189
+
190
+ end
191
+ end
192
+
193
+ before do
194
+ configuration.before_process << handler1
195
+ configuration.before_process << handler2
196
+ end
197
+
198
+ it "calls only the first handler and doesn't calls #report" do
199
+ options = {
200
+ :level => level,
201
+ :scope => Rollbar::LazyStore.new(scope),
202
+ :exception => exception,
203
+ :message => message,
204
+ :extra => extra
205
+ }
206
+ expect(handler1).to receive(:call).with(options).and_call_original
207
+ expect(handler2).not_to receive(:call)
208
+ expect(notifier).not_to receive(:report)
209
+
210
+ result = notifier.log(level, message, exception, extra)
211
+
212
+ expect(result).to be_eql('ignored')
213
+ end
214
+
215
+ context 'if the first handler fails' do
216
+ let(:exception) { StandardError.new('foo') }
217
+ let(:handler1) do
218
+ proc { |options| raise exception }
219
+ end
220
+
221
+ it 'doesnt call the second handler and logs the error' do
222
+ expect(handler2).not_to receive(:call)
223
+ expect(notifier).to receive(:log_error).with("[Rollbar] Error calling the `before_process` hook: #{exception}")
224
+
225
+ notifier.log(level, message, exception, extra)
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ context 'with transform handlers in configuration' do
232
+ let!(:notifier) { Rollbar::Notifier.new }
233
+ let(:scope) { { :bar => :foo } }
234
+ let(:configuration) do
235
+ config = Rollbar::Configuration.new
236
+ config.enabled = true
237
+ config
238
+ end
239
+ let(:message) { 'message' }
240
+ let(:exception) { Exception.new }
241
+ let(:extra) { {:foo => :bar } }
242
+ let(:level) { 'error' }
243
+
244
+ before do
245
+ notifier.configuration = configuration
246
+ notifier.scope!(scope)
247
+ end
248
+
249
+ context 'without mutation in payload' do
250
+ let(:handler) do
251
+ proc do |options|
252
+
253
+ end
254
+ end
255
+
256
+ before do
257
+ configuration.transform = handler
258
+ end
259
+
260
+ it 'calls the handler with the correct options' do
261
+ options = {
262
+ :level => level,
263
+ :scope => Rollbar::LazyStore.new(scope),
264
+ :exception => exception,
265
+ :message => message,
266
+ :extra => extra,
267
+ :payload => kind_of(Hash)
268
+ }
269
+ expect(handler).to receive(:call).with(options).and_call_original
270
+ expect(notifier).to receive(:schedule_payload).with(kind_of(Hash))
271
+
272
+ notifier.log(level, message, exception, extra)
273
+ end
274
+ end
275
+
276
+ context 'with mutation in payload' do
277
+ let(:new_payload) do
278
+ {
279
+ 'access_token' => notifier.configuration.access_token,
280
+ 'data' => {
281
+ }
282
+ }
283
+ end
284
+ let(:handler) do
285
+ proc do |options|
286
+ payload = options[:payload]
287
+
288
+ payload.replace(new_payload)
289
+ end
290
+ end
291
+
292
+ before do
293
+ configuration.transform = handler
294
+ end
295
+
296
+ it 'calls the handler with the correct options' do
297
+ options = {
298
+ :level => level,
299
+ :scope => Rollbar::LazyStore.new(scope),
300
+ :exception => exception,
301
+ :message => message,
302
+ :extra => extra,
303
+ :payload => kind_of(Hash)
304
+ }
305
+ expect(handler).to receive(:call).with(options).and_call_original
306
+ expect(notifier).to receive(:schedule_payload).with(new_payload)
307
+
308
+ notifier.log(level, message, exception, extra)
309
+ end
310
+ end
311
+
312
+ context 'with two handlers' do
313
+ let(:handler1) { proc { |options|} }
314
+ let(:handler2) { proc { |options|} }
315
+
316
+ before do
317
+ configuration.transform << handler1
318
+ configuration.transform << handler2
319
+ end
320
+
321
+ context 'and the first one fails' do
322
+ let(:exception) { StandardError.new('foo') }
323
+ let(:handler1) do
324
+ proc { |options| raise exception }
325
+ end
326
+
327
+ it 'doesnt call the second handler and logs the error' do
328
+ expect(handler2).not_to receive(:call)
329
+ expect(notifier).to receive(:log_error).with("[Rollbar] Error calling the `transform` hook: #{exception}")
330
+
331
+ notifier.log(level, message, exception, extra)
332
+ end
333
+ end
334
+ end
335
+ end
336
+
107
337
  context 'debug/info/warning/error/critical' do
108
338
  let(:exception) do
109
339
  begin
@@ -243,7 +473,7 @@ describe Rollbar do
243
473
  notifier3.configuration.code_version.should == '456'
244
474
  notifier3.configuration.payload_options.should == {
245
475
  :a => 'a',
246
- :b => {:c => 3, :d => 'd'},
476
+ :b => {:c => 'c'},
247
477
  :c => 'c'
248
478
  }
249
479
 
@@ -427,15 +657,24 @@ describe Rollbar do
427
657
  notifier.configure do |config|
428
658
  config.custom_data_method = custom_method
429
659
  end
430
-
431
- expect(notifier).to receive(:report_custom_data_error).once.and_return(custom_data_report)
432
660
  end
433
661
 
434
662
  it 'doesnt crash the report' do
663
+ expect(notifier).to receive(:report_custom_data_error).once.and_return(custom_data_report)
435
664
  payload = notifier.send(:build_payload, 'info', 'message', nil, extra)
436
665
 
437
666
  expect(payload['data'][:body][:message][:extra]).to be_eql(expected_extra)
438
667
  end
668
+
669
+ context 'and for some reason the safely.error returns a String' do
670
+ it 'returns an empty Hash' do
671
+ allow_any_instance_of(Rollbar::Notifier).to receive(:error).and_return('ignored')
672
+
673
+ payload = notifier.send(:build_payload, 'info', 'message', nil, extra)
674
+
675
+ expect(payload['data'][:body][:message][:extra]).to be_eql(extra)
676
+ end
677
+ end
439
678
  end
440
679
 
441
680
  it 'should include project_gem_paths' do
@@ -1665,17 +1904,17 @@ describe Rollbar do
1665
1904
  { :foo => 'bar' }
1666
1905
  end
1667
1906
 
1668
- it 'changes payload options inside the block' do
1907
+ it 'changes data in scope_object inside the block' do
1669
1908
  Rollbar.reset_notifier!
1670
1909
  configure
1671
1910
 
1672
1911
  current_notifier_id = Rollbar.notifier.object_id
1673
1912
 
1674
1913
  Rollbar.scoped(scope_options) do
1675
- configuration = Rollbar.notifier.configuration
1914
+ scope_object = Rollbar.notifier.scope_object
1676
1915
 
1677
1916
  expect(Rollbar.notifier.object_id).not_to be_eql(current_notifier_id)
1678
- expect(configuration.payload_options).to be_eql(scope_options)
1917
+ expect(scope_object).to be_eql(scope_options)
1679
1918
  end
1680
1919
 
1681
1920
  expect(Rollbar.notifier.object_id).to be_eql(current_notifier_id)
@@ -1696,7 +1935,7 @@ describe Rollbar do
1696
1935
  let(:block) do
1697
1936
  proc do
1698
1937
  Thread.new do
1699
- scope = Rollbar.notifier.configuration.payload_options
1938
+ scope = Rollbar.notifier.scope_object
1700
1939
  Thread.main[:inner_scope] = scope
1701
1940
  end.join
1702
1941
  end
@@ -1722,10 +1961,10 @@ describe Rollbar do
1722
1961
  before { reconfigure_notifier }
1723
1962
 
1724
1963
  it 'adds the new scope to the payload options' do
1725
- configuration = Rollbar.notifier.configuration
1964
+ scope_object = Rollbar.notifier.scope_object
1726
1965
  Rollbar.scope!(new_scope)
1727
1966
 
1728
- expect(configuration.payload_options).to be_eql(new_scope)
1967
+ expect(scope_object).to be_eql(new_scope)
1729
1968
  end
1730
1969
  end
1731
1970
 
@@ -1799,6 +2038,28 @@ describe Rollbar do
1799
2038
  end
1800
2039
  end
1801
2040
 
2041
+ describe '.preconfigure'do
2042
+ before do
2043
+ Rollbar.unconfigure
2044
+ Rollbar.reset_notifier!
2045
+ end
2046
+
2047
+ it 'resets the notifier' do
2048
+ Rollbar.configure do |config|
2049
+ config.access_token = 'foo'
2050
+ end
2051
+
2052
+ Thread.new {}
2053
+
2054
+ Rollbar.preconfigure do |config|
2055
+ config.root = 'bar'
2056
+ end
2057
+
2058
+ notifier_config = Rollbar.notifier.configuration
2059
+ expect(notifier_config.root).to be_eql('bar')
2060
+ end
2061
+ end
2062
+
1802
2063
  # configure with some basic params
1803
2064
  def configure
1804
2065
  reconfigure_notifier
@@ -29,7 +29,7 @@ RSpec.configure do |config|
29
29
  config.formatter = 'documentation'
30
30
 
31
31
  config.use_transactional_fixtures = true
32
- config.order = "random"
32
+ config.order = 'random'
33
33
 
34
34
  config.before(:suite) do
35
35
  DatabaseCleaner.strategy = :truncation
@@ -44,12 +44,6 @@ RSpec.configure do |config|
44
44
  config.after(:each) do
45
45
  DatabaseCleaner.clean
46
46
  end
47
- config.backtrace_exclusion_patterns = [/gems\/rspec-.*/]
48
47
 
49
- if ENV['SKIP_DUMMY_ROLLBAR'] == 'true'
50
- config.filter_run(:skip_dummy_rollbar => true)
51
- else
52
- config.filter_run_excluding(:skip_dummy_rollbar => true)
53
- end
48
+ config.backtrace_exclusion_patterns = [/gems\/rspec-.*/]
54
49
  end
55
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-21 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: sucker_punch
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.0.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.0.0
83
83
  - !ruby/object:Gem::Dependency
@@ -215,6 +215,8 @@ extensions: []
215
215
  extra_rdoc_files: []
216
216
  files:
217
217
  - ".gitignore"
218
+ - ".gitmodules"
219
+ - ".rubocop.yml"
218
220
  - ".travis.yml"
219
221
  - Appraisals
220
222
  - CHANGELOG.md
@@ -226,6 +228,8 @@ files:
226
228
  - UPGRADE_FROM_RATCHET.md
227
229
  - UPGRADING.md
228
230
  - bin/rollbar-rails-runner
231
+ - data/rollbar.snippet.js
232
+ - docs/configuration_options.md
229
233
  - gemfiles/rails30.gemfile
230
234
  - gemfiles/rails31.gemfile
231
235
  - gemfiles/rails32.gemfile
@@ -253,11 +257,18 @@ files:
253
257
  - lib/rollbar/encoding/encoder.rb
254
258
  - lib/rollbar/encoding/legacy_encoder.rb
255
259
  - lib/rollbar/exception_reporter.rb
260
+ - lib/rollbar/exceptions.rb
256
261
  - lib/rollbar/goalie.rb
262
+ - lib/rollbar/js.rb
263
+ - lib/rollbar/js/frameworks.rb
264
+ - lib/rollbar/js/frameworks/rails.rb
265
+ - lib/rollbar/js/middleware.rb
266
+ - lib/rollbar/js/version.rb
257
267
  - lib/rollbar/json.rb
258
268
  - lib/rollbar/json/default.rb
259
269
  - lib/rollbar/json/oj.rb
260
270
  - lib/rollbar/language_support.rb
271
+ - lib/rollbar/lazy_store.rb
261
272
  - lib/rollbar/logger_proxy.rb
262
273
  - lib/rollbar/middleware/rack/builder.rb
263
274
  - lib/rollbar/middleware/rack/test_session.rb
@@ -285,6 +296,7 @@ files:
285
296
  - lib/rollbar/util/hash.rb
286
297
  - lib/rollbar/util/ip_obfuscator.rb
287
298
  - lib/rollbar/version.rb
299
+ - lib/tasks/tasks.rake
288
300
  - rollbar.gemspec
289
301
  - spec/cacert.pem
290
302
  - spec/controllers/home_controller_spec.rb
@@ -309,9 +321,11 @@ files:
309
321
  - spec/dummyapp/app/views/home/cause_exception.html.erb
310
322
  - spec/dummyapp/app/views/home/index.html.erb
311
323
  - spec/dummyapp/app/views/home/report_exception.html.erb
324
+ - spec/dummyapp/app/views/js/test.html.erb
312
325
  - spec/dummyapp/app/views/layouts/_messages.html.erb
313
326
  - spec/dummyapp/app/views/layouts/_navigation.html.erb
314
327
  - spec/dummyapp/app/views/layouts/application.html.erb
328
+ - spec/dummyapp/app/views/layouts/simple.html.erb
315
329
  - spec/dummyapp/app/views/users/index.html.erb
316
330
  - spec/dummyapp/app/views/users/show.html.erb
317
331
  - spec/dummyapp/config.ru
@@ -357,8 +371,11 @@ files:
357
371
  - spec/rollbar/delayed_job/job_data.rb
358
372
  - spec/rollbar/delayed_job_spec.rb
359
373
  - spec/rollbar/encoding/encoder_spec.rb
374
+ - spec/rollbar/js/frameworks/rails_spec.rb
375
+ - spec/rollbar/js/middleware_spec.rb
360
376
  - spec/rollbar/json/oj_spec.rb
361
377
  - spec/rollbar/json_spec.rb
378
+ - spec/rollbar/lazy_store_spec.rb
362
379
  - spec/rollbar/logger_proxy_spec.rb
363
380
  - spec/rollbar/middleware/rack/builder_spec.rb
364
381
  - spec/rollbar/middleware/sinatra_spec.rb
@@ -430,9 +447,11 @@ test_files:
430
447
  - spec/dummyapp/app/views/home/cause_exception.html.erb
431
448
  - spec/dummyapp/app/views/home/index.html.erb
432
449
  - spec/dummyapp/app/views/home/report_exception.html.erb
450
+ - spec/dummyapp/app/views/js/test.html.erb
433
451
  - spec/dummyapp/app/views/layouts/_messages.html.erb
434
452
  - spec/dummyapp/app/views/layouts/_navigation.html.erb
435
453
  - spec/dummyapp/app/views/layouts/application.html.erb
454
+ - spec/dummyapp/app/views/layouts/simple.html.erb
436
455
  - spec/dummyapp/app/views/users/index.html.erb
437
456
  - spec/dummyapp/app/views/users/show.html.erb
438
457
  - spec/dummyapp/config.ru
@@ -478,8 +497,11 @@ test_files:
478
497
  - spec/rollbar/delayed_job/job_data.rb
479
498
  - spec/rollbar/delayed_job_spec.rb
480
499
  - spec/rollbar/encoding/encoder_spec.rb
500
+ - spec/rollbar/js/frameworks/rails_spec.rb
501
+ - spec/rollbar/js/middleware_spec.rb
481
502
  - spec/rollbar/json/oj_spec.rb
482
503
  - spec/rollbar/json_spec.rb
504
+ - spec/rollbar/lazy_store_spec.rb
483
505
  - spec/rollbar/logger_proxy_spec.rb
484
506
  - spec/rollbar/middleware/rack/builder_spec.rb
485
507
  - spec/rollbar/middleware/sinatra_spec.rb