timber 2.6.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +8 -38
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +30 -284
  5. data/Rakefile +78 -0
  6. data/lib/timber.rb +6 -6
  7. data/lib/timber/config.rb +1 -83
  8. data/lib/timber/config/integrations.rb +1 -47
  9. data/lib/timber/context.rb +3 -24
  10. data/lib/timber/contexts.rb +2 -30
  11. data/lib/timber/contexts/http.rb +16 -36
  12. data/lib/timber/contexts/release.rb +12 -23
  13. data/lib/timber/contexts/runtime.rb +9 -36
  14. data/lib/timber/contexts/session.rb +8 -21
  15. data/lib/timber/contexts/system.rb +9 -16
  16. data/lib/timber/contexts/user.rb +13 -33
  17. data/lib/timber/current_context.rb +16 -78
  18. data/lib/timber/event.rb +12 -9
  19. data/lib/timber/events.rb +1 -33
  20. data/lib/timber/events/controller_call.rb +20 -31
  21. data/lib/timber/events/error.rb +18 -26
  22. data/lib/timber/events/exception.rb +1 -0
  23. data/lib/timber/events/sql_query.rb +14 -24
  24. data/lib/timber/events/template_render.rb +13 -24
  25. data/lib/timber/integration.rb +1 -1
  26. data/lib/timber/integrator.rb +1 -1
  27. data/lib/timber/log_devices/http.rb +98 -19
  28. data/lib/timber/log_entry.rb +6 -24
  29. data/lib/timber/logger.rb +5 -14
  30. data/lib/timber/util.rb +1 -6
  31. data/lib/timber/util/non_nil_hash_builder.rb +3 -1
  32. data/lib/timber/version.rb +1 -1
  33. data/spec/README.md +2 -8
  34. data/spec/spec_helper.rb +0 -7
  35. data/spec/support/timber.rb +1 -3
  36. data/spec/timber/current_context_spec.rb +12 -50
  37. data/spec/timber/events/controller_call_spec.rb +4 -4
  38. data/spec/timber/events/error_spec.rb +4 -9
  39. data/spec/timber/log_devices/http_spec.rb +26 -2
  40. data/spec/timber/log_entry_spec.rb +12 -6
  41. data/spec/timber/logger_spec.rb +27 -68
  42. data/timber.gemspec +1 -1
  43. metadata +5 -139
  44. data/gemfiles/rails-3.0.gemfile +0 -5
  45. data/gemfiles/rails-3.1.gemfile +0 -5
  46. data/gemfiles/rails-3.2.gemfile +0 -5
  47. data/gemfiles/rails-4.0.gemfile +0 -9
  48. data/gemfiles/rails-4.1.gemfile +0 -9
  49. data/gemfiles/rails-4.2.gemfile +0 -9
  50. data/gemfiles/rails-5.0.gemfile +0 -9
  51. data/gemfiles/rails-5.1.gemfile +0 -9
  52. data/gemfiles/rails-edge.gemfile +0 -7
  53. data/lib/timber/cli.rb +0 -60
  54. data/lib/timber/cli/api.rb +0 -183
  55. data/lib/timber/cli/api/application.rb +0 -34
  56. data/lib/timber/cli/config_file.rb +0 -71
  57. data/lib/timber/cli/file_helper.rb +0 -53
  58. data/lib/timber/cli/installer.rb +0 -70
  59. data/lib/timber/cli/installers.rb +0 -102
  60. data/lib/timber/cli/installers/config_file.rb +0 -51
  61. data/lib/timber/cli/installers/other.rb +0 -59
  62. data/lib/timber/cli/installers/rails.rb +0 -225
  63. data/lib/timber/cli/installers/root.rb +0 -116
  64. data/lib/timber/cli/io.rb +0 -100
  65. data/lib/timber/cli/io/ansi.rb +0 -22
  66. data/lib/timber/cli/io/messages.rb +0 -198
  67. data/lib/timber/cli/os_helper.rb +0 -74
  68. data/lib/timber/config/integrations/rack.rb +0 -74
  69. data/lib/timber/contexts/custom.rb +0 -44
  70. data/lib/timber/contexts/organization.rb +0 -48
  71. data/lib/timber/events/custom.rb +0 -53
  72. data/lib/timber/events/http_request.rb +0 -71
  73. data/lib/timber/events/http_response.rb +0 -81
  74. data/lib/timber/frameworks.rb +0 -19
  75. data/lib/timber/frameworks/rails.rb +0 -27
  76. data/lib/timber/integrations.rb +0 -29
  77. data/lib/timber/integrations/action_controller.rb +0 -18
  78. data/lib/timber/integrations/action_controller/log_subscriber.rb +0 -27
  79. data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +0 -46
  80. data/lib/timber/integrations/action_dispatch.rb +0 -23
  81. data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +0 -53
  82. data/lib/timber/integrations/action_view.rb +0 -18
  83. data/lib/timber/integrations/action_view/log_subscriber.rb +0 -27
  84. data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +0 -83
  85. data/lib/timber/integrations/active_record.rb +0 -18
  86. data/lib/timber/integrations/active_record/log_subscriber.rb +0 -26
  87. data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +0 -53
  88. data/lib/timber/integrations/rack.rb +0 -27
  89. data/lib/timber/integrations/rack/error_event.rb +0 -64
  90. data/lib/timber/integrations/rack/http_context.rb +0 -27
  91. data/lib/timber/integrations/rack/http_events.rb +0 -210
  92. data/lib/timber/integrations/rack/middleware.rb +0 -28
  93. data/lib/timber/integrations/rack/session_context.rb +0 -65
  94. data/lib/timber/integrations/rack/user_context.rb +0 -135
  95. data/lib/timber/integrations/rails.rb +0 -22
  96. data/lib/timber/integrations/rails/rack_logger.rb +0 -60
  97. data/lib/timber/overrides.rb +0 -12
  98. data/lib/timber/overrides/active_support_3_tagged_logging.rb +0 -111
  99. data/lib/timber/overrides/active_support_buffered_logger.rb +0 -22
  100. data/lib/timber/overrides/active_support_tagged_logging.rb +0 -66
  101. data/lib/timber/overrides/lograge.rb +0 -18
  102. data/lib/timber/overrides/rails_stdout_logging.rb +0 -21
  103. data/lib/timber/util/active_support_log_subscriber.rb +0 -37
  104. data/lib/timber/util/attribute_normalizer.rb +0 -89
  105. data/lib/timber/util/hash.rb +0 -90
  106. data/lib/timber/util/request.rb +0 -72
  107. data/lib/timber/util/struct.rb +0 -16
  108. data/spec/rails/tagged_logging_spec.rb +0 -44
  109. data/spec/support/action_controller.rb +0 -8
  110. data/spec/support/active_record.rb +0 -32
  111. data/spec/support/rails.rb +0 -67
  112. data/spec/support/rails/templates/_partial.html +0 -1
  113. data/spec/support/rails/templates/template.html +0 -1
  114. data/spec/timber/cli/config_file_spec.rb +0 -26
  115. data/spec/timber/cli/installers/config_file_spec.rb +0 -36
  116. data/spec/timber/cli/installers/other_spec.rb +0 -49
  117. data/spec/timber/cli/installers/rails_spec.rb +0 -364
  118. data/spec/timber/cli/installers/root_spec.rb +0 -73
  119. data/spec/timber/config_spec.rb +0 -28
  120. data/spec/timber/contexts/custom_spec.rb +0 -11
  121. data/spec/timber/contexts/organization_spec.rb +0 -11
  122. data/spec/timber/contexts/runtime_spec.rb +0 -11
  123. data/spec/timber/contexts/system_spec.rb +0 -11
  124. data/spec/timber/contexts/user_spec.rb +0 -11
  125. data/spec/timber/contexts_spec.rb +0 -49
  126. data/spec/timber/event_spec.rb +0 -10
  127. data/spec/timber/events/custom_spec.rb +0 -36
  128. data/spec/timber/events/http_request_spec.rb +0 -32
  129. data/spec/timber/events/http_response_spec.rb +0 -12
  130. data/spec/timber/events_spec.rb +0 -55
  131. data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +0 -55
  132. data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +0 -53
  133. data/spec/timber/integrations/action_view/log_subscriber_spec.rb +0 -115
  134. data/spec/timber/integrations/active_record/log_subscriber_spec.rb +0 -46
  135. data/spec/timber/integrations/rack/error_event_spec.rb +0 -63
  136. data/spec/timber/integrations/rack/http_context_spec.rb +0 -60
  137. data/spec/timber/integrations/rack/http_events_spec.rb +0 -101
  138. data/spec/timber/integrations/rack/session_context_spec.rb +0 -62
  139. data/spec/timber/integrations/rails/rack_logger_spec.rb +0 -58
  140. data/spec/timber/util/attribute_normalizer_spec.rb +0 -90
  141. data/spec/timber/util/hash_spec.rb +0 -30
  142. data/spec/timber/util/request_spec.rb +0 -10
@@ -1,8 +0,0 @@
1
- begin
2
- require "action_controller"
3
- rescue LoadError
4
- end
5
-
6
- if defined?(::ActionController::Base)
7
- ::ActionController::Base.prepend_view_path("#{File.dirname(__FILE__)}/rails/templates")
8
- end
@@ -1,32 +0,0 @@
1
- begin
2
- require 'active_record'
3
- rescue LoadError
4
- end
5
-
6
- if defined?(::ActiveRecord::Base)
7
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
8
- ActiveRecord::Schema.define do
9
- self.verbose = false
10
-
11
- create_table :organizations, :force => true do |t|
12
- t.string :name
13
-
14
- t.timestamps :null => false
15
- end
16
-
17
- create_table :users, :force => true do |t|
18
- t.integer :age
19
- t.string :email
20
- t.string :first_name
21
-
22
- t.timestamps :null => false
23
- end
24
-
25
- end
26
-
27
- class Organization < ::ActiveRecord::Base
28
- end
29
-
30
- class User < ::ActiveRecord::Base
31
- end
32
- end
@@ -1,67 +0,0 @@
1
- begin
2
- require "rails"
3
- rescue LoadError
4
- end
5
-
6
- if defined?(::Rails)
7
- # Defualt the rails logger to nothing, each test shoould be
8
- # responsible for setting up the logger
9
- logger = Timber::Logger.new(nil) # change to STDOUT to see rails logs
10
- Rails.logger = logger
11
-
12
- class RailsApp < Rails::Application
13
- if ::Rails.version =~ /^3\./
14
- config.secret_token = '1e05af2b349457936a41427e63450937'
15
- else
16
- config.secret_key_base = '1e05af2b349457936a41427e63450937'
17
- end
18
-
19
- # This ensures our tests fail, otherwise exceptions get swallowed by ActionDispatch::DebugExceptions
20
- config.action_dispatch.show_exceptions = false
21
- config.active_support.deprecation = :stderr
22
- config.eager_load = false
23
- end
24
-
25
- RailsApp.initialize!
26
-
27
- module Support
28
- module Rails
29
- def dispatch_rails_request(path, additional_env_options = {})
30
- application = ::Rails.application
31
- env = application.respond_to?(:env_config) ? application.env_config.clone : application.env_defaults.clone
32
- env["rack.request.cookie_hash"] = {}.with_indifferent_access
33
- env["CONTENT_LENGTH"] = 100
34
- env["REMOTE_ADDR"] = "123.456.789.10"
35
- env["HTTP_X_REQUEST_ID"] = "unique-request-id-1234"
36
- env["action_dispatch.request_id"] = env["HTTP_X_REQUEST_ID"]
37
- env = env.merge(additional_env_options)
38
- ::Rack::MockRequest.new(application).get(path, env)
39
- end
40
-
41
- def with_rails_logger(logger)
42
- old_logger = ::Rails.logger
43
-
44
- # We have to set these again because rails set's these after initialization.
45
- # Since we've already booted the rails app we need to update them all as we
46
- # change the logger.
47
- #
48
- # You can see here that they use simple class attribute, hence the reason we need
49
- # to update all of them: https://github.com/rails/rails/blob/700ec897f97c60016ad748236bf3a49ef15a20de/actionview/lib/action_view/base.rb#L157
50
- ::ActionCable::Server::Base.logger = logger if defined?(::ActionCable::Server::Base) && ::ActionCable::Server::Base.respond_to?(:logger=)
51
- ::ActionController::Base.logger = logger if defined?(::ActionController::Base) && ::ActionController::Base.respond_to?(:logger=)
52
- ::ActionMailer::Base.logger = logger if defined?(::ActionMailer::Base) && ::ActionMailer::Base.respond_to?(:logger=)
53
- ::ActionView::Base.logger = logger if defined?(::ActionView::Base) && ::ActionView::Base.respond_to?(:logger=)
54
- ::ActiveRecord::Base.logger = logger if defined?(::ActiveRecord::Base) && ::ActiveRecord::Base.respond_to?(:logger=)
55
- ::Rails.logger = logger
56
-
57
- yield
58
-
59
- ::Rails.logger = old_logger
60
- end
61
- end
62
- end
63
-
64
- RSpec.configure do |config|
65
- config.include Support::Rails
66
- end
67
- end
@@ -1 +0,0 @@
1
- I am a partial
@@ -1 +0,0 @@
1
- I am a template
@@ -1,26 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::CLI::ConfigFile, :rails_23 => true do
4
- let(:api) { Timber::CLI::API.new("abcd1234") }
5
- let(:file_helper) { @file_helper = Timber::CLI::FileHelper.new(api) }
6
- let(:path) { "config/initializers/timber.rb" }
7
- let(:config_file) { described_class.new(path, file_helper) }
8
- let(:initial_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For common configuration options see:\n# https://timber.io/docs/languages/ruby/configuration\n#\n# For a full list of configuration options see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }
9
- let(:contents_hook) { "# Add additional configuration here." }
10
-
11
- describe ".create!" do
12
- it "should create" do
13
- expect(config_file.file_helper).to receive(:write).with(path, initial_contents).exactly(1).times
14
- config_file.create!
15
- end
16
- end
17
-
18
- describe ".logrageify!" do
19
- it "should not set the option in the config file" do
20
- allow(config_file).to receive(:log_rage?).and_return(true)
21
- config_file.logrageify!
22
- new_contents = initial_contents.gsub(contents_hook, "config.logrageify!\n\n#{contents_hook}")
23
- expect(config_file.send(:content)).to eq(new_contents)
24
- end
25
- end
26
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::CLI::Installers::ConfigFile, :rails_23 => true do
4
- let(:api_key) { "abcd1234" }
5
- let(:app) do
6
- attributes = {
7
- "api_key" => api_key,
8
- "environment" => "development",
9
- "heroku_drain_url" => "http://drain.heroku.com",
10
- "name" => "My Rails App",
11
- "platform_type" => "other"
12
- }
13
- Timber::CLI::API::Application.new(attributes)
14
- end
15
- let(:api) { Timber::CLI::API.new(api_key) }
16
- let(:input) { StringIO.new }
17
- let(:output) { StringIO.new }
18
- let(:io) { Timber::CLI::IO.new(io_out: output, io_in: input) }
19
- let(:installer) { described_class.new(io, api) }
20
- let(:initial_config_contents) { "# Timber.io Ruby Configuration - Simple Structured Logging\n#\n# ^ ^ ^ ^ ___I_ ^ ^ ^ ^ ^ ^ ^\n# /|\\/|\\/|\\ /|\\ /\\-_--\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ / \\_-__\\ /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# /|\\/|\\/|\\ /|\\ |[]| [] | /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\\n# -------------------------------------------------------------------\n# Website: https://timber.io\n# Documentation: https://timber.io/docs\n# Support: support@timber.io\n# -------------------------------------------------------------------\n\nconfig = Timber::Config.instance\n\n# Add additional configuration here.\n# For common configuration options see:\n# https://timber.io/docs/languages/ruby/configuration\n#\n# For a full list of configuration options see:\n# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config\n\n" }
21
-
22
- describe ".run" do
23
- it "should run properly" do
24
- path = "/path/to/file"
25
- config_file = Timber::CLI::ConfigFile.new(path, installer.file_helper)
26
-
27
- expect(Timber::CLI::ConfigFile).to receive(:new).with(path, installer.file_helper).and_return(config_file)
28
- expect(config_file).to receive(:exists?).exactly(1).times.and_return(false)
29
- expect(installer).to receive(:lograge?).exactly(1).times.and_return(true)
30
- expect(config_file).to receive(:logrageify!).exactly(1).times
31
- expect(config_file).to receive(:create!).exactly(1).times
32
-
33
- installer.run(app, path)
34
- end
35
- end
36
- end
@@ -1,49 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Timber::CLI::Installers::Other, :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
- context "heroku" do
25
- before(:each) do
26
- app.platform_type = "heroku"
27
- end
28
-
29
- it "should run properly" do
30
- expect(installer).to receive(:install_stdout).exactly(1).times
31
- expect(installer).to receive(:ask_to_proceed).exactly(1).times
32
-
33
- installer.run(app)
34
- end
35
- end
36
-
37
- context "non-heroku" do
38
- it "should run properly" do
39
- api_key_code = "'#{api_key}'"
40
- expect(installer).to receive(:get_api_key_storage_preference).exactly(1).times.and_return(:inline)
41
- expect(installer).to receive(:get_api_key_code).with(:inline).exactly(1).times.and_return(api_key_code)
42
- expect(installer).to receive(:install_http).with(api_key_code).exactly(1).times
43
- expect(installer).to receive(:ask_to_proceed).exactly(1).times
44
-
45
- installer.run(app)
46
- end
47
- end
48
- end
49
- end
@@ -1,364 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::CLI::Installers::Rails, :rails_23 => true do
4
- let(:api_key) { "abcd1234" }
5
- let(:app) do
6
- attributes = {
7
- "api_key" => api_key,
8
- "environment" => "development",
9
- "heroku_drain_url" => "http://drain.heroku.com",
10
- "name" => "My Rails App",
11
- "platform_type" => "other"
12
- }
13
- Timber::CLI::API::Application.new(attributes)
14
- end
15
- let(:api) { Timber::CLI::API.new(api_key) }
16
- let(:input) { StringIO.new }
17
- let(:output) { StringIO.new }
18
- let(:io) { Timber::CLI::IO.new(io_out: output, io_in: input) }
19
- let(:installer) { described_class.new(io, api) }
20
- let(:logger_code) { defined?(ActiveSupport::TaggedLogging) ? "ActiveSupport::TaggedLogging.new(logger)" : "logger" }
21
-
22
- describe ".run" do
23
- context "development" do
24
- it "should execute properly" do
25
- expect(installer).to receive(:install_initializer).with(app).exactly(1).times
26
- expect(installer).to receive(:install_development_environment).with(app).exactly(1).times
27
- expect(installer).to receive(:install_test_environment).with(app).exactly(1).times
28
- expect(installer).to_not receive(:install_app_environment)
29
-
30
- installer.run(app)
31
- end
32
- end
33
-
34
- context "staging" do
35
- before(:each) do
36
- app.environment = "staging"
37
- end
38
-
39
- it "should execute properly" do
40
- expect(installer).to receive(:install_initializer).with(app).exactly(1).times
41
- expect(installer).to receive(:install_development_environment).with(app).exactly(1).times
42
- expect(installer).to receive(:install_test_environment).with(app).exactly(1).times
43
- expect(installer).to receive(:install_app_environment).with(app).exactly(1).times
44
-
45
- installer.run(app)
46
- end
47
- end
48
-
49
- context "production" do
50
- before(:each) do
51
- app.environment = "production"
52
- end
53
-
54
- it "should execute properly" do
55
- expect(installer).to receive(:install_initializer).with(app).exactly(1).times
56
- expect(installer).to receive(:install_development_environment).with(app).exactly(1).times
57
- expect(installer).to receive(:install_test_environment).with(app).exactly(1).times
58
- expect(installer).to receive(:install_app_environment).with(app).exactly(1).times
59
-
60
- installer.run(app)
61
- end
62
- end
63
- end
64
-
65
- describe ".install_initializer" do
66
- it "should create a config file" do
67
- config_file_path = "config/initializers/timber.rb"
68
- expect_any_instance_of(Timber::CLI::Installers::ConfigFile).to receive(:run).with(app, config_file_path).exactly(1).times
69
-
70
- installer.send(:install_initializer, app)
71
- end
72
- end
73
-
74
- describe ".install_development_environment" do
75
- let(:env_file_path) { "config/environments/development.rb" }
76
-
77
- context "env file exists" do
78
- context "not installed" do
79
- context "send logs" do
80
- it "should setup properly" do
81
- expect(installer).to receive(:get_environment_file_path).
82
- with("development").
83
- exactly(1).times.
84
- and_return(env_file_path)
85
-
86
- expect(installer).to receive(:already_installed?).
87
- with(env_file_path).
88
- exactly(1).times.
89
- and_return(false)
90
-
91
- expect(installer).to receive(:get_development_preference).
92
- with(app).
93
- exactly(1).times.
94
- and_return(:send)
95
-
96
- expected_code = <<-CODE
97
- # Install the Timber.io logger
98
- # ----------------------------
99
- # Remove the `http_device` to stop sending development logs to Timber.
100
- # Be sure to keep the `file_device` or replace it with `STDOUT`.
101
- http_device = Timber::LogDevices::HTTP.new('#{app.api_key}')
102
- file_device = File.open("\#{Rails.root}/log/development.log", "a")
103
- file_device.binmode
104
- log_devices = [http_device, file_device]
105
-
106
- # Do not modify below this line. It's important to keep the `Timber::Logger`
107
- # because it provides an API for logging structured data and capturing context.
108
- logger = Timber::Logger.new(*log_devices)
109
- logger.level = config.log_level
110
- config.logger = #{logger_code}
111
- CODE
112
-
113
- expect(installer).to receive(:install_logger).
114
- with(env_file_path, expected_code).
115
- exactly(1).times
116
-
117
- result = installer.send(:install_development_environment, app)
118
- expect(result).to eq(:http)
119
- end
120
- end
121
-
122
- context "dont send" do
123
- it "should setup properly" do
124
- expect(installer).to receive(:get_environment_file_path).
125
- with("development").
126
- exactly(1).times.
127
- and_return(env_file_path)
128
-
129
- expect(installer).to receive(:already_installed?).
130
- with(env_file_path).
131
- exactly(1).times.
132
- and_return(false)
133
-
134
- expect(installer).to receive(:get_development_preference).
135
- with(app).
136
- exactly(1).times.
137
- and_return(:dont_send)
138
-
139
- expect(installer).to receive(:install_stdout).
140
- with(env_file_path).
141
- exactly(1).times
142
-
143
- result = installer.send(:install_development_environment, app)
144
- expect(result).to eq(:stdout)
145
- end
146
- end
147
- end
148
-
149
- context "installed" do
150
- it "should skip" do
151
- expect(installer).to receive(:get_environment_file_path).
152
- with("development").
153
- exactly(1).times.
154
- and_return(env_file_path)
155
-
156
- expect(installer).to receive(:already_installed?).
157
- with(env_file_path).
158
- exactly(1).times.
159
- and_return(true)
160
-
161
- result = installer.send(:install_development_environment, app)
162
- expect(result).to eq(:already_installed)
163
- end
164
- end
165
- end
166
- end
167
-
168
- describe ".install_test_environment" do
169
- let(:env_file_path) { "config/environments/test.rb" }
170
-
171
- context "env file exists" do
172
- context "not installed" do
173
- it "should setup properly" do
174
- expect(installer).to receive(:get_environment_file_path).
175
- with("test").
176
- exactly(1).times.
177
- and_return(env_file_path)
178
-
179
- expect(installer).to receive(:already_installed?).
180
- with(env_file_path).
181
- exactly(1).times.
182
- and_return(false)
183
-
184
- expect(installer).to receive(:install_nil).
185
- with(env_file_path).
186
- exactly(1).times
187
-
188
- result = installer.send(:install_test_environment, app)
189
- expect(result).to eq(:nil)
190
- end
191
- end
192
-
193
- context "installed" do
194
- it "should skip" do
195
- expect(installer).to receive(:get_environment_file_path).
196
- with("test").
197
- exactly(1).times.
198
- and_return(env_file_path)
199
-
200
- expect(installer).to receive(:already_installed?).
201
- with(env_file_path).
202
- exactly(1).times.
203
- and_return(true)
204
-
205
- result = installer.send(:install_test_environment, app)
206
- expect(result).to eq(:already_installed)
207
- end
208
- end
209
- end
210
- end
211
-
212
- describe ".install_app_environment" do
213
- context "production" do
214
- before(:each) do
215
- app.environment = "production"
216
- end
217
-
218
- let(:env_file_path) { "config/environments/production.rb" }
219
-
220
- context "env file exists" do
221
- context "not installed" do
222
- context "http" do
223
- it "should setup properly" do
224
- expect(installer).to receive(:get_environment_file_path).
225
- with("production").
226
- exactly(1).times.
227
- and_return(env_file_path)
228
-
229
- expect(installer).to receive(:already_installed?).
230
- with(env_file_path).
231
- exactly(1).times.
232
- and_return(false)
233
-
234
- expect(installer).to receive(:get_delivery_strategy).
235
- with(app).
236
- exactly(1).times.
237
- and_return(:http)
238
-
239
- expect(installer).to receive(:get_api_key_storage_preference).
240
- exactly(1).times.
241
- and_return(:inline)
242
-
243
- expect(installer).to receive(:install_http).
244
- with(env_file_path, :inline).
245
- exactly(1).times
246
-
247
- result = installer.send(:install_app_environment, app)
248
- expect(result).to eq(:http)
249
- end
250
- end
251
-
252
- context "stdout" do
253
- it "should setup properly" do
254
- expect(installer).to receive(:get_environment_file_path).
255
- with("production").
256
- exactly(1).times.
257
- and_return(env_file_path)
258
-
259
- expect(installer).to receive(:already_installed?).
260
- with(env_file_path).
261
- exactly(1).times.
262
- and_return(false)
263
-
264
- expect(installer).to receive(:get_delivery_strategy).
265
- with(app).
266
- exactly(1).times.
267
- and_return(:stdout)
268
-
269
- expect(installer).to receive(:install_stdout).
270
- with(env_file_path).
271
- exactly(1).times
272
-
273
- result = installer.send(:install_app_environment, app)
274
- expect(result).to eq(:stdout)
275
- end
276
- end
277
- end
278
-
279
- context "installed" do
280
- it "should skip" do
281
- expect(installer).to receive(:get_environment_file_path).
282
- with("production").
283
- exactly(1).times.
284
- and_return(env_file_path)
285
-
286
- expect(installer).to receive(:already_installed?).
287
- with(env_file_path).
288
- exactly(1).times.
289
- and_return(true)
290
-
291
- result = installer.send(:install_app_environment, app)
292
- expect(result).to eq(:already_installed)
293
- end
294
- end
295
- end
296
- end
297
- end
298
-
299
- describe ".get_environment_file_path" do
300
- it "should return the file if it exists" do
301
- env_file_path = "config/environments/development.rb"
302
- expect(installer.file_helper).to receive(:exists?).with(env_file_path).exactly(1).times.and_return(true)
303
-
304
- result = installer.send(:get_environment_file_path, "development")
305
- expect(result).to eq(env_file_path)
306
- end
307
-
308
- it "should return nil if it does not exist" do
309
- env_file_path = "config/environments/production.rb"
310
- expect(installer.file_helper).to receive(:exists?).with(env_file_path).exactly(1).times.and_return(false)
311
-
312
- result = installer.send(:get_environment_file_path, "production")
313
- expect(result).to eq(nil)
314
- end
315
- end
316
-
317
- describe ".install_nil" do
318
- it "should pass the proper code" do
319
- env_file_path = "config/environments/development.rb"
320
-
321
- expected_code = <<-CODE
322
- # Install the Timber.io logger
323
- # ----------------------------
324
- # `nil` is passed to disable logging. It's important to keep the `Timber::Logger`
325
- # because it provides an API for logging structured data and capturing context.
326
- logger = Timber::Logger.new(nil)
327
- logger.level = config.log_level
328
- config.logger = #{logger_code}
329
- CODE
330
-
331
- expect(installer).to receive(:install_logger).
332
- with(env_file_path, expected_code).
333
- exactly(1).times
334
-
335
- installer.send(:install_nil, env_file_path)
336
- end
337
- end
338
-
339
- describe ".install_logger" do
340
- context "not installed" do
341
- it "should pass the proper code" do
342
- env_file_path = "config/environments/development.rb"
343
-
344
- logger_code = "my code"
345
-
346
- current_contents = "\nend"
347
-
348
- expect(installer.file_helper).to receive(:read).
349
- with(env_file_path).
350
- exactly(1).times.
351
- and_return(current_contents)
352
-
353
- new_contents = "\n\nmy code\nend"
354
-
355
- expect(installer.file_helper).to receive(:write).
356
- with(env_file_path, new_contents).
357
- exactly(1).times.
358
- and_return("\nend")
359
-
360
- installer.send(:install_logger, env_file_path, logger_code)
361
- end
362
- end
363
- end
364
- end