loga 2.1.2 → 2.2.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.
Files changed (142) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +157 -0
  3. data/.codeclimate.yml +4 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +13 -8
  6. data/Appraisals +16 -6
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +0 -1
  9. data/Guardfile +8 -6
  10. data/README.md +1 -0
  11. data/Rakefile +1 -1
  12. data/gemfiles/rails32.gemfile +1 -2
  13. data/gemfiles/rails40.gemfile +1 -2
  14. data/gemfiles/rails42.gemfile +11 -0
  15. data/gemfiles/rails50.gemfile +1 -2
  16. data/gemfiles/rails52.gemfile +11 -0
  17. data/gemfiles/sinatra14.gemfile +1 -2
  18. data/gemfiles/unit.gemfile +1 -2
  19. data/lib/loga.rb +4 -2
  20. data/lib/loga/configuration.rb +5 -5
  21. data/lib/loga/ext/rails/rack/debug_exceptions.rb +1 -2
  22. data/lib/loga/formatters/simple_formatter.rb +1 -1
  23. data/lib/loga/log_subscribers/action_mailer.rb +59 -0
  24. data/lib/loga/rack/logger.rb +1 -1
  25. data/lib/loga/rack/request_id.rb +2 -2
  26. data/lib/loga/railtie.rb +22 -9
  27. data/lib/loga/version.rb +1 -1
  28. data/loga.gemspec +9 -8
  29. data/spec/fixtures/README.md +23 -3
  30. data/spec/fixtures/rails32.rb +79 -0
  31. data/spec/fixtures/rails40.rb +80 -0
  32. data/spec/fixtures/rails42.rb +80 -0
  33. data/spec/fixtures/rails50.rb +80 -0
  34. data/spec/fixtures/rails52.rb +80 -0
  35. data/spec/integration/rails/action_mailer_spec.rb +63 -0
  36. data/spec/integration/rails/railtie_spec.rb +15 -0
  37. data/spec/integration/sinatra_spec.rb +2 -2
  38. data/spec/spec_helper.rb +7 -8
  39. data/spec/support/gethostname_shared.rb +7 -0
  40. data/spec/support/helpers.rb +0 -4
  41. data/spec/unit/loga/configuration_spec.rb +4 -4
  42. data/spec/unit/loga/formatters/gelf_formatter_spec.rb +1 -1
  43. data/spec/unit/loga/formatters/simple_formatter_spec.rb +2 -2
  44. data/spec/unit/loga/log_subscribers/action_mailer_spec.rb +69 -0
  45. data/spec/unit/loga/rack/logger_spec.rb +1 -1
  46. data/spec/unit/loga_spec.rb +1 -1
  47. metadata +71 -225
  48. data/circle.yml +0 -23
  49. data/spec/fixtures/rails32/Rakefile +0 -7
  50. data/spec/fixtures/rails32/app/controllers/application_controller.rb +0 -28
  51. data/spec/fixtures/rails32/app/helpers/application_helper.rb +0 -2
  52. data/spec/fixtures/rails32/app/views/layouts/application.html.erb +0 -14
  53. data/spec/fixtures/rails32/app/views/user.html.erb +0 -1
  54. data/spec/fixtures/rails32/config.ru +0 -4
  55. data/spec/fixtures/rails32/config/application.rb +0 -71
  56. data/spec/fixtures/rails32/config/boot.rb +0 -6
  57. data/spec/fixtures/rails32/config/environment.rb +0 -5
  58. data/spec/fixtures/rails32/config/environments/development.rb +0 -26
  59. data/spec/fixtures/rails32/config/environments/production.rb +0 -50
  60. data/spec/fixtures/rails32/config/environments/test.rb +0 -35
  61. data/spec/fixtures/rails32/config/initializers/backtrace_silencers.rb +0 -7
  62. data/spec/fixtures/rails32/config/initializers/inflections.rb +0 -15
  63. data/spec/fixtures/rails32/config/initializers/mime_types.rb +0 -5
  64. data/spec/fixtures/rails32/config/initializers/secret_token.rb +0 -7
  65. data/spec/fixtures/rails32/config/initializers/session_store.rb +0 -8
  66. data/spec/fixtures/rails32/config/initializers/wrap_parameters.rb +0 -10
  67. data/spec/fixtures/rails32/config/locales/en.yml +0 -5
  68. data/spec/fixtures/rails32/config/routes.rb +0 -64
  69. data/spec/fixtures/rails32/public/404.html +0 -26
  70. data/spec/fixtures/rails32/public/422.html +0 -26
  71. data/spec/fixtures/rails32/public/500.html +0 -25
  72. data/spec/fixtures/rails32/public/favicon.ico +0 -0
  73. data/spec/fixtures/rails32/public/index.html +0 -241
  74. data/spec/fixtures/rails32/public/robots.txt +0 -5
  75. data/spec/fixtures/rails32/script/rails +0 -6
  76. data/spec/fixtures/rails40/Rakefile +0 -6
  77. data/spec/fixtures/rails40/app/controllers/application_controller.rb +0 -30
  78. data/spec/fixtures/rails40/app/helpers/application_helper.rb +0 -2
  79. data/spec/fixtures/rails40/app/views/layouts/application.html.erb +0 -14
  80. data/spec/fixtures/rails40/app/views/user.html.erb +0 -1
  81. data/spec/fixtures/rails40/bin/bundle +0 -3
  82. data/spec/fixtures/rails40/bin/rails +0 -4
  83. data/spec/fixtures/rails40/bin/rake +0 -4
  84. data/spec/fixtures/rails40/config.ru +0 -4
  85. data/spec/fixtures/rails40/config/application.rb +0 -37
  86. data/spec/fixtures/rails40/config/boot.rb +0 -4
  87. data/spec/fixtures/rails40/config/environment.rb +0 -5
  88. data/spec/fixtures/rails40/config/environments/development.rb +0 -24
  89. data/spec/fixtures/rails40/config/environments/production.rb +0 -65
  90. data/spec/fixtures/rails40/config/environments/test.rb +0 -39
  91. data/spec/fixtures/rails40/config/initializers/backtrace_silencers.rb +0 -7
  92. data/spec/fixtures/rails40/config/initializers/filter_parameter_logging.rb +0 -4
  93. data/spec/fixtures/rails40/config/initializers/inflections.rb +0 -16
  94. data/spec/fixtures/rails40/config/initializers/mime_types.rb +0 -5
  95. data/spec/fixtures/rails40/config/initializers/secret_token.rb +0 -12
  96. data/spec/fixtures/rails40/config/initializers/session_store.rb +0 -3
  97. data/spec/fixtures/rails40/config/initializers/wrap_parameters.rb +0 -9
  98. data/spec/fixtures/rails40/config/locales/en.yml +0 -23
  99. data/spec/fixtures/rails40/config/routes.rb +0 -62
  100. data/spec/fixtures/rails40/public/404.html +0 -58
  101. data/spec/fixtures/rails40/public/422.html +0 -58
  102. data/spec/fixtures/rails40/public/500.html +0 -57
  103. data/spec/fixtures/rails40/public/favicon.ico +0 -0
  104. data/spec/fixtures/rails40/public/robots.txt +0 -5
  105. data/spec/fixtures/rails50/Rakefile +0 -6
  106. data/spec/fixtures/rails50/app/controllers/application_controller.rb +0 -28
  107. data/spec/fixtures/rails50/app/helpers/application_helper.rb +0 -2
  108. data/spec/fixtures/rails50/app/views/layouts/application.html.erb +0 -13
  109. data/spec/fixtures/rails50/app/views/user.html.erb +0 -1
  110. data/spec/fixtures/rails50/bin/bundle +0 -3
  111. data/spec/fixtures/rails50/bin/rails +0 -4
  112. data/spec/fixtures/rails50/bin/rake +0 -4
  113. data/spec/fixtures/rails50/bin/setup +0 -34
  114. data/spec/fixtures/rails50/bin/update +0 -29
  115. data/spec/fixtures/rails50/config.ru +0 -5
  116. data/spec/fixtures/rails50/config/application.rb +0 -34
  117. data/spec/fixtures/rails50/config/boot.rb +0 -3
  118. data/spec/fixtures/rails50/config/cable.yml +0 -9
  119. data/spec/fixtures/rails50/config/environment.rb +0 -5
  120. data/spec/fixtures/rails50/config/environments/development.rb +0 -44
  121. data/spec/fixtures/rails50/config/environments/production.rb +0 -75
  122. data/spec/fixtures/rails50/config/environments/test.rb +0 -42
  123. data/spec/fixtures/rails50/config/initializers/application_controller_renderer.rb +0 -6
  124. data/spec/fixtures/rails50/config/initializers/backtrace_silencers.rb +0 -7
  125. data/spec/fixtures/rails50/config/initializers/cookies_serializer.rb +0 -5
  126. data/spec/fixtures/rails50/config/initializers/filter_parameter_logging.rb +0 -4
  127. data/spec/fixtures/rails50/config/initializers/inflections.rb +0 -16
  128. data/spec/fixtures/rails50/config/initializers/mime_types.rb +0 -4
  129. data/spec/fixtures/rails50/config/initializers/new_framework_defaults.rb +0 -21
  130. data/spec/fixtures/rails50/config/initializers/session_store.rb +0 -3
  131. data/spec/fixtures/rails50/config/initializers/wrap_parameters.rb +0 -9
  132. data/spec/fixtures/rails50/config/locales/en.yml +0 -23
  133. data/spec/fixtures/rails50/config/puma.rb +0 -47
  134. data/spec/fixtures/rails50/config/routes.rb +0 -9
  135. data/spec/fixtures/rails50/config/secrets.yml +0 -23
  136. data/spec/fixtures/rails50/public/404.html +0 -67
  137. data/spec/fixtures/rails50/public/422.html +0 -67
  138. data/spec/fixtures/rails50/public/500.html +0 -66
  139. data/spec/fixtures/rails50/public/apple-touch-icon-precomposed.png +0 -0
  140. data/spec/fixtures/rails50/public/apple-touch-icon.png +0 -0
  141. data/spec/fixtures/rails50/public/favicon.ico +0 -0
  142. data/spec/fixtures/rails50/public/robots.txt +0 -5
@@ -2,7 +2,6 @@ module ActionDispatch
2
2
  class DebugExceptions
3
3
  private
4
4
 
5
- def logger(_request)
6
- end
5
+ def logger(_request); end
7
6
  end
8
7
  end
@@ -29,7 +29,7 @@ module Loga
29
29
  def compute_event_message(event)
30
30
  components = [event.message]
31
31
 
32
- %i(type data exception).each do |attr|
32
+ %i[type data exception].each do |attr|
33
33
  if event.public_send(attr)
34
34
  components.push "#{attr}=#{event.public_send(attr)}"
35
35
  end
@@ -0,0 +1,59 @@
1
+ module Loga
2
+ module LogSubscribers
3
+ # Loga::LogSubscribers::ActionMailer tracks the three
4
+ # mailing events: 'process', 'deliver' and 'receive', and
5
+ # builds a loga event instance for each particular invocation.
6
+ class ActionMailer < ActiveSupport::LogSubscriber
7
+ def deliver(event)
8
+ mailer = event.payload[:mailer]
9
+ recipients = event.payload[:to].join(',')
10
+ unique_id = event.payload[:unique_id]
11
+ duration = event.duration.round(1)
12
+ message = "#{mailer}: Sent mail to #{recipients} in (#{duration}ms)"
13
+
14
+ loga_event = Event.new(
15
+ data: { mailer: mailer, unique_id: unique_id },
16
+ message: message,
17
+ type: 'action_mailer',
18
+ )
19
+
20
+ logger.info(loga_event)
21
+ end
22
+
23
+ def process(event)
24
+ mailer = event.payload[:mailer]
25
+ action = event.payload[:action]
26
+ unique_id = event.payload[:unique_id]
27
+ duration = event.duration.round(1)
28
+
29
+ message = "#{mailer}##{action}: Processed outbound mail in (#{duration}ms)"
30
+
31
+ loga_event = Event.new(
32
+ data: { mailer: mailer, unique_id: unique_id, action: action },
33
+ message: message,
34
+ type: 'action_mailer',
35
+ )
36
+
37
+ logger.debug(loga_event)
38
+ end
39
+
40
+ def receive(event)
41
+ from = event.payload[:from]
42
+ mailer = event.payload[:mailer]
43
+ unique_id = event.payload[:unique_id]
44
+
45
+ loga_event = Event.new(
46
+ data: { mailer: mailer, unique_id: unique_id },
47
+ message: "Received mail #{from} in (#{event.duration.round(1)}ms)",
48
+ type: 'action_mailer',
49
+ )
50
+
51
+ logger.info(loga_event)
52
+ end
53
+
54
+ def logger
55
+ Loga.logger
56
+ end
57
+ end
58
+ end
59
+ end
@@ -63,7 +63,7 @@ module Loga
63
63
  end
64
64
 
65
65
  def compute_message
66
- '%{method} %{filtered_full_path} %{status} in %{duration}ms' % {
66
+ '%<method>s %<filtered_full_path>s %<status>d in %<duration>dms' % {
67
67
  method: request.request_method,
68
68
  filtered_full_path: request.filtered_full_path,
69
69
  status: data['status'],
@@ -3,7 +3,7 @@ require 'securerandom'
3
3
  require 'active_support/core_ext/string/access'
4
4
  require 'active_support/core_ext/object/blank'
5
5
 
6
- # rubocop:disable Metrics/LineLength, Lint/AssignmentInCondition
6
+ # rubocop:disable Lint/AssignmentInCondition, Metrics/LineLength, Style/GuardClause
7
7
  module Loga
8
8
  module Rack
9
9
  # Makes a unique request id available to the action_dispatch.request_id env variable (which is then accessible through
@@ -41,4 +41,4 @@ module Loga
41
41
  end
42
42
  end
43
43
  end
44
- # rubocop:enable Metrics/LineLength, Lint/AssignmentInCondition, Style/GuardClause
44
+ # rubocop:enable Lint/AssignmentInCondition, Metrics/LineLength, Style/GuardClause
@@ -1,4 +1,5 @@
1
1
  require 'loga'
2
+ require 'loga/log_subscribers/action_mailer'
2
3
 
3
4
  module Loga
4
5
  class Railtie < Rails::Railtie
@@ -153,29 +154,41 @@ module Loga
153
154
 
154
155
  def call
155
156
  ensure_subscriptions_attached
157
+ subscribe_to_action_mailer
156
158
  remove_log_subscriptions
157
159
  end
158
160
 
159
161
  private
160
162
 
163
+ def subscribe_to_action_mailer
164
+ LogSubscribers::ActionMailer.attach_to(:action_mailer)
165
+ end
166
+
161
167
  # Ensure LogSubscribers are attached when available
162
168
  def ensure_subscriptions_attached
163
169
  ActionView::Base if defined?(ActionView::Base)
164
170
  ActionController::Base if defined?(ActionController::Base)
171
+ ActionMailer::Base if defined?(ActionMailer::Base)
165
172
  end
166
173
 
167
- # rubocop:disable Metrics/LineLength
168
174
  def remove_log_subscriptions
169
175
  ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
170
- case subscriber
171
- when defined?(ActionView::LogSubscriber) && ActionView::LogSubscriber
172
- unsubscribe(:action_view, subscriber)
173
- when defined?(ActionController::LogSubscriber) && ActionController::LogSubscriber
174
- unsubscribe(:action_controller, subscriber)
175
- end
176
+ component = log_subscription_component(subscriber)
177
+
178
+ unsubscribe(component, subscriber)
179
+ end
180
+ end
181
+
182
+ def log_subscription_component(subscriber) # rubocop:disable CyclomaticComplexity
183
+ case subscriber
184
+ when defined?(ActionView::LogSubscriber) && ActionView::LogSubscriber
185
+ :action_view
186
+ when defined?(ActionController::LogSubscriber) && ActionController::LogSubscriber
187
+ :action_controller
188
+ when defined?(ActionMailer::LogSubscriber) && ActionMailer::LogSubscriber
189
+ :action_mailer
176
190
  end
177
191
  end
178
- # rubocop:enable Metrics/LineLength
179
192
 
180
193
  def unsubscribe(component, subscriber)
181
194
  events = subscriber
@@ -187,7 +200,7 @@ module Loga
187
200
  .listeners_for("#{event}.#{component}")
188
201
  .each do |listener|
189
202
  if listener.instance_variable_get('@delegate') == subscriber
190
- ActiveSupport::Notifications.unsubscribe listener
203
+ ActiveSupport::Notifications.unsubscribe(listener)
191
204
  end
192
205
  end
193
206
  end
@@ -1,3 +1,3 @@
1
1
  module Loga
2
- VERSION = '2.1.2'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'loga/version'
@@ -21,15 +21,16 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'activesupport', '>= 2.3.8'
22
22
  spec.add_dependency 'rack'
23
23
 
24
- spec.add_development_dependency 'appraisal', '~> 2.0.2'
25
- spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'appraisal', '~> 2.2.0'
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'byebug'
27
+ spec.add_development_dependency 'guard', '~> 2.13'
28
+ spec.add_development_dependency 'guard-rspec', '~> 4.7.3'
29
+ spec.add_development_dependency 'guard-rubocop', '~> 1.2'
26
30
  spec.add_development_dependency 'pry'
27
31
  spec.add_development_dependency 'rack-test'
28
32
  spec.add_development_dependency 'rake'
29
- spec.add_development_dependency 'rspec', '~> 3.5.0'
30
- spec.add_development_dependency 'rubocop', '~> 0.40.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.6.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.50.0'
31
35
  spec.add_development_dependency 'timecop'
32
- spec.add_development_dependency 'guard', '~> 2.13'
33
- spec.add_development_dependency 'guard-rubocop', '~> 1.2'
34
- spec.add_development_dependency 'guard-rspec', '~> 4.7.3'
35
36
  end
@@ -1,11 +1,31 @@
1
1
  # Generating fixture Apps
2
2
 
3
3
  ## Rails 3.2
4
- `appraisal rails32 rails new spec/fixtures/rails32 --skip-gemfile --skip-git --skip-active-record --skip-sprockets --skip-javascript --skip-test-unit`
5
4
 
5
+ ```
6
+ appraisal rails32 rails new spec/fixtures/rails32 --skip-gemfile --skip-git --skip-active-record --skip-sprockets --skip-javascript --skip-test-unit
7
+ ```
6
8
 
7
9
  ## Rails 4.0
8
- `appraisal rails40 rails new spec/fixtures/rails40 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit`
10
+
11
+ ```
12
+ appraisal rails40 rails new spec/fixtures/rails40 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit
13
+ ```
14
+
15
+ ## Rails 4.2
16
+
17
+ ```
18
+ appraisal rails42 rails new spec/fixtures/rails42 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit
19
+ ```
9
20
 
10
21
  ## Rails 5.0
11
- `appraisal rails50 rails new spec/fixtures/rails50 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit`
22
+
23
+ ```
24
+ appraisal rails50 rails new spec/fixtures/rails50 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit
25
+ ```
26
+
27
+ ## Rails 5.2
28
+
29
+ ```
30
+ appraisal rails52 rails new spec/fixtures/rails52 --skip-gemfile --skip-git --skip-keeps --skip-active-record --skip-action-view --skip-sprockets --skip-spring --skip-javascript --skip-test-unit
31
+ ```
@@ -0,0 +1,79 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_mailer/railtie'
3
+
4
+ Bundler.require(*Rails.groups(assets: %w[development test]))
5
+
6
+ STREAM = StringIO.new unless defined?(STREAM)
7
+
8
+ class Dummy < Rails::Application
9
+ config.filter_parameters += [:password]
10
+ config.secret_token = '32431967aed1c4357d311f27708a1837a938f07e0abfdefa6b8b398d7024c08c6b883ce9254cdd8573ce8e78f9dd192efff39395127811040fc695ab23677452'
11
+ config.session_store :cookie_store, key: '_rails32_session'
12
+
13
+ config.log_tags = [:uuid, 'TEST_TAG']
14
+ config.loga = {
15
+ device: STREAM,
16
+ host: 'bird.example.com',
17
+ service_name: 'hello_world_app',
18
+ service_version: '1.0',
19
+ }
20
+ config.action_mailer.delivery_method = :test
21
+ end
22
+
23
+ class ApplicationController < ActionController::Base
24
+ include Rails.application.routes.url_helpers
25
+ protect_from_forgery
26
+
27
+ def ok
28
+ render text: 'Hello Rails'
29
+ end
30
+
31
+ def error
32
+ nil.name
33
+ end
34
+
35
+ def show
36
+ render json: params
37
+ end
38
+
39
+ def create
40
+ render json: params
41
+ end
42
+
43
+ def new
44
+ redirect_to :ok
45
+ end
46
+
47
+ def update
48
+ @id = params[:id]
49
+ render '/user'
50
+ end
51
+ end
52
+
53
+ class FakeMailer < ActionMailer::Base
54
+ default from: 'notifications@example.com'
55
+
56
+ def self.send_email
57
+ basic_mail.deliver
58
+ end
59
+
60
+ def basic_mail
61
+ mail(
62
+ to: 'user@example.com',
63
+ subject: 'Welcome to My Awesome Site',
64
+ body: 'Banana muffin',
65
+ content_type: 'text/html',
66
+ )
67
+ end
68
+ end
69
+
70
+ Dummy.routes.append do
71
+ get 'ok' => 'application#ok'
72
+ get 'error' => 'application#error'
73
+ get 'show' => 'application#show'
74
+ post 'users' => 'application#create'
75
+ get 'new' => 'application#new'
76
+ put 'users/:id' => 'application#update'
77
+ end
78
+
79
+ Dummy.initialize!
@@ -0,0 +1,80 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_mailer/railtie'
3
+
4
+ Bundler.require(*Rails.groups)
5
+
6
+ STREAM = StringIO.new unless defined?(STREAM)
7
+
8
+ class Dummy < Rails::Application
9
+ config.eager_load = true
10
+ config.filter_parameters += [:password]
11
+ config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24'
12
+ config.session_store :cookie_store, key: '_rails40_session'
13
+
14
+ config.log_tags = [:uuid, 'TEST_TAG']
15
+ config.loga = {
16
+ device: STREAM,
17
+ host: 'bird.example.com',
18
+ service_name: 'hello_world_app',
19
+ service_version: '1.0',
20
+ }
21
+ config.action_mailer.delivery_method = :test
22
+ end
23
+
24
+ class ApplicationController < ActionController::Base
25
+ include Rails.application.routes.url_helpers
26
+ protect_from_forgery
27
+
28
+ def ok
29
+ render text: 'Hello Rails'
30
+ end
31
+
32
+ def error
33
+ nil.name
34
+ end
35
+
36
+ def show
37
+ render json: params
38
+ end
39
+
40
+ def create
41
+ render json: params
42
+ end
43
+
44
+ def new
45
+ redirect_to :ok
46
+ end
47
+
48
+ def update
49
+ @id = params[:id]
50
+ render '/user'
51
+ end
52
+ end
53
+
54
+ class FakeMailer < ActionMailer::Base
55
+ default from: 'notifications@example.com'
56
+
57
+ def self.send_email
58
+ basic_mail.deliver
59
+ end
60
+
61
+ def basic_mail
62
+ mail(
63
+ to: 'user@example.com',
64
+ subject: 'Welcome to My Awesome Site',
65
+ body: 'Banana muffin',
66
+ content_type: 'text/html',
67
+ )
68
+ end
69
+ end
70
+
71
+ Dummy.routes.append do
72
+ get 'ok' => 'application#ok'
73
+ get 'error' => 'application#error'
74
+ get 'show' => 'application#show'
75
+ post 'users' => 'application#create'
76
+ get 'new' => 'application#new'
77
+ put 'users/:id' => 'application#update'
78
+ end
79
+
80
+ Dummy.initialize!
@@ -0,0 +1,80 @@
1
+ require 'action_controller/railtie'
2
+ require 'action_mailer/railtie'
3
+
4
+ Bundler.require(*Rails.groups)
5
+
6
+ STREAM = StringIO.new unless defined?(STREAM)
7
+
8
+ class Dummy < Rails::Application
9
+ config.eager_load = true
10
+ config.filter_parameters += [:password]
11
+ config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24'
12
+ config.session_store :cookie_store, key: '_rails42_session'
13
+
14
+ config.log_tags = [:uuid, 'TEST_TAG']
15
+ config.loga = {
16
+ device: STREAM,
17
+ host: 'bird.example.com',
18
+ service_name: 'hello_world_app',
19
+ service_version: '1.0',
20
+ }
21
+ config.action_mailer.delivery_method = :test
22
+ end
23
+
24
+ class ApplicationController < ActionController::Base
25
+ include Rails.application.routes.url_helpers
26
+ protect_from_forgery
27
+
28
+ def ok
29
+ render text: 'Hello Rails'
30
+ end
31
+
32
+ def error
33
+ nil.name
34
+ end
35
+
36
+ def show
37
+ render json: params
38
+ end
39
+
40
+ def create
41
+ render json: params
42
+ end
43
+
44
+ def new
45
+ redirect_to :ok
46
+ end
47
+
48
+ def update
49
+ @id = params[:id]
50
+ render '/user'
51
+ end
52
+ end
53
+
54
+ class FakeMailer < ActionMailer::Base
55
+ default from: 'notifications@example.com'
56
+
57
+ def self.send_email
58
+ basic_mail.deliver_now
59
+ end
60
+
61
+ def basic_mail
62
+ mail(
63
+ to: 'user@example.com',
64
+ subject: 'Welcome to My Awesome Site',
65
+ body: 'Banana muffin',
66
+ content_type: 'text/html',
67
+ )
68
+ end
69
+ end
70
+
71
+ Dummy.routes.append do
72
+ get 'ok' => 'application#ok'
73
+ get 'error' => 'application#error'
74
+ get 'show' => 'application#show'
75
+ post 'users' => 'application#create'
76
+ get 'new' => 'application#new'
77
+ put 'users/:id' => 'application#update'
78
+ end
79
+
80
+ Dummy.initialize!