Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Only send notices if configured with an api_key #268

Merged
merged 1 commit into from May 2, 2014
Jump to file or symbol
Failed to load files and symbols.
+34 −2
Split
View
@@ -147,7 +147,7 @@ def build_lookup_hash_for(exception, options = {})
private
def send_notice(notice)
- if configuration.public?
+ if configuration.configured? && configuration.public?
if configuration.async?
configuration.async.call(notice)
nil # make sure we never set env["airbrake.error_id"] for async notices
@@ -256,6 +256,10 @@ def merge(hash)
to_hash.merge(hash)
end
+ def configured?
+ !api_key.nil? && !api_key.empty?
+ end
+
# Determines if the notifier will send notices.
# @return [Boolean] Returns +false+ if in a development environment, +true+ otherwise.
def public?
View
@@ -183,6 +183,27 @@ class ConfigurationTest < Test::Unit::TestCase
assert_same_elements %w(development test cucumber), config.development_environments
end
+ context "configured?" do
+ setup do
+ @config = Airbrake::Configuration.new
+ end
+
+ should "be true if given an api_key" do
+ @config.api_key = "1234"
+ assert @config.configured?
+ end
+
+ should "be false with a nil api_key" do
+ @config.api_key = nil
+ assert !@config.configured?
+ end
+
+ should "be false with a blank api_key" do
+ @config.api_key = ''
+ assert !@config.configured?
+ end
+ end
+
should "be public in a public environment" do
config = Airbrake::Configuration.new
config.development_environments = %w(development)
@@ -269,6 +269,13 @@ def test_not_deliver_notices_from_exceptions_in_development_environments
assert_caught_and_not_sent
end
+ def test_not_deliver_notices_from_exceptions_with_no_api_key
+ Airbrake.configuration.api_key = nil
+ @app = AirbrakeTestController.action(:boom)
+ get '/'
+ assert_caught_and_not_sent
+ end
+
def test_not_deliver_notices_from_actions_that_dont_raise
@app = AirbrakeTestController.action(:hello)
get '/'
View
@@ -187,7 +187,7 @@ def set_development_env
config_opts = { 'one' => 'two', 'three' => 'four' }
stub_notice!
stub_sender!
- Airbrake.configuration = stub('config', :merge => config_opts, :public? => true,:async? => nil)
+ Airbrake.configuration = stub('config', :merge => config_opts, :configured? => true, :public? => true,:async? => nil)
Airbrake.notify(exception)