square-hoptoad_notifier 2.4.8

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 (52) hide show
  1. data/CHANGELOG +427 -0
  2. data/INSTALL +25 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.md +435 -0
  5. data/README_FOR_HEROKU_ADDON.md +93 -0
  6. data/Rakefile +227 -0
  7. data/SUPPORTED_RAILS_VERSIONS +10 -0
  8. data/TESTING.rdoc +8 -0
  9. data/generators/hoptoad/hoptoad_generator.rb +88 -0
  10. data/generators/hoptoad/lib/insert_commands.rb +34 -0
  11. data/generators/hoptoad/lib/rake_commands.rb +24 -0
  12. data/generators/hoptoad/templates/capistrano_hook.rb +6 -0
  13. data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +25 -0
  14. data/generators/hoptoad/templates/initializer.rb +6 -0
  15. data/lib/hoptoad_notifier.rb +153 -0
  16. data/lib/hoptoad_notifier/backtrace.rb +99 -0
  17. data/lib/hoptoad_notifier/capistrano.rb +20 -0
  18. data/lib/hoptoad_notifier/configuration.rb +242 -0
  19. data/lib/hoptoad_notifier/notice.rb +337 -0
  20. data/lib/hoptoad_notifier/rack.rb +42 -0
  21. data/lib/hoptoad_notifier/rails.rb +41 -0
  22. data/lib/hoptoad_notifier/rails/action_controller_catcher.rb +30 -0
  23. data/lib/hoptoad_notifier/rails/controller_methods.rb +68 -0
  24. data/lib/hoptoad_notifier/rails/error_lookup.rb +33 -0
  25. data/lib/hoptoad_notifier/rails/javascript_notifier.rb +42 -0
  26. data/lib/hoptoad_notifier/rails3_tasks.rb +82 -0
  27. data/lib/hoptoad_notifier/railtie.rb +32 -0
  28. data/lib/hoptoad_notifier/sender.rb +83 -0
  29. data/lib/hoptoad_notifier/shared_tasks.rb +29 -0
  30. data/lib/hoptoad_notifier/tasks.rb +83 -0
  31. data/lib/hoptoad_notifier/user_informer.rb +23 -0
  32. data/lib/hoptoad_notifier/version.rb +3 -0
  33. data/lib/hoptoad_tasks.rb +44 -0
  34. data/lib/rails/generators/hoptoad/hoptoad_generator.rb +94 -0
  35. data/lib/templates/javascript_notifier.erb +13 -0
  36. data/lib/templates/rescue.erb +91 -0
  37. data/rails/init.rb +1 -0
  38. data/script/integration_test.rb +38 -0
  39. data/test/backtrace_test.rb +118 -0
  40. data/test/catcher_test.rb +331 -0
  41. data/test/configuration_test.rb +216 -0
  42. data/test/helper.rb +248 -0
  43. data/test/hoptoad_tasks_test.rb +152 -0
  44. data/test/javascript_notifier_test.rb +52 -0
  45. data/test/logger_test.rb +85 -0
  46. data/test/notice_test.rb +448 -0
  47. data/test/notifier_test.rb +222 -0
  48. data/test/rack_test.rb +58 -0
  49. data/test/rails_initializer_test.rb +36 -0
  50. data/test/sender_test.rb +161 -0
  51. data/test/user_informer_test.rb +29 -0
  52. metadata +225 -0
@@ -0,0 +1,216 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+
5
+ include DefinesConstants
6
+
7
+ should "provide default values" do
8
+ assert_config_default :proxy_host, nil
9
+ assert_config_default :proxy_port, nil
10
+ assert_config_default :proxy_user, nil
11
+ assert_config_default :proxy_pass, nil
12
+ assert_config_default :project_root, nil
13
+ assert_config_default :environment_name, nil
14
+ assert_config_default :logger, nil
15
+ assert_config_default :notifier_version, HoptoadNotifier::VERSION
16
+ assert_config_default :notifier_name, 'Hoptoad Notifier'
17
+ assert_config_default :notifier_url, 'http://hoptoadapp.com'
18
+ assert_config_default :secure, false
19
+ assert_config_default :host, 'hoptoadapp.com'
20
+ assert_config_default :http_open_timeout, 2
21
+ assert_config_default :http_read_timeout, 5
22
+ assert_config_default :ignore_by_filters, []
23
+ assert_config_default :ignore_user_agent, []
24
+ assert_config_default :params_filters,
25
+ HoptoadNotifier::Configuration::DEFAULT_PARAMS_FILTERS
26
+ assert_config_default :backtrace_filters,
27
+ HoptoadNotifier::Configuration::DEFAULT_BACKTRACE_FILTERS
28
+ assert_config_default :ignore,
29
+ HoptoadNotifier::Configuration::IGNORE_DEFAULT
30
+ assert_config_default :development_lookup, true
31
+ assert_config_default :framework, 'Standalone'
32
+ end
33
+
34
+ should "provide default values for secure connections" do
35
+ config = HoptoadNotifier::Configuration.new
36
+ config.secure = true
37
+ assert_equal 443, config.port
38
+ assert_equal 'https', config.protocol
39
+ end
40
+
41
+ should "provide default values for insecure connections" do
42
+ config = HoptoadNotifier::Configuration.new
43
+ config.secure = false
44
+ assert_equal 80, config.port
45
+ assert_equal 'http', config.protocol
46
+ end
47
+
48
+ should "not cache inferred ports" do
49
+ config = HoptoadNotifier::Configuration.new
50
+ config.secure = false
51
+ config.port
52
+ config.secure = true
53
+ assert_equal 443, config.port
54
+ end
55
+
56
+ should "allow values to be overwritten" do
57
+ assert_config_overridable :proxy_host
58
+ assert_config_overridable :proxy_port
59
+ assert_config_overridable :proxy_user
60
+ assert_config_overridable :proxy_pass
61
+ assert_config_overridable :secure
62
+ assert_config_overridable :host
63
+ assert_config_overridable :port
64
+ assert_config_overridable :http_open_timeout
65
+ assert_config_overridable :http_read_timeout
66
+ assert_config_overridable :project_root
67
+ assert_config_overridable :notifier_version
68
+ assert_config_overridable :notifier_name
69
+ assert_config_overridable :notifier_url
70
+ assert_config_overridable :environment_name
71
+ assert_config_overridable :development_lookup
72
+ assert_config_overridable :logger
73
+ end
74
+
75
+ should "have an api key" do
76
+ assert_config_overridable :api_key
77
+ end
78
+
79
+ should "act like a hash" do
80
+ config = HoptoadNotifier::Configuration.new
81
+ hash = config.to_hash
82
+ [:api_key, :backtrace_filters, :development_environments,
83
+ :environment_name, :host, :http_open_timeout,
84
+ :http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent,
85
+ :notifier_name, :notifier_url, :notifier_version, :params_filters,
86
+ :project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port,
87
+ :proxy_user, :secure, :development_lookup].each do |option|
88
+ assert_equal config[option], hash[option], "Wrong value for #{option}"
89
+ end
90
+ end
91
+
92
+ should "be mergable" do
93
+ config = HoptoadNotifier::Configuration.new
94
+ hash = config.to_hash
95
+ assert_equal hash.merge(:key => 'value'), config.merge(:key => 'value')
96
+ end
97
+
98
+ should "allow param filters to be appended" do
99
+ assert_appends_value :params_filters
100
+ end
101
+
102
+ should "warn when attempting to read environment filters" do
103
+ config = HoptoadNotifier::Configuration.new
104
+ config.
105
+ expects(:warn).
106
+ with(regexp_matches(/deprecated/i))
107
+ assert_equal [], config.environment_filters
108
+ end
109
+
110
+ should "warn when attempting to write js_notifier" do
111
+ config = HoptoadNotifier::Configuration.new
112
+ config.
113
+ expects(:warn).
114
+ with(regexp_matches(/deprecated/i))
115
+ config.js_notifier = true
116
+ end
117
+
118
+ should "allow ignored user agents to be appended" do
119
+ assert_appends_value :ignore_user_agent
120
+ end
121
+
122
+ should "allow backtrace filters to be appended" do
123
+ assert_appends_value(:backtrace_filters) do |config|
124
+ new_filter = lambda {}
125
+ config.filter_backtrace(&new_filter)
126
+ new_filter
127
+ end
128
+ end
129
+
130
+ should "allow ignore by filters to be appended" do
131
+ assert_appends_value(:ignore_by_filters) do |config|
132
+ new_filter = lambda {}
133
+ config.ignore_by_filter(&new_filter)
134
+ new_filter
135
+ end
136
+ end
137
+
138
+ should "allow ignored exceptions to be appended" do
139
+ config = HoptoadNotifier::Configuration.new
140
+ original_filters = config.ignore.dup
141
+ new_filter = 'hello'
142
+ config.ignore << new_filter
143
+ assert_same_elements original_filters + [new_filter], config.ignore
144
+ end
145
+
146
+ should "allow ignored exceptions to be replaced" do
147
+ assert_replaces(:ignore, :ignore_only=)
148
+ end
149
+
150
+ should "allow ignored user agents to be replaced" do
151
+ assert_replaces(:ignore_user_agent, :ignore_user_agent_only=)
152
+ end
153
+
154
+ should "use development and test as development environments by default" do
155
+ config = HoptoadNotifier::Configuration.new
156
+ assert_same_elements %w(development test cucumber), config.development_environments
157
+ end
158
+
159
+ should "be public in a public environment" do
160
+ config = HoptoadNotifier::Configuration.new
161
+ config.development_environments = %w(development)
162
+ config.environment_name = 'production'
163
+ assert config.public?
164
+ end
165
+
166
+ should "not be public in a development environment" do
167
+ config = HoptoadNotifier::Configuration.new
168
+ config.development_environments = %w(staging)
169
+ config.environment_name = 'staging'
170
+ assert !config.public?
171
+ end
172
+
173
+ should "be public without an environment name" do
174
+ config = HoptoadNotifier::Configuration.new
175
+ assert config.public?
176
+ end
177
+
178
+ should "use the assigned logger if set" do
179
+ config = HoptoadNotifier::Configuration.new
180
+ config.logger = "CUSTOM LOGGER"
181
+ assert_equal "CUSTOM LOGGER", config.logger
182
+ end
183
+
184
+ def assert_config_default(option, default_value, config = nil)
185
+ config ||= HoptoadNotifier::Configuration.new
186
+ assert_equal default_value, config.send(option)
187
+ end
188
+
189
+ def assert_config_overridable(option, value = 'a value')
190
+ config = HoptoadNotifier::Configuration.new
191
+ config.send(:"#{option}=", value)
192
+ assert_equal value, config.send(option)
193
+ end
194
+
195
+ def assert_appends_value(option, &block)
196
+ config = HoptoadNotifier::Configuration.new
197
+ original_values = config.send(option).dup
198
+ block ||= lambda do |config|
199
+ new_value = 'hello'
200
+ config.send(option) << new_value
201
+ new_value
202
+ end
203
+ new_value = block.call(config)
204
+ assert_same_elements original_values + [new_value], config.send(option)
205
+ end
206
+
207
+ def assert_replaces(option, setter)
208
+ config = HoptoadNotifier::Configuration.new
209
+ new_value = 'hello'
210
+ config.send(setter, [new_value])
211
+ assert_equal [new_value], config.send(option)
212
+ config.send(setter, new_value)
213
+ assert_equal [new_value], config.send(option)
214
+ end
215
+
216
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,248 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ gem "activesupport", "= 2.3.11"
5
+ gem "activerecord", "= 2.3.11"
6
+ gem "actionpack", "= 2.3.11"
7
+ gem "nokogiri", "= 1.4.3.1"
8
+ gem "shoulda", ">= 2.11.1"
9
+ gem 'bourne', '>= 1.0'
10
+ gem "sham_rack", "~> 1.3.0"
11
+
12
+ $LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
13
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
14
+
15
+ require 'shoulda'
16
+ require 'mocha'
17
+
18
+ require 'ginger'
19
+
20
+
21
+ require 'action_controller'
22
+ require 'action_controller/test_process'
23
+ require 'active_record'
24
+ require 'active_record/base'
25
+ require 'active_support'
26
+ require 'nokogiri'
27
+ require 'rack'
28
+ require 'bourne'
29
+ require 'sham_rack'
30
+
31
+ require "hoptoad_notifier"
32
+
33
+ begin require 'redgreen'; rescue LoadError; end
34
+
35
+ module TestMethods
36
+ def rescue_action e
37
+ raise e
38
+ end
39
+
40
+ def do_raise
41
+ raise "Hoptoad"
42
+ end
43
+
44
+ def do_not_raise
45
+ render :text => "Success"
46
+ end
47
+
48
+ def do_raise_ignored
49
+ raise ActiveRecord::RecordNotFound.new("404")
50
+ end
51
+
52
+ def do_raise_not_ignored
53
+ raise ActiveRecord::StatementInvalid.new("Statement invalid")
54
+ end
55
+
56
+ def manual_notify
57
+ notify_hoptoad(Exception.new)
58
+ render :text => "Success"
59
+ end
60
+
61
+ def manual_notify_ignored
62
+ notify_hoptoad(ActiveRecord::RecordNotFound.new("404"))
63
+ render :text => "Success"
64
+ end
65
+ end
66
+
67
+ class HoptoadController < ActionController::Base
68
+ include TestMethods
69
+ end
70
+
71
+ class Test::Unit::TestCase
72
+ def request(action = nil, method = :get, user_agent = nil, params = {})
73
+ @request = ActionController::TestRequest.new
74
+ @request.action = action ? action.to_s : ""
75
+
76
+ if user_agent
77
+ if @request.respond_to?(:user_agent=)
78
+ @request.user_agent = user_agent
79
+ else
80
+ @request.env["HTTP_USER_AGENT"] = user_agent
81
+ end
82
+ end
83
+ @request.query_parameters = @request.query_parameters.merge(params)
84
+ @response = ActionController::TestResponse.new
85
+ @controller.process(@request, @response)
86
+ end
87
+
88
+ # Borrowed from ActiveSupport 2.3.2
89
+ def assert_difference(expression, difference = 1, message = nil, &block)
90
+ b = block.send(:binding)
91
+ exps = Array.wrap(expression)
92
+ before = exps.map { |e| eval(e, b) }
93
+
94
+ yield
95
+
96
+ exps.each_with_index do |e, i|
97
+ error = "#{e.inspect} didn't change by #{difference}"
98
+ error = "#{message}.\n#{error}" if message
99
+ assert_equal(before[i] + difference, eval(e, b), error)
100
+ end
101
+ end
102
+
103
+ def assert_no_difference(expression, message = nil, &block)
104
+ assert_difference expression, 0, message, &block
105
+ end
106
+
107
+ def stub_sender
108
+ stub('sender', :send_to_hoptoad => nil)
109
+ end
110
+
111
+ def stub_sender!
112
+ HoptoadNotifier.sender = stub_sender
113
+ end
114
+
115
+ def stub_notice
116
+ stub('notice', :to_xml => 'some yaml', :ignore? => false)
117
+ end
118
+
119
+ def stub_notice!
120
+ stub_notice.tap do |notice|
121
+ HoptoadNotifier::Notice.stubs(:new => notice)
122
+ end
123
+ end
124
+
125
+ def create_dummy
126
+ HoptoadNotifier::DummySender.new
127
+ end
128
+
129
+ def reset_config
130
+ HoptoadNotifier.configuration = nil
131
+ HoptoadNotifier.configure do |config|
132
+ config.api_key = 'abc123'
133
+ end
134
+ end
135
+
136
+ def clear_backtrace_filters
137
+ HoptoadNotifier.configuration.backtrace_filters.clear
138
+ end
139
+
140
+ def build_exception
141
+ raise
142
+ rescue => caught_exception
143
+ caught_exception
144
+ end
145
+
146
+ def build_notice_data(exception = nil)
147
+ exception ||= build_exception
148
+ {
149
+ :api_key => 'abc123',
150
+ :error_class => exception.class.name,
151
+ :error_message => "#{exception.class.name}: #{exception.message}",
152
+ :backtrace => exception.backtrace,
153
+ :environment => { 'PATH' => '/bin', 'REQUEST_URI' => '/users/1' },
154
+ :request => {
155
+ :params => { 'controller' => 'users', 'action' => 'show', 'id' => '1' },
156
+ :rails_root => '/path/to/application',
157
+ :url => "http://test.host/users/1"
158
+ },
159
+ :session => {
160
+ :key => '123abc',
161
+ :data => { 'user_id' => '5', 'flash' => { 'notice' => 'Logged in successfully' } }
162
+ }
163
+ }
164
+ end
165
+
166
+ def assert_caught_and_sent
167
+ assert !HoptoadNotifier.sender.collected.empty?
168
+ end
169
+
170
+ def assert_caught_and_not_sent
171
+ assert HoptoadNotifier.sender.collected.empty?
172
+ end
173
+
174
+ def assert_array_starts_with(expected, actual)
175
+ assert_respond_to actual, :to_ary
176
+ array = actual.to_ary.reverse
177
+ expected.reverse.each_with_index do |value, i|
178
+ assert_equal value, array[i]
179
+ end
180
+ end
181
+
182
+ def assert_valid_node(document, xpath, content)
183
+ nodes = document.xpath(xpath)
184
+ assert nodes.any?{|node| node.content == content },
185
+ "Expected xpath #{xpath} to have content #{content}, " +
186
+ "but found #{nodes.map { |n| n.content }} in #{nodes.size} matching nodes." +
187
+ "Document:\n#{document.to_s}"
188
+ end
189
+ end
190
+
191
+ module DefinesConstants
192
+ def setup
193
+ @defined_constants = []
194
+ end
195
+
196
+ def teardown
197
+ @defined_constants.each do |constant|
198
+ Object.__send__(:remove_const, constant)
199
+ end
200
+ end
201
+
202
+ def define_constant(name, value)
203
+ Object.const_set(name, value)
204
+ @defined_constants << name
205
+ end
206
+ end
207
+
208
+ # Also stolen from AS 2.3.2
209
+ class Array
210
+ # Wraps the object in an Array unless it's an Array. Converts the
211
+ # object to an Array using #to_ary if it implements that.
212
+ def self.wrap(object)
213
+ case object
214
+ when nil
215
+ []
216
+ when self
217
+ object
218
+ else
219
+ if object.respond_to?(:to_ary)
220
+ object.to_ary
221
+ else
222
+ [object]
223
+ end
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ class CollectingSender
230
+ attr_reader :collected
231
+
232
+ def initialize
233
+ @collected = []
234
+ end
235
+
236
+ def send_to_hoptoad(data)
237
+ @collected << data
238
+ end
239
+ end
240
+
241
+ class FakeLogger
242
+ def info(*args); end
243
+ def debug(*args); end
244
+ def warn(*args); end
245
+ def error(*args); end
246
+ def fatal(*args); end
247
+ end
248
+