Permalink
Browse files

allow configuration of application name

  • Loading branch information...
1 parent 037c136 commit 6a4968c68e61f7e31bd433992b0d050c8f56d82e @qrush qrush committed Mar 12, 2012
Showing with 12 additions and 4 deletions.
  1. +2 −2 lib/query_comments.rb
  2. +10 −2 test/query_comments_test.rb
View
@@ -2,7 +2,7 @@
require 'action_controller'
module QueryComments
- mattr_accessor :comment
+ mattr_accessor :comment, :application_name
module ActiveRecordInstrumentation
def self.included(instrumented_class)
@@ -38,7 +38,7 @@ def to_sql_with_instrumentation(arel)
def self.initialize!
ActionController::Base.class_eval do
def record_query_comment
- QueryComments.comment = "application:BCX,controller:#{controller_name},action:#{action_name}"
+ QueryComments.comment = "application:#{QueryComments.application_name || "rails"},controller:#{controller_name},action:#{action_name}"
yield
ensure
QueryComments.comment = nil
@@ -51,7 +51,7 @@ def test_query_commenting_on_mysql_driver_with_no_action
def test_query_commenting_on_mysql_driver_with_action
PostsController.action(:driver_only).call(@env)
- assert_match %r{select id from posts /\*application:BCX,controller:posts,action:driver_only\*/$}, @queries.first
+ assert_match %r{select id from posts /\*application:rails,controller:posts,action:driver_only\*/$}, @queries.first
end
def test_query_commenting_on_arel_with_no_action
@@ -61,10 +61,18 @@ def test_query_commenting_on_arel_with_no_action
def test_query_commenting_on_arel_with_action
PostsController.action(:arel_only).call(@env)
- assert_match %r{SELECT `posts`\.\* FROM `posts` /\*application:BCX,controller:posts,action:arel_only\*/$}, @queries.last
+ assert_match %r{SELECT `posts`\.\* FROM `posts` /\*application:rails,controller:posts,action:arel_only\*/$}, @queries.last
+ end
+
+ def test_configuring_application
+ QueryComments.application_name = "customapp"
+ PostsController.action(:driver_only).call(@env)
+
+ assert_match %r{/\*application:customapp,controller:posts,action:driver_only\*/$}, @queries.first
end
def teardown
+ QueryComments.application_name = nil
ActiveSupport::Notifications.unsubscribe "sql.active_record"
end
end

0 comments on commit 6a4968c

Please sign in to comment.