Skip to content
This repository was archived by the owner on Mar 11, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pkg
Gemfile.lock
.bundle
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
source 'https://rubygems.org'
gemspec

group :development do
gem 'minitest'
end
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test_*.rb', 'test/**/test_*.rb']
t.verbose = true
end
11 changes: 10 additions & 1 deletion lib/scrolls/rails/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ class LogSubscriber < ActiveSupport::LogSubscriber

def process_action(event)
exception = event.payload[:exception]
if exception

if exception.present?
# In Rails 3.2.9 event.payload[:exception] was changed from an
# Exception object to an Array containing the e.class.name and
# e.message. Adding handling for this case here.
if exception.is_a?(Array)
exception_class_name, exception_message = exception
exception = exception_class_name.constantize.new(exception_message)
end

Scrolls.log_exception({status: 500}, exception)
else
Scrolls.log(extract_request_data_from_event(event))
Expand Down
2 changes: 1 addition & 1 deletion lib/scrolls/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Scrolls
module Rails
VERSION = '0.0.1'
VERSION = '0.0.2'
end
end
57 changes: 57 additions & 0 deletions test/rails/test_log_subscriber.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'minitest/autorun'

require 'active_support/core_ext/object' # provides .present? && constantize
require 'scrolls/rails/log_subscriber'

class FakeEvent
attr_accessor :payload
end

# mock Scrolls to something useful for this test
module Scrolls
class << self
def log_exception info, ex
@@info = info
@@ex = ex
end

def info
@@info
end

def exception
@@ex
end
end
end

class ScrollsRailsLogSubscriber < Minitest::Test
def setup
@sub = Scrolls::Rails::LogSubscriber.new
@evt = FakeEvent.new
end

def test_process_action_with_array
@evt.payload = {
exception: ['Exception', 'Test array']
}

@sub.process_action(@evt)

assert_equal({status: 500}, Scrolls.info)
assert_kind_of(Exception, Scrolls.exception)
assert_equal('Test array', Scrolls.exception.message)
end

def test_process_action_with_exception
@evt.payload = {
exception: Exception.new('Test exception')
}

@sub.process_action(@evt)

assert_equal({status: 500}, Scrolls.info)
assert_kind_of(Exception, Scrolls.exception)
assert_equal('Test exception', Scrolls.exception.message)
end
end