nunes 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +15 -7
  3. data/Changelog.md +8 -0
  4. data/Gemfile +1 -1
  5. data/README.md +2 -3
  6. data/Rakefile +10 -0
  7. data/lib/nunes.rb +12 -0
  8. data/lib/nunes/adapter.rb +4 -2
  9. data/lib/nunes/instrumentable.rb +1 -1
  10. data/lib/nunes/subscriber.rb +5 -2
  11. data/lib/nunes/subscribers/action_controller.rb +51 -24
  12. data/lib/nunes/subscribers/action_mailer.rb +2 -2
  13. data/lib/nunes/subscribers/action_view.rb +5 -2
  14. data/lib/nunes/subscribers/active_job.rb +2 -3
  15. data/lib/nunes/subscribers/active_record.rb +4 -1
  16. data/lib/nunes/version.rb +1 -1
  17. data/script/test +10 -13
  18. data/test/controller_instrumentation_test.rb +47 -5
  19. data/test/helper.rb +5 -1
  20. data/test/instrumentable_test.rb +27 -3
  21. data/test/job_instrumentation_test.rb +11 -8
  22. data/test/mailer_instrumentation_test.rb +5 -1
  23. data/test/namespaced_controller_instrumentation_test.rb +7 -7
  24. data/test/namespaced_job_instrumentation_test.rb +33 -0
  25. data/test/namespaced_mailer_instrumentation_test.rb +35 -0
  26. data/test/namespaced_model_instrumentation_test.rb +55 -0
  27. data/test/nunes_test.rb +8 -0
  28. data/test/{rails_app → rails_app_4.2.5}/.gitignore +0 -0
  29. data/test/{rails_app → rails_app_4.2.5}/Rakefile +0 -0
  30. data/test/{rails_app → rails_app_4.2.5}/app/assets/images/rails.png +0 -0
  31. data/test/{rails_app → rails_app_4.2.5}/app/assets/javascripts/application.js +0 -0
  32. data/test/{rails_app → rails_app_4.2.5}/app/assets/stylesheets/application.css +0 -0
  33. data/test/{rails_app → rails_app_4.2.5}/app/controllers/admin/posts_controller.rb +2 -7
  34. data/test/{rails_app → rails_app_4.2.5}/app/controllers/application_controller.rb +0 -0
  35. data/test/{rails_app → rails_app_4.2.5}/app/controllers/posts_controller.rb +1 -7
  36. data/test/{rails_app → rails_app_4.2.5}/app/helpers/application_helper.rb +0 -0
  37. data/test/rails_app_4.2.5/app/jobs/spam/detector_job.rb +11 -0
  38. data/test/{rails_app → rails_app_4.2.5}/app/jobs/spam_detector_job.rb +0 -0
  39. data/test/{rails_app → rails_app_4.2.5}/app/mailers/.gitkeep +0 -0
  40. data/test/rails_app_4.2.5/app/mailers/admin/post_mailer.rb +13 -0
  41. data/test/{rails_app → rails_app_4.2.5}/app/mailers/post_mailer.rb +0 -0
  42. data/test/{rails_app → rails_app_4.2.5}/app/models/.gitkeep +0 -0
  43. data/test/rails_app_4.2.5/app/models/admin/post.rb +5 -0
  44. data/test/{rails_app → rails_app_4.2.5}/app/models/post.rb +0 -0
  45. data/test/{rails_app/app/views → rails_app_4.2.5/app/views/admin}/post_mailer/created.text.erb +0 -0
  46. data/test/{rails_app → rails_app_4.2.5}/app/views/admin/posts/index.html.erb +0 -0
  47. data/test/{rails_app → rails_app_4.2.5}/app/views/layouts/application.html.erb +0 -0
  48. data/test/rails_app_4.2.5/app/views/post_mailer/created.text.erb +1 -0
  49. data/test/{rails_app → rails_app_4.2.5}/app/views/posts/_post.html.erb +0 -0
  50. data/test/{rails_app → rails_app_4.2.5}/app/views/posts/index.html.erb +0 -0
  51. data/test/{rails_app → rails_app_4.2.5}/config.ru +0 -0
  52. data/test/{rails_app → rails_app_4.2.5}/config/application.rb +0 -0
  53. data/test/{rails_app → rails_app_4.2.5}/config/boot.rb +0 -0
  54. data/test/{rails_app → rails_app_4.2.5}/config/database.yml +0 -0
  55. data/test/{rails_app → rails_app_4.2.5}/config/environment.rb +0 -0
  56. data/test/{rails_app → rails_app_4.2.5}/config/environments/development.rb +0 -0
  57. data/test/{rails_app → rails_app_4.2.5}/config/environments/production.rb +0 -0
  58. data/test/{rails_app → rails_app_4.2.5}/config/environments/test.rb +0 -0
  59. data/test/{rails_app → rails_app_4.2.5}/config/initializers/backtrace_silencers.rb +0 -0
  60. data/test/{rails_app → rails_app_4.2.5}/config/initializers/force_test_schema_load.rb +0 -0
  61. data/test/{rails_app → rails_app_4.2.5}/config/initializers/inflections.rb +0 -0
  62. data/test/{rails_app → rails_app_4.2.5}/config/initializers/mime_types.rb +0 -0
  63. data/test/{rails_app → rails_app_4.2.5}/config/initializers/secret_token.rb +0 -0
  64. data/test/{rails_app → rails_app_4.2.5}/config/initializers/session_store.rb +0 -0
  65. data/test/{rails_app → rails_app_4.2.5}/config/initializers/wrap_parameters.rb +0 -0
  66. data/test/{rails_app → rails_app_4.2.5}/config/locales/en.yml +0 -0
  67. data/test/{rails_app → rails_app_4.2.5}/config/routes.rb +0 -0
  68. data/test/{rails_app → rails_app_4.2.5}/config/secrets.yml +0 -0
  69. data/test/{rails_app → rails_app_4.2.5}/db/migrate/20130417154459_create_posts.rb +0 -0
  70. data/test/{rails_app → rails_app_4.2.5}/db/schema.rb +0 -0
  71. data/test/{rails_app → rails_app_4.2.5}/db/seeds.rb +0 -0
  72. data/test/{rails_app → rails_app_4.2.5}/lib/assets/.gitkeep +0 -0
  73. data/test/{rails_app → rails_app_4.2.5}/lib/tasks/.gitkeep +0 -0
  74. data/test/{rails_app → rails_app_4.2.5}/public/404.html +0 -0
  75. data/test/{rails_app → rails_app_4.2.5}/public/422.html +0 -0
  76. data/test/{rails_app → rails_app_4.2.5}/public/500.html +0 -0
  77. data/test/{rails_app → rails_app_4.2.5}/public/favicon.ico +0 -0
  78. data/test/{rails_app → rails_app_4.2.5}/public/index.html +0 -0
  79. data/test/{rails_app → rails_app_4.2.5}/public/robots.txt +0 -0
  80. data/test/{rails_app → rails_app_4.2.5}/script/rails +0 -0
  81. data/test/rails_app_5.0.0/.gitignore +21 -0
  82. data/test/rails_app_5.0.0/Gemfile +48 -0
  83. data/test/rails_app_5.0.0/README.md +24 -0
  84. data/test/rails_app_5.0.0/Rakefile +6 -0
  85. data/test/rails_app_5.0.0/app/assets/config/manifest.js +3 -0
  86. data/test/rails_app_5.0.0/app/assets/images/.keep +0 -0
  87. data/test/rails_app_5.0.0/app/assets/images/rails.png +0 -0
  88. data/test/rails_app_5.0.0/app/assets/javascripts/application.js +13 -0
  89. data/test/rails_app_5.0.0/app/assets/javascripts/cable.js +13 -0
  90. data/test/rails_app_5.0.0/app/assets/javascripts/channels/.keep +0 -0
  91. data/test/rails_app_5.0.0/app/assets/stylesheets/application.css +15 -0
  92. data/test/rails_app_5.0.0/app/channels/application_cable/channel.rb +4 -0
  93. data/test/rails_app_5.0.0/app/channels/application_cable/connection.rb +4 -0
  94. data/test/rails_app_5.0.0/app/controllers/admin/posts_controller.rb +14 -0
  95. data/test/rails_app_5.0.0/app/controllers/application_controller.rb +3 -0
  96. data/test/rails_app_5.0.0/app/controllers/concerns/.keep +0 -0
  97. data/test/rails_app_5.0.0/app/controllers/posts_controller.rb +22 -0
  98. data/test/rails_app_5.0.0/app/helpers/application_helper.rb +2 -0
  99. data/test/rails_app_5.0.0/app/jobs/application_job.rb +2 -0
  100. data/test/rails_app_5.0.0/app/jobs/spam/detector_job.rb +11 -0
  101. data/test/rails_app_5.0.0/app/jobs/spam_detector_job.rb +9 -0
  102. data/test/rails_app_5.0.0/app/mailers/admin/post_mailer.rb +13 -0
  103. data/test/rails_app_5.0.0/app/mailers/application_mailer.rb +4 -0
  104. data/test/rails_app_5.0.0/app/mailers/post_mailer.rb +11 -0
  105. data/test/rails_app_5.0.0/app/models/admin/post.rb +5 -0
  106. data/test/rails_app_5.0.0/app/models/application_record.rb +3 -0
  107. data/test/rails_app_5.0.0/app/models/concerns/.keep +0 -0
  108. data/test/rails_app_5.0.0/app/models/post.rb +2 -0
  109. data/test/rails_app_5.0.0/app/views/admin/post_mailer/created.text.erb +1 -0
  110. data/test/rails_app_5.0.0/app/views/admin/posts/index.html.erb +5 -0
  111. data/test/rails_app_5.0.0/app/views/layouts/application.html.erb +14 -0
  112. data/test/rails_app_5.0.0/app/views/layouts/mailer.html.erb +13 -0
  113. data/test/rails_app_5.0.0/app/views/layouts/mailer.text.erb +1 -0
  114. data/test/rails_app_5.0.0/app/views/post_mailer/created.text.erb +1 -0
  115. data/test/rails_app_5.0.0/app/views/posts/_post.html.erb +1 -0
  116. data/test/rails_app_5.0.0/app/views/posts/index.html.erb +5 -0
  117. data/test/rails_app_5.0.0/bin/bundle +3 -0
  118. data/test/rails_app_5.0.0/bin/rails +9 -0
  119. data/test/rails_app_5.0.0/bin/rake +9 -0
  120. data/test/rails_app_5.0.0/bin/setup +34 -0
  121. data/test/rails_app_5.0.0/bin/spring +15 -0
  122. data/test/rails_app_5.0.0/bin/update +29 -0
  123. data/test/rails_app_5.0.0/config.ru +5 -0
  124. data/test/rails_app_5.0.0/config/application.rb +15 -0
  125. data/test/rails_app_5.0.0/config/boot.rb +3 -0
  126. data/test/rails_app_5.0.0/config/cable.yml +9 -0
  127. data/test/rails_app_5.0.0/config/database.yml +25 -0
  128. data/test/rails_app_5.0.0/config/environment.rb +5 -0
  129. data/test/rails_app_5.0.0/config/environments/development.rb +54 -0
  130. data/test/rails_app_5.0.0/config/environments/production.rb +86 -0
  131. data/test/rails_app_5.0.0/config/environments/test.rb +42 -0
  132. data/test/rails_app_5.0.0/config/initializers/application_controller_renderer.rb +6 -0
  133. data/test/rails_app_5.0.0/config/initializers/assets.rb +11 -0
  134. data/test/rails_app_5.0.0/config/initializers/backtrace_silencers.rb +7 -0
  135. data/test/rails_app_5.0.0/config/initializers/cookies_serializer.rb +5 -0
  136. data/test/rails_app_5.0.0/config/initializers/filter_parameter_logging.rb +4 -0
  137. data/test/rails_app_5.0.0/config/initializers/force_test_schema_load.rb +3 -0
  138. data/test/rails_app_5.0.0/config/initializers/inflections.rb +16 -0
  139. data/test/rails_app_5.0.0/config/initializers/mime_types.rb +4 -0
  140. data/test/rails_app_5.0.0/config/initializers/new_framework_defaults.rb +24 -0
  141. data/test/rails_app_5.0.0/config/initializers/session_store.rb +3 -0
  142. data/test/rails_app_5.0.0/config/initializers/wrap_parameters.rb +14 -0
  143. data/test/rails_app_5.0.0/config/locales/en.yml +23 -0
  144. data/test/rails_app_5.0.0/config/puma.rb +47 -0
  145. data/test/rails_app_5.0.0/config/routes.rb +12 -0
  146. data/test/rails_app_5.0.0/config/secrets.yml +22 -0
  147. data/test/rails_app_5.0.0/config/spring.rb +6 -0
  148. data/test/rails_app_5.0.0/db/migrate/20160812134213_create_posts.rb +9 -0
  149. data/test/rails_app_5.0.0/db/schema.rb +21 -0
  150. data/test/rails_app_5.0.0/db/seeds.rb +7 -0
  151. data/test/rails_app_5.0.0/lib/assets/.keep +0 -0
  152. data/test/rails_app_5.0.0/lib/tasks/.keep +0 -0
  153. data/test/rails_app_5.0.0/log/.keep +0 -0
  154. data/test/rails_app_5.0.0/public/404.html +67 -0
  155. data/test/rails_app_5.0.0/public/422.html +67 -0
  156. data/test/rails_app_5.0.0/public/500.html +66 -0
  157. data/test/rails_app_5.0.0/public/apple-touch-icon-precomposed.png +0 -0
  158. data/test/rails_app_5.0.0/public/apple-touch-icon.png +0 -0
  159. data/test/rails_app_5.0.0/public/favicon.ico +0 -0
  160. data/test/rails_app_5.0.0/public/robots.txt +5 -0
  161. data/test/rails_app_5.0.0/test/controllers/.keep +0 -0
  162. data/test/rails_app_5.0.0/test/fixtures/.keep +0 -0
  163. data/test/rails_app_5.0.0/test/fixtures/files/.keep +0 -0
  164. data/test/rails_app_5.0.0/test/helpers/.keep +0 -0
  165. data/test/rails_app_5.0.0/test/integration/.keep +0 -0
  166. data/test/rails_app_5.0.0/test/mailers/.keep +0 -0
  167. data/test/rails_app_5.0.0/test/models/.keep +0 -0
  168. data/test/rails_app_5.0.0/test/test_helper.rb +10 -0
  169. data/test/rails_app_5.0.0/vendor/assets/javascripts/.keep +0 -0
  170. data/test/rails_app_5.0.0/vendor/assets/stylesheets/.keep +0 -0
  171. data/test/support/adapter_test_helpers.rb +17 -2
  172. metadata +295 -100
@@ -8,6 +8,8 @@ require "action_mailer"
8
8
  root = Pathname(__FILE__).dirname.join("..").expand_path
9
9
  Dir[root.join("test/support/**/*.rb")].each { |f| require f }
10
10
 
11
+ puts "Running tests against rails version #{Rails.version}"
12
+
11
13
  class ActionController::TestCase
12
14
  include AdapterTestHelpers
13
15
  end
@@ -20,6 +22,8 @@ class ActiveSupport::TestCase
20
22
  include AdapterTestHelpers
21
23
  end
22
24
 
23
- require "rails_app/config/environment"
25
+ rails_version = ENV["RAILS_VERSION"] || "4.2.5"
26
+
27
+ require "rails_app_#{rails_version}/config/environment"
24
28
 
25
29
  require "nunes"
@@ -1,7 +1,7 @@
1
1
  require "helper"
2
2
 
3
3
  class InstrumentationTest < ActiveSupport::TestCase
4
- attr_reader :thing_class
4
+ attr_reader :thing_class, :namespaced_thing_class
5
5
 
6
6
  setup :setup_subscriber, :setup_class
7
7
  teardown :teardown_subscriber, :teardown_class
@@ -30,6 +30,17 @@ class InstrumentationTest < ActiveSupport::TestCase
30
30
  'Thing'
31
31
  end
32
32
 
33
+ def yo(args = {})
34
+ :dude
35
+ end
36
+ }
37
+ @namespaced_thing_class = Class.new {
38
+ extend Nunes::Instrumentable
39
+
40
+ def self.name
41
+ 'Some::Thing'
42
+ end
43
+
33
44
  def yo(args = {})
34
45
  :dude
35
46
  end
@@ -38,6 +49,7 @@ class InstrumentationTest < ActiveSupport::TestCase
38
49
 
39
50
  def teardown_class
40
51
  @thing_class = nil
52
+ @namespaced_thing_class = nil
41
53
  end
42
54
 
43
55
  test "adds methods when extended" do
@@ -59,7 +71,7 @@ class InstrumentationTest < ActiveSupport::TestCase
59
71
 
60
72
  assert_not_nil event, "No events were found."
61
73
  assert_equal "Thing.yo", event.payload[:metric]
62
- assert_in_delta 0, event.duration, 0.1
74
+ assert event.duration > 0, "Expected #{event.duration} to be greater than 0"
63
75
 
64
76
  assert_timer "Thing.yo"
65
77
  end
@@ -80,7 +92,7 @@ class InstrumentationTest < ActiveSupport::TestCase
80
92
 
81
93
  assert_not_nil event, "No events were found."
82
94
  assert_equal "Thing.find", event.payload[:metric]
83
- assert_in_delta 0, event.duration, 0.1
95
+ assert event.duration > 0, "Expected #{event.duration} to be greater than 0"
84
96
 
85
97
  assert_timer "Thing.find"
86
98
  end
@@ -118,6 +130,18 @@ class InstrumentationTest < ActiveSupport::TestCase
118
130
  assert_timer "Thing.yo"
119
131
  end
120
132
 
133
+ test "instrument_method_time for namespaced class" do
134
+ namespaced_thing_class.instrument_method_time :yo
135
+
136
+ event = slurp_events { namespaced_thing_class.new.yo(some: 'thing') }.last
137
+
138
+ assert_not_nil event, "No events were found."
139
+ assert_equal "Some-Thing.yo", event.payload[:metric]
140
+ assert event.duration > 0, "Expected #{event.duration} to be greater than 0"
141
+
142
+ assert_timer "Some-Thing.yo"
143
+ end
144
+
121
145
  def slurp_events(&block)
122
146
  events = []
123
147
  callback = lambda { |*args| events << ActiveSupport::Notifications::Event.new(*args) }
@@ -1,6 +1,8 @@
1
1
  require "helper"
2
2
 
3
3
  class JobInstrumentationTest < ActiveSupport::TestCase
4
+ include ActiveJob::TestHelper
5
+
4
6
  setup :setup_subscriber
5
7
  teardown :teardown_subscriber
6
8
 
@@ -13,18 +15,19 @@ class JobInstrumentationTest < ActiveSupport::TestCase
13
15
  end
14
16
 
15
17
  test "perform_now" do
16
- p = Post.new(title: 'Testing')
17
- SpamDetectorJob.perform_now(p)
18
+ post = Post.new(title: 'Testing')
19
+ SpamDetectorJob.perform_now(post)
18
20
 
19
- assert_timer "active_job.spam_detector_job.perform"
21
+ assert_timer "active_job.SpamDetectorJob.perform"
20
22
  end
21
23
 
22
24
  test "perform_later" do
23
- p = Post.create!(title: 'Testing')
24
- SpamDetectorJob.perform_later(p)
25
+ post = Post.create!(title: 'Testing')
26
+ perform_enqueued_jobs do
27
+ SpamDetectorJob.perform_later(post)
28
+ end
25
29
 
26
- assert_timer "active_job.spam_detector_job.perform"
27
- assert_counter "active_job.spam_detector_job.enqueue"
30
+ assert_counter "active_job.SpamDetectorJob.enqueue"
31
+ assert_timer "active_job.SpamDetectorJob.perform"
28
32
  end
29
-
30
33
  end
@@ -1,6 +1,8 @@
1
1
  require "helper"
2
2
 
3
3
  class MailerInstrumentationTest < ActionMailer::TestCase
4
+ include ActiveJob::TestHelper
5
+
4
6
  tests PostMailer
5
7
 
6
8
  setup :setup_subscriber
@@ -20,7 +22,9 @@ class MailerInstrumentationTest < ActionMailer::TestCase
20
22
  end
21
23
 
22
24
  test "deliver_later" do
23
- PostMailer.created.deliver_later
25
+ perform_enqueued_jobs do
26
+ PostMailer.created.deliver_later
27
+ end
24
28
  assert_timer "action_mailer.deliver.PostMailer"
25
29
  end
26
30
 
@@ -19,21 +19,21 @@ class NamespacedControllerInstrumentationTest < ActionController::TestCase
19
19
 
20
20
  assert_response :success
21
21
 
22
- assert_timer "action_controller.controller.Admin.PostsController.index.runtime.total"
23
- assert_timer "action_controller.controller.Admin.PostsController.index.runtime.view"
24
- assert_timer "action_controller.controller.Admin.PostsController.index.runtime.db"
22
+ assert_timer "action_controller.controller.Admin-PostsController.index.runtime.total"
23
+ assert_timer "action_controller.controller.Admin-PostsController.index.runtime.view"
24
+ assert_timer "action_controller.controller.Admin-PostsController.index.runtime.db"
25
25
 
26
26
  assert_counter "action_controller.format.html"
27
27
  assert_counter "action_controller.status.200"
28
28
 
29
- assert_counter "action_controller.controller.Admin.PostsController.index.format.html"
30
- assert_counter "action_controller.controller.Admin.PostsController.index.status.200"
29
+ assert_counter "action_controller.controller.Admin-PostsController.index.format.html"
30
+ assert_counter "action_controller.controller.Admin-PostsController.index.status.200"
31
31
  end
32
32
 
33
33
  test "process_action w/ json" do
34
34
  get :index, format: :json
35
35
 
36
- assert_counter "action_controller.controller.Admin.PostsController.index.format.json"
36
+ assert_counter "action_controller.controller.Admin-PostsController.index.format.json"
37
37
  end
38
38
 
39
39
  test "process_action bad_request" do
@@ -41,6 +41,6 @@ class NamespacedControllerInstrumentationTest < ActionController::TestCase
41
41
 
42
42
  assert_response :forbidden
43
43
 
44
- assert_counter "action_controller.controller.Admin.PostsController.new.status.403"
44
+ assert_counter "action_controller.controller.Admin-PostsController.new.status.403"
45
45
  end
46
46
  end
@@ -0,0 +1,33 @@
1
+ require "helper"
2
+
3
+ class NamespacedJobInstrumentationTest < ActiveSupport::TestCase
4
+ include ActiveJob::TestHelper
5
+
6
+ setup :setup_subscriber
7
+ teardown :teardown_subscriber
8
+
9
+ def setup_subscriber
10
+ @subscriber = Nunes::Subscribers::ActiveJob.subscribe(adapter)
11
+ end
12
+
13
+ def teardown_subscriber
14
+ ActiveSupport::Notifications.unsubscribe @subscriber if @subscriber
15
+ end
16
+
17
+ test "perform_now" do
18
+ post = Post.new(title: 'Testing')
19
+ Spam::DetectorJob.perform_now(post)
20
+
21
+ assert_timer "active_job.Spam-DetectorJob.perform"
22
+ end
23
+
24
+ test "perform_later" do
25
+ post = Post.create!(title: 'Testing')
26
+ perform_enqueued_jobs do
27
+ Spam::DetectorJob.perform_later(post)
28
+ end
29
+
30
+ assert_counter "active_job.Spam-DetectorJob.enqueue"
31
+ assert_timer "active_job.Spam-DetectorJob.perform"
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require "helper"
2
+
3
+ class NamespacedMailerInstrumentationTest < ActionMailer::TestCase
4
+ include ActiveJob::TestHelper
5
+
6
+ tests Admin::PostMailer
7
+
8
+ setup :setup_subscriber
9
+ teardown :teardown_subscriber
10
+
11
+ def setup_subscriber
12
+ @subscriber = Nunes::Subscribers::ActionMailer.subscribe(adapter)
13
+ end
14
+
15
+ def teardown_subscriber
16
+ ActiveSupport::Notifications.unsubscribe @subscriber if @subscriber
17
+ end
18
+
19
+ test "deliver_now" do
20
+ Admin::PostMailer.created.deliver_now
21
+ assert_timer "action_mailer.deliver.Admin-PostMailer"
22
+ end
23
+
24
+ test "deliver_later" do
25
+ perform_enqueued_jobs do
26
+ Admin::PostMailer.created.deliver_later
27
+ end
28
+ assert_timer "action_mailer.deliver.Admin-PostMailer"
29
+ end
30
+
31
+ test "receive" do
32
+ Admin::PostMailer.receive Admin::PostMailer.created
33
+ assert_timer "action_mailer.receive.Admin-PostMailer"
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ require "helper"
2
+
3
+ class NamespacedModelInstrumentationTest < ActiveSupport::TestCase
4
+ setup :setup_subscriber
5
+ teardown :teardown_subscriber
6
+
7
+ def setup_subscriber
8
+ @subscriber = Nunes::Subscribers::ActiveRecord.subscribe(adapter)
9
+ end
10
+
11
+ def teardown_subscriber
12
+ ActiveSupport::Notifications.unsubscribe @subscriber if @subscriber
13
+ end
14
+
15
+ test "transaction" do
16
+ Admin::Post.create(title: 'Testing')
17
+
18
+ assert_timer "active_record.sql.transaction_begin"
19
+ assert_timer "active_record.sql.transaction_commit"
20
+ end
21
+
22
+ test "create" do
23
+ Admin::Post.create(title: 'Testing')
24
+
25
+ assert_timer "active_record.sql"
26
+ assert_timer "active_record.sql.insert"
27
+ end
28
+
29
+ test "update" do
30
+ post = Admin::Post.create
31
+ adapter.clear
32
+ post.update_attributes(title: "Title")
33
+
34
+ assert_timer "active_record.sql"
35
+ assert_timer "active_record.sql.update"
36
+ end
37
+
38
+ test "find" do
39
+ post = Admin::Post.create
40
+ adapter.clear
41
+ Admin::Post.find(post.id)
42
+
43
+ assert_timer "active_record.sql"
44
+ assert_timer "active_record.sql.select"
45
+ end
46
+
47
+ test "destroy" do
48
+ post = Admin::Post.create
49
+ adapter.clear
50
+ post.destroy
51
+
52
+ assert_timer "active_record.sql"
53
+ assert_timer "active_record.sql.delete"
54
+ end
55
+ end
@@ -17,4 +17,12 @@ class NunesTest < ActiveSupport::TestCase
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ test "class_to_metric" do
22
+ assert_equal nil, Nunes.class_to_metric(nil)
23
+ assert_equal "Foo", Nunes.class_to_metric("Foo")
24
+ assert_equal "Nunes", Nunes.class_to_metric(Nunes)
25
+ assert_equal "Spam-DetectorJob", Nunes.class_to_metric(Spam::DetectorJob)
26
+ assert_equal "Spam-DetectorJob", Nunes.class_to_metric("Spam::DetectorJob")
27
+ end
20
28
  end
@@ -1,12 +1,7 @@
1
1
  class Admin::PostsController < ApplicationController
2
- # Use fake post for controller as I don't want active record to mingle here.
3
- Post = Struct.new(:title)
4
-
5
2
  def index
6
- @posts = [
7
- Post.new('First'),
8
- Post.new('Second'),
9
- ]
3
+ @posts = Post.all
4
+
10
5
  respond_to do |format|
11
6
  format.html { render }
12
7
  format.json { render :json => @posts }
@@ -1,12 +1,6 @@
1
1
  class PostsController < ApplicationController
2
- # Use fake post for controller as I don't want active record to mingle here.
3
- Post = Struct.new(:title)
4
-
5
2
  def index
6
- @posts = [
7
- Post.new('First'),
8
- Post.new('Second'),
9
- ]
3
+ @posts = Post.all
10
4
  end
11
5
 
12
6
  def some_data
@@ -0,0 +1,11 @@
1
+ module Spam
2
+ class DetectorJob < ActiveJob::Base
3
+ queue_as :default
4
+
5
+ def perform(*posts)
6
+ posts.detect do |post|
7
+ post.title.include?("Buy watches cheap!")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Admin
2
+ class PostMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+
5
+ def created
6
+ mail to: "to@example.org"
7
+ end
8
+
9
+ def receive(email)
10
+ # do something
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Admin
2
+ class Post < ActiveRecord::Base
3
+ self.table_name = "posts"
4
+ end
5
+ end