timber 2.6.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -38
- data/CHANGELOG.md +9 -0
- data/README.md +30 -284
- data/Rakefile +78 -0
- data/lib/timber.rb +6 -6
- data/lib/timber/config.rb +1 -83
- data/lib/timber/config/integrations.rb +1 -47
- data/lib/timber/context.rb +3 -24
- data/lib/timber/contexts.rb +2 -30
- data/lib/timber/contexts/http.rb +16 -36
- data/lib/timber/contexts/release.rb +12 -23
- data/lib/timber/contexts/runtime.rb +9 -36
- data/lib/timber/contexts/session.rb +8 -21
- data/lib/timber/contexts/system.rb +9 -16
- data/lib/timber/contexts/user.rb +13 -33
- data/lib/timber/current_context.rb +16 -78
- data/lib/timber/event.rb +12 -9
- data/lib/timber/events.rb +1 -33
- data/lib/timber/events/controller_call.rb +20 -31
- data/lib/timber/events/error.rb +18 -26
- data/lib/timber/events/exception.rb +1 -0
- data/lib/timber/events/sql_query.rb +14 -24
- data/lib/timber/events/template_render.rb +13 -24
- data/lib/timber/integration.rb +1 -1
- data/lib/timber/integrator.rb +1 -1
- data/lib/timber/log_devices/http.rb +98 -19
- data/lib/timber/log_entry.rb +6 -24
- data/lib/timber/logger.rb +5 -14
- data/lib/timber/util.rb +1 -6
- data/lib/timber/util/non_nil_hash_builder.rb +3 -1
- data/lib/timber/version.rb +1 -1
- data/spec/README.md +2 -8
- data/spec/spec_helper.rb +0 -7
- data/spec/support/timber.rb +1 -3
- data/spec/timber/current_context_spec.rb +12 -50
- data/spec/timber/events/controller_call_spec.rb +4 -4
- data/spec/timber/events/error_spec.rb +4 -9
- data/spec/timber/log_devices/http_spec.rb +26 -2
- data/spec/timber/log_entry_spec.rb +12 -6
- data/spec/timber/logger_spec.rb +27 -68
- data/timber.gemspec +1 -1
- metadata +5 -139
- data/gemfiles/rails-3.0.gemfile +0 -5
- data/gemfiles/rails-3.1.gemfile +0 -5
- data/gemfiles/rails-3.2.gemfile +0 -5
- data/gemfiles/rails-4.0.gemfile +0 -9
- data/gemfiles/rails-4.1.gemfile +0 -9
- data/gemfiles/rails-4.2.gemfile +0 -9
- data/gemfiles/rails-5.0.gemfile +0 -9
- data/gemfiles/rails-5.1.gemfile +0 -9
- data/gemfiles/rails-edge.gemfile +0 -7
- data/lib/timber/cli.rb +0 -60
- data/lib/timber/cli/api.rb +0 -183
- data/lib/timber/cli/api/application.rb +0 -34
- data/lib/timber/cli/config_file.rb +0 -71
- data/lib/timber/cli/file_helper.rb +0 -53
- data/lib/timber/cli/installer.rb +0 -70
- data/lib/timber/cli/installers.rb +0 -102
- data/lib/timber/cli/installers/config_file.rb +0 -51
- data/lib/timber/cli/installers/other.rb +0 -59
- data/lib/timber/cli/installers/rails.rb +0 -225
- data/lib/timber/cli/installers/root.rb +0 -116
- data/lib/timber/cli/io.rb +0 -100
- data/lib/timber/cli/io/ansi.rb +0 -22
- data/lib/timber/cli/io/messages.rb +0 -198
- data/lib/timber/cli/os_helper.rb +0 -74
- data/lib/timber/config/integrations/rack.rb +0 -74
- data/lib/timber/contexts/custom.rb +0 -44
- data/lib/timber/contexts/organization.rb +0 -48
- data/lib/timber/events/custom.rb +0 -53
- data/lib/timber/events/http_request.rb +0 -71
- data/lib/timber/events/http_response.rb +0 -81
- data/lib/timber/frameworks.rb +0 -19
- data/lib/timber/frameworks/rails.rb +0 -27
- data/lib/timber/integrations.rb +0 -29
- data/lib/timber/integrations/action_controller.rb +0 -18
- data/lib/timber/integrations/action_controller/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +0 -46
- data/lib/timber/integrations/action_dispatch.rb +0 -23
- data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +0 -53
- data/lib/timber/integrations/action_view.rb +0 -18
- data/lib/timber/integrations/action_view/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +0 -83
- data/lib/timber/integrations/active_record.rb +0 -18
- data/lib/timber/integrations/active_record/log_subscriber.rb +0 -26
- data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +0 -53
- data/lib/timber/integrations/rack.rb +0 -27
- data/lib/timber/integrations/rack/error_event.rb +0 -64
- data/lib/timber/integrations/rack/http_context.rb +0 -27
- data/lib/timber/integrations/rack/http_events.rb +0 -210
- data/lib/timber/integrations/rack/middleware.rb +0 -28
- data/lib/timber/integrations/rack/session_context.rb +0 -65
- data/lib/timber/integrations/rack/user_context.rb +0 -135
- data/lib/timber/integrations/rails.rb +0 -22
- data/lib/timber/integrations/rails/rack_logger.rb +0 -60
- data/lib/timber/overrides.rb +0 -12
- data/lib/timber/overrides/active_support_3_tagged_logging.rb +0 -111
- data/lib/timber/overrides/active_support_buffered_logger.rb +0 -22
- data/lib/timber/overrides/active_support_tagged_logging.rb +0 -66
- data/lib/timber/overrides/lograge.rb +0 -18
- data/lib/timber/overrides/rails_stdout_logging.rb +0 -21
- data/lib/timber/util/active_support_log_subscriber.rb +0 -37
- data/lib/timber/util/attribute_normalizer.rb +0 -89
- data/lib/timber/util/hash.rb +0 -90
- data/lib/timber/util/request.rb +0 -72
- data/lib/timber/util/struct.rb +0 -16
- data/spec/rails/tagged_logging_spec.rb +0 -44
- data/spec/support/action_controller.rb +0 -8
- data/spec/support/active_record.rb +0 -32
- data/spec/support/rails.rb +0 -67
- data/spec/support/rails/templates/_partial.html +0 -1
- data/spec/support/rails/templates/template.html +0 -1
- data/spec/timber/cli/config_file_spec.rb +0 -26
- data/spec/timber/cli/installers/config_file_spec.rb +0 -36
- data/spec/timber/cli/installers/other_spec.rb +0 -49
- data/spec/timber/cli/installers/rails_spec.rb +0 -364
- data/spec/timber/cli/installers/root_spec.rb +0 -73
- data/spec/timber/config_spec.rb +0 -28
- data/spec/timber/contexts/custom_spec.rb +0 -11
- data/spec/timber/contexts/organization_spec.rb +0 -11
- data/spec/timber/contexts/runtime_spec.rb +0 -11
- data/spec/timber/contexts/system_spec.rb +0 -11
- data/spec/timber/contexts/user_spec.rb +0 -11
- data/spec/timber/contexts_spec.rb +0 -49
- data/spec/timber/event_spec.rb +0 -10
- data/spec/timber/events/custom_spec.rb +0 -36
- data/spec/timber/events/http_request_spec.rb +0 -32
- data/spec/timber/events/http_response_spec.rb +0 -12
- data/spec/timber/events_spec.rb +0 -55
- data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +0 -55
- data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +0 -53
- data/spec/timber/integrations/action_view/log_subscriber_spec.rb +0 -115
- data/spec/timber/integrations/active_record/log_subscriber_spec.rb +0 -46
- data/spec/timber/integrations/rack/error_event_spec.rb +0 -63
- data/spec/timber/integrations/rack/http_context_spec.rb +0 -60
- data/spec/timber/integrations/rack/http_events_spec.rb +0 -101
- data/spec/timber/integrations/rack/session_context_spec.rb +0 -62
- data/spec/timber/integrations/rails/rack_logger_spec.rb +0 -58
- data/spec/timber/util/attribute_normalizer_spec.rb +0 -90
- data/spec/timber/util/hash_spec.rb +0 -30
- data/spec/timber/util/request_spec.rb +0 -10
@@ -1,73 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Timber::CLI::Installers::Root, :rails_23 => true do
|
6
|
-
let(:api_key) { "abcd1234" }
|
7
|
-
let(:app) do
|
8
|
-
attributes = {
|
9
|
-
"api_key" => api_key,
|
10
|
-
"environment" => "development",
|
11
|
-
"heroku_drain_url" => "http://drain.heroku.com",
|
12
|
-
"name" => "My Rails App",
|
13
|
-
"platform_type" => "other"
|
14
|
-
}
|
15
|
-
Timber::CLI::API::Application.new(attributes)
|
16
|
-
end
|
17
|
-
let(:api) { Timber::CLI::API.new(api_key) }
|
18
|
-
let(:input) { StringIO.new }
|
19
|
-
let(:output) { StringIO.new }
|
20
|
-
let(:io) { Timber::CLI::IO.new(io_out: output, io_in: input) }
|
21
|
-
let(:installer) { described_class.new(io, api) }
|
22
|
-
|
23
|
-
describe ".run" do
|
24
|
-
it "should run properly" do
|
25
|
-
input.string = "y\n"
|
26
|
-
|
27
|
-
expect(installer).to receive(:run_sub_installer).with(app).exactly(1).times
|
28
|
-
expect(installer).to receive(:send_test_messages).exactly(1).times
|
29
|
-
expect(installer).to receive(:confirm_log_delivery).exactly(1).times
|
30
|
-
expect(installer).to receive(:wrap_up).with(app).exactly(1).times
|
31
|
-
expect(api).to receive(:event).with(:success).exactly(1).times
|
32
|
-
expect(installer).to receive(:collect_feedback).exactly(1).times
|
33
|
-
|
34
|
-
installer.run(app)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ".get_sub_installer" do
|
39
|
-
context "with Rails" do
|
40
|
-
around(:each) do |example|
|
41
|
-
if defined?(Rails)
|
42
|
-
example.run
|
43
|
-
else
|
44
|
-
Rails = true
|
45
|
-
example.run
|
46
|
-
Object.send(:remove_const, :Rails)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return Rails" do
|
51
|
-
expect(installer.send(:get_sub_installer).class).to eq(Timber::CLI::Installers::Rails)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "without Rails" do
|
56
|
-
around(:each) do |example|
|
57
|
-
if defined?(Rails)
|
58
|
-
OldRails = Rails
|
59
|
-
Object.send(:remove_const, :Rails)
|
60
|
-
example.run
|
61
|
-
Rails = OldRails
|
62
|
-
Object.send(:remove_const, :OldRails)
|
63
|
-
else
|
64
|
-
example.run
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return other" do
|
69
|
-
expect(installer.send(:get_sub_installer).class).to eq(Timber::CLI::Installers::Other)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/timber/config_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "singleton"
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Timber::Config, :rails_23 => true do
|
5
|
-
let(:config) { Timber::Config.send(:new) }
|
6
|
-
|
7
|
-
describe ".logrageify!" do
|
8
|
-
it "should logrageify" do
|
9
|
-
expect(Timber::Integrations::ActionController.silence?).to eq(false)
|
10
|
-
expect(Timber::Integrations::ActionView.silence?).to eq(false)
|
11
|
-
expect(Timber::Integrations::ActiveRecord.silence?).to eq(false)
|
12
|
-
expect(Timber::Integrations::Rack::HTTPEvents.collapse_into_single_event?).to eq(false)
|
13
|
-
|
14
|
-
config.logrageify!
|
15
|
-
|
16
|
-
expect(Timber::Integrations::ActionController.silence?).to eq(true)
|
17
|
-
expect(Timber::Integrations::ActionView.silence?).to eq(true)
|
18
|
-
expect(Timber::Integrations::ActiveRecord.silence?).to eq(true)
|
19
|
-
expect(Timber::Integrations::Rack::HTTPEvents.collapse_into_single_event?).to eq(true)
|
20
|
-
|
21
|
-
# Reset
|
22
|
-
Timber::Integrations::ActionController.silence = false
|
23
|
-
Timber::Integrations::ActionView.silence = false
|
24
|
-
Timber::Integrations::ActiveRecord.silence = false
|
25
|
-
Timber::Integrations::Rack::HTTPEvents.collapse_into_single_event = false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts::Custom, :rails_23 => true do
|
4
|
-
describe ".as_json" do
|
5
|
-
it "should coerce type into an atom" do
|
6
|
-
custom_context = described_class.new(:type => "my type", :data => {:key => "value"})
|
7
|
-
json = custom_context.as_json()
|
8
|
-
expect(json.keys.first).to eq(:"my type")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts::Organization, :rails_23 => true do
|
4
|
-
describe ".as_json" do
|
5
|
-
it "should coerce id into a string" do
|
6
|
-
user_context = described_class.new(:id => 1)
|
7
|
-
json = user_context.as_json()
|
8
|
-
expect(json[:id]).to eq("1")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts::Runtime, :rails_23 => true do
|
4
|
-
describe ".as_json" do
|
5
|
-
it "should coerce vm_pid into an string" do
|
6
|
-
custom_context = described_class.new(:vm_pid => 1)
|
7
|
-
json = custom_context.as_json()
|
8
|
-
expect(json[:vm_pid]).to eq("1")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts::System, :rails_23 => true do
|
4
|
-
describe ".as_json" do
|
5
|
-
it "should coerce pid into an integer" do
|
6
|
-
custom_context = described_class.new(:pid => "1")
|
7
|
-
json = custom_context.as_json()
|
8
|
-
expect(json[:pid]).to eq(1)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts::User, :rails_23 => true do
|
4
|
-
describe ".as_json" do
|
5
|
-
it "should coerce id into a string" do
|
6
|
-
user_context = described_class.new(:id => 1)
|
7
|
-
json = user_context.as_json()
|
8
|
-
expect(json[:id]).to eq("1")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Contexts, :rails_23 => true do
|
4
|
-
describe ".build" do
|
5
|
-
it "should build a Timber::Context" do
|
6
|
-
context = Timber::Contexts::Custom.new(
|
7
|
-
type: :build,
|
8
|
-
data: {version: "1.0.0"}
|
9
|
-
)
|
10
|
-
built_context = Timber::Contexts.build(context)
|
11
|
-
expect(built_context).to eq(context)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should use #to_timber_context" do
|
15
|
-
BuildContext = Struct.new(:version) do
|
16
|
-
def to_timber_context
|
17
|
-
Timber::Contexts::Custom.new(
|
18
|
-
type: :build,
|
19
|
-
data: respond_to?(:to_h) ? to_h : Timber::Util::Struct.to_hash(self)
|
20
|
-
)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
built_context = Timber::Contexts.build(BuildContext.new("1.0.0"))
|
24
|
-
expect(built_context).to be_kind_of(Timber::Contexts::Custom)
|
25
|
-
expect(built_context.type).to eq(:build)
|
26
|
-
Object.send(:remove_const, :BuildContext)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should accept a properly structured hash" do
|
30
|
-
built_context = Timber::Contexts.build(build: {version: "1.0.0"})
|
31
|
-
expect(built_context).to be_kind_of(Timber::Contexts::Custom)
|
32
|
-
expect(built_context.type).to eq(:build)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should accept a struct" do
|
36
|
-
BuildContext = Struct.new(:version) do
|
37
|
-
def type; :build; end
|
38
|
-
end
|
39
|
-
built_context = Timber::Contexts.build(BuildContext.new("1.0.0"))
|
40
|
-
expect(built_context).to be_kind_of(Timber::Contexts::Custom)
|
41
|
-
expect(built_context.type).to eq(:build)
|
42
|
-
Object.send(:remove_const, :BuildContext)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should return nil for unsupported" do
|
46
|
-
expect(Timber::Contexts.build(1)).to be_nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/spec/timber/event_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Event, :rails_23 => true do
|
4
|
-
describe "#to_s" do
|
5
|
-
it "should display the message" do
|
6
|
-
event = Timber::Events::Custom.new(message: "Build version 1.0.0", type: :build, data: {version: "1.0.0"})
|
7
|
-
expect(event.to_s).to eq("Build version 1.0.0")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Events::Custom, :rails_23 => true do
|
4
|
-
describe ".to_hash" do
|
5
|
-
it "should coerce type into an atom" do
|
6
|
-
custom_event = described_class.new(:type => "my type", :message => "hello", :data => {:key => "value"})
|
7
|
-
hash = custom_event.to_hash()
|
8
|
-
expect(hash.keys.first).to eq(:"my type")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should coerce a Time into a float representing fractional milliseconds" do
|
12
|
-
timer = Timber::Timer.start
|
13
|
-
sleep(0.25)
|
14
|
-
custom_event = described_class.new(:type => :my_event, :message => "hello", :data => {:time_ms => timer})
|
15
|
-
expect(custom_event.message).to include("in ")
|
16
|
-
expect(custom_event.message).to end_with("ms")
|
17
|
-
data = custom_event.data
|
18
|
-
expect(data[:time_ms]).to be_kind_of(Float)
|
19
|
-
expect(data[:time_ms]).to be > 0.0
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#new" do
|
24
|
-
it "does not require data key" do
|
25
|
-
custom_event = described_class.new(:type => "my type", :message => "hello")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#as_json" do
|
30
|
-
it "should render an empty data hash" do
|
31
|
-
custom_event = described_class.new(:type => "my type", :message => "hello")
|
32
|
-
hash = custom_event.as_json()
|
33
|
-
expect(hash).to eq({:custom => {:"my type" => {}}})
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Timber::Events::HTTPRequest, :rails_23 => true do
|
6
|
-
describe ".initialize" do
|
7
|
-
it "should coerce content_length into an integer" do
|
8
|
-
event = described_class.new(:method => 'GET', :content_length => "123")
|
9
|
-
expect(event.content_length).to eq(123)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "with a header filters" do
|
13
|
-
around(:each) do |example|
|
14
|
-
old_http_header_filters = Timber::Config.instance.http_header_filters
|
15
|
-
Timber::Config.instance.http_header_filters += ['api-key']
|
16
|
-
example.run
|
17
|
-
Timber::Config.instance.http_header_filters = old_http_header_filters
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should sanitize headers when a config option is set" do
|
21
|
-
event = described_class.new(:headers => {'Api-Key' => 'abcde'}, :host => 'my.host.com', :method => 'GET', :path => '/path', :scheme => 'https')
|
22
|
-
expect(event.headers).to eq({'api-key' => '[sanitized]'})
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should handle header encoding" do
|
27
|
-
referer = 'http://www.metrojobb.se/jobb/1013893-skadeadministratör'.force_encoding('ASCII-8BIT')
|
28
|
-
event = described_class.new(:headers => {'Referer' => referer}, :host => 'my.host.com', :method => 'GET', :path => '/path', :scheme => 'https')
|
29
|
-
expect(event.headers["referer"].encoding).to eq(::Encoding::UTF_8)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Timber::Events::HTTPResponse, :rails_23 => true do
|
6
|
-
describe ".initialize" do
|
7
|
-
it "should coerce content_length into an integer" do
|
8
|
-
event = described_class.new(:content_length => "123", :status => 200, :time_ms => 1)
|
9
|
-
expect(event.content_length).to eq(123)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/spec/timber/events_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Events, :rails_23 => true do
|
4
|
-
describe ".build" do
|
5
|
-
it "should build a Timber::Event" do
|
6
|
-
event = Timber::Events::Custom.new(
|
7
|
-
type: :payment_rejected,
|
8
|
-
message: "Payment rejected",
|
9
|
-
data: {customer_id: "abcd1234", amount: 100}
|
10
|
-
)
|
11
|
-
built_event = Timber::Events.build(event)
|
12
|
-
expect(built_event).to eq(event)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should use #to_timber_event" do
|
16
|
-
PaymentRejectedEvent = Struct.new(:customer_id, :amount) do
|
17
|
-
def to_timber_event
|
18
|
-
Timber::Events::Custom.new(
|
19
|
-
type: :payment_rejected,
|
20
|
-
message: "Payment rejected for #{customer_id}",
|
21
|
-
data: respond_to?(:to_h) ? to_h : hash
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
built_event = Timber::Events.build(PaymentRejectedEvent.new("abcd1234", 100))
|
26
|
-
expect(built_event).to be_kind_of(Timber::Events::Custom)
|
27
|
-
expect(built_event.type).to eq(:payment_rejected)
|
28
|
-
expect(built_event.message).to eq("Payment rejected for abcd1234")
|
29
|
-
Object.send(:remove_const, :PaymentRejectedEvent)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should accept a properly structured hash" do
|
33
|
-
built_event = Timber::Events.build({message: "Payment rejected", payment_rejected: {customer_id: "abcd1234", amount: 100}})
|
34
|
-
expect(built_event).to be_kind_of(Timber::Events::Custom)
|
35
|
-
expect(built_event.type).to eq(:payment_rejected)
|
36
|
-
expect(built_event.message).to eq("Payment rejected")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should accept a struct" do
|
40
|
-
PaymentRejectedEvent = Struct.new(:customer_id, :amount) do
|
41
|
-
def message; "Payment rejected for #{customer_id}"; end
|
42
|
-
def type; :payment_rejected; end
|
43
|
-
end
|
44
|
-
built_event = Timber::Events.build(PaymentRejectedEvent.new("abcd1234", 100))
|
45
|
-
expect(built_event).to be_kind_of(Timber::Events::Custom)
|
46
|
-
expect(built_event.type).to eq(:payment_rejected)
|
47
|
-
expect(built_event.message).to eq("Payment rejected for abcd1234")
|
48
|
-
Object.send(:remove_const, :PaymentRejectedEvent)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should return nil for unsupported" do
|
52
|
-
expect(Timber::Events.build(1)).to be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if defined?(::ActionController)
|
4
|
-
describe Timber::Integrations::ActionController::LogSubscriber do
|
5
|
-
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
6
|
-
let(:io) { StringIO.new }
|
7
|
-
let(:logger) do
|
8
|
-
logger = Timber::Logger.new(io)
|
9
|
-
logger.level = ::Logger::INFO
|
10
|
-
logger
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#insert!" do
|
14
|
-
around(:each) do |example|
|
15
|
-
class LogSubscriberController < ActionController::Base
|
16
|
-
layout nil
|
17
|
-
|
18
|
-
def index
|
19
|
-
render json: {}
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_for_action(action_name)
|
23
|
-
action_name
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
::RailsApp.routes.draw do
|
28
|
-
get 'log_subscriber' => 'log_subscriber#index'
|
29
|
-
end
|
30
|
-
|
31
|
-
with_rails_logger(logger) do
|
32
|
-
Timecop.freeze(time) { example.run }
|
33
|
-
end
|
34
|
-
|
35
|
-
Object.send(:remove_const, :LogSubscriberController)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should log a controller_call event once" do
|
39
|
-
# Rails uses this to calculate the view runtime below
|
40
|
-
allow(Benchmark).to receive(:ms).and_return(1).and_yield
|
41
|
-
|
42
|
-
dispatch_rails_request("/log_subscriber?query=value")
|
43
|
-
lines = clean_lines(io.string.split("\n"))
|
44
|
-
expect(lines.length).to eq(3)
|
45
|
-
expect(lines[1]).to start_with('Processing by LogSubscriberController#index as HTML\n Parameters: {"query"=>"value"} @metadata {"level":"info","dt":"2016-09-01T12:00:00.000000Z"')
|
46
|
-
expect(lines[1]).to include('"event":{"controller_call":{"controller":"LogSubscriberController","action":"index","params_json":"{\"query\":\"value\"}"}}')
|
47
|
-
end
|
48
|
-
|
49
|
-
# Remove blank lines since Rails does this to space out requests in the logs
|
50
|
-
def clean_lines(lines)
|
51
|
-
lines.select { |line| !line.start_with?(" @metadat") }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if defined?(::ActionDispatch)
|
4
|
-
describe Timber::Integrations::ActionDispatch::DebugExceptions do
|
5
|
-
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
6
|
-
let(:io) { StringIO.new }
|
7
|
-
let(:logger) do
|
8
|
-
logger = Timber::Logger.new(io)
|
9
|
-
logger.level = ::Logger::DEBUG
|
10
|
-
logger
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#insert!" do
|
14
|
-
around(:each) do |example|
|
15
|
-
class ExceptionController < ActionController::Base
|
16
|
-
layout nil
|
17
|
-
|
18
|
-
def index
|
19
|
-
raise "boom"
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_for_action(action_name)
|
23
|
-
action_name
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
::RailsApp.routes.draw do
|
28
|
-
get 'exception' => 'exception#index'
|
29
|
-
end
|
30
|
-
|
31
|
-
with_rails_logger(logger) do
|
32
|
-
Timecop.freeze(time) { example.run }
|
33
|
-
end
|
34
|
-
|
35
|
-
Object.send(:remove_const, :ExceptionController)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should log an exception event once" do
|
39
|
-
expect { dispatch_rails_request("/exception") }.to raise_error(RuntimeError)
|
40
|
-
|
41
|
-
lines = clean_lines(io.string.split("\n"))
|
42
|
-
expect(lines.length).to eq(3)
|
43
|
-
expect(lines[2]).to start_with('RuntimeError (boom) @metadata {"level":"fatal",')
|
44
|
-
expect(lines[2]).to include("\"event\":{\"error\":{\"name\":\"RuntimeError\",\"message\":\"boom\",\"backtrace_json\":\"[")
|
45
|
-
end
|
46
|
-
|
47
|
-
# Remove blank lines since Rails does this to space out requests in the logs
|
48
|
-
def clean_lines(lines)
|
49
|
-
lines.select { |line| !line.start_with?(" @metadat") }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|