projectlocker_pulse 0.2.1
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.
- data/CHANGELOG +26 -0
- data/Gemfile +3 -0
- data/Guardfile +6 -0
- data/INSTALL +20 -0
- data/MIT-LICENSE +23 -0
- data/README.md +439 -0
- data/README_FOR_HEROKU_ADDON.md +89 -0
- data/Rakefile +223 -0
- data/SUPPORTED_RAILS_VERSIONS +38 -0
- data/TESTING.md +41 -0
- data/features/metal.feature +18 -0
- data/features/rack.feature +60 -0
- data/features/rails.feature +272 -0
- data/features/rails_with_js_notifier.feature +97 -0
- data/features/rake.feature +27 -0
- data/features/sinatra.feature +29 -0
- data/features/step_definitions/file_steps.rb +10 -0
- data/features/step_definitions/metal_steps.rb +23 -0
- data/features/step_definitions/rack_steps.rb +23 -0
- data/features/step_definitions/rails_application_steps.rb +478 -0
- data/features/step_definitions/rake_steps.rb +17 -0
- data/features/support/env.rb +18 -0
- data/features/support/matchers.rb +35 -0
- data/features/support/projectlocker_pulse_shim.rb.template +16 -0
- data/features/support/rails.rb +201 -0
- data/features/support/rake/Rakefile +68 -0
- data/features/support/terminal.rb +107 -0
- data/features/user_informer.feature +63 -0
- data/generators/pulse/lib/insert_commands.rb +34 -0
- data/generators/pulse/lib/rake_commands.rb +24 -0
- data/generators/pulse/pulse_generator.rb +94 -0
- data/generators/pulse/templates/capistrano_hook.rb +6 -0
- data/generators/pulse/templates/initializer.rb +6 -0
- data/generators/pulse/templates/pulse_tasks.rake +25 -0
- data/install.rb +1 -0
- data/lib/projectlocker_pulse.rb +159 -0
- data/lib/pulse/backtrace.rb +108 -0
- data/lib/pulse/capistrano.rb +43 -0
- data/lib/pulse/configuration.rb +305 -0
- data/lib/pulse/notice.rb +390 -0
- data/lib/pulse/rack.rb +54 -0
- data/lib/pulse/rails/action_controller_catcher.rb +30 -0
- data/lib/pulse/rails/controller_methods.rb +85 -0
- data/lib/pulse/rails/error_lookup.rb +33 -0
- data/lib/pulse/rails/javascript_notifier.rb +47 -0
- data/lib/pulse/rails/middleware/exceptions_catcher.rb +33 -0
- data/lib/pulse/rails.rb +40 -0
- data/lib/pulse/rails3_tasks.rb +99 -0
- data/lib/pulse/railtie.rb +49 -0
- data/lib/pulse/rake_handler.rb +65 -0
- data/lib/pulse/sender.rb +128 -0
- data/lib/pulse/shared_tasks.rb +47 -0
- data/lib/pulse/tasks.rb +83 -0
- data/lib/pulse/user_informer.rb +27 -0
- data/lib/pulse/utils/blank.rb +53 -0
- data/lib/pulse/version.rb +3 -0
- data/lib/pulse_tasks.rb +64 -0
- data/lib/rails/generators/pulse/pulse_generator.rb +100 -0
- data/lib/templates/javascript_notifier.erb +15 -0
- data/lib/templates/rescue.erb +91 -0
- data/pulse.gemspec +39 -0
- data/rails/init.rb +1 -0
- data/resources/README.md +34 -0
- data/resources/ca-bundle.crt +3376 -0
- data/script/integration_test.rb +38 -0
- data/test/backtrace_test.rb +162 -0
- data/test/capistrano_test.rb +34 -0
- data/test/catcher_test.rb +333 -0
- data/test/configuration_test.rb +236 -0
- data/test/helper.rb +263 -0
- data/test/javascript_notifier_test.rb +51 -0
- data/test/logger_test.rb +79 -0
- data/test/notice_test.rb +490 -0
- data/test/notifier_test.rb +276 -0
- data/test/projectlocker_pulse_tasks_test.rb +170 -0
- data/test/pulse.xsd +88 -0
- data/test/rack_test.rb +58 -0
- data/test/rails_initializer_test.rb +36 -0
- data/test/recursion_test.rb +10 -0
- data/test/sender_test.rb +288 -0
- data/test/user_informer_test.rb +29 -0
- metadata +432 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
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, Pulse::VERSION
|
16
|
+
assert_config_default :notifier_name, 'Pulse Notifier'
|
17
|
+
assert_config_default :notifier_url, 'http://rubyforge.org/projects/pl-errata/'
|
18
|
+
assert_config_default :secure, false
|
19
|
+
assert_config_default :host, 'errors.projectlocker.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
|
+
Pulse::Configuration::DEFAULT_PARAMS_FILTERS
|
26
|
+
assert_config_default :backtrace_filters,
|
27
|
+
Pulse::Configuration::DEFAULT_BACKTRACE_FILTERS
|
28
|
+
assert_config_default :ignore,
|
29
|
+
Pulse::Configuration::IGNORE_DEFAULT
|
30
|
+
assert_config_default :development_lookup, true
|
31
|
+
assert_config_default :framework, 'Standalone'
|
32
|
+
assert_config_default :async, nil
|
33
|
+
end
|
34
|
+
|
35
|
+
should "set GirlFriday-callable for async=true" do
|
36
|
+
config = Pulse::Configuration.new
|
37
|
+
config.async = true
|
38
|
+
assert config.async.respond_to?(:call)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "set provided-callable for async {}" do
|
42
|
+
config = Pulse::Configuration.new
|
43
|
+
config.async {|notice| :ok}
|
44
|
+
assert config.async.respond_to?(:call)
|
45
|
+
assert_equal :ok, config.async.call
|
46
|
+
end
|
47
|
+
|
48
|
+
should "provide default values for secure connections" do
|
49
|
+
config = Pulse::Configuration.new
|
50
|
+
config.secure = true
|
51
|
+
assert_equal 443, config.port
|
52
|
+
assert_equal 'https', config.protocol
|
53
|
+
end
|
54
|
+
|
55
|
+
should "provide default values for insecure connections" do
|
56
|
+
config = Pulse::Configuration.new
|
57
|
+
config.secure = false
|
58
|
+
assert_equal 80, config.port
|
59
|
+
assert_equal 'http', config.protocol
|
60
|
+
end
|
61
|
+
|
62
|
+
should "not cache inferred ports" do
|
63
|
+
config = Pulse::Configuration.new
|
64
|
+
config.secure = false
|
65
|
+
config.port
|
66
|
+
config.secure = true
|
67
|
+
assert_equal 443, config.port
|
68
|
+
end
|
69
|
+
|
70
|
+
should "allow values to be overwritten" do
|
71
|
+
assert_config_overridable :proxy_host
|
72
|
+
assert_config_overridable :proxy_port
|
73
|
+
assert_config_overridable :proxy_user
|
74
|
+
assert_config_overridable :proxy_pass
|
75
|
+
assert_config_overridable :secure
|
76
|
+
assert_config_overridable :host
|
77
|
+
assert_config_overridable :port
|
78
|
+
assert_config_overridable :http_open_timeout
|
79
|
+
assert_config_overridable :http_read_timeout
|
80
|
+
assert_config_overridable :project_root
|
81
|
+
assert_config_overridable :notifier_version
|
82
|
+
assert_config_overridable :notifier_name
|
83
|
+
assert_config_overridable :notifier_url
|
84
|
+
assert_config_overridable :environment_name
|
85
|
+
assert_config_overridable :development_lookup
|
86
|
+
assert_config_overridable :logger
|
87
|
+
assert_config_overridable :async
|
88
|
+
end
|
89
|
+
|
90
|
+
should "have an api key" do
|
91
|
+
assert_config_overridable :api_key
|
92
|
+
end
|
93
|
+
|
94
|
+
should "act like a hash" do
|
95
|
+
config = Pulse::Configuration.new
|
96
|
+
hash = config.to_hash
|
97
|
+
[:api_key, :backtrace_filters, :development_environments,
|
98
|
+
:environment_name, :host, :http_open_timeout,
|
99
|
+
:http_read_timeout, :ignore, :ignore_by_filters, :ignore_user_agent,
|
100
|
+
:notifier_name, :notifier_url, :notifier_version, :params_filters,
|
101
|
+
:project_root, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port,
|
102
|
+
:proxy_user, :secure, :development_lookup, :async].each do |option|
|
103
|
+
assert_equal config[option], hash[option], "Wrong value for #{option}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
should "be mergable" do
|
108
|
+
config = Pulse::Configuration.new
|
109
|
+
hash = config.to_hash
|
110
|
+
assert_equal hash.merge(:key => 'value'), config.merge(:key => 'value')
|
111
|
+
end
|
112
|
+
|
113
|
+
should "allow param filters to be appended" do
|
114
|
+
assert_appends_value :params_filters
|
115
|
+
end
|
116
|
+
|
117
|
+
should "warn when attempting to read environment filters" do
|
118
|
+
config = Pulse::Configuration.new
|
119
|
+
config.
|
120
|
+
expects(:warn).
|
121
|
+
with(regexp_matches(/deprecated/i))
|
122
|
+
assert_equal [], config.environment_filters
|
123
|
+
end
|
124
|
+
|
125
|
+
should "warn when attempting to write js_notifier" do
|
126
|
+
config = Pulse::Configuration.new
|
127
|
+
config.
|
128
|
+
expects(:warn).
|
129
|
+
with(regexp_matches(/deprecated/i))
|
130
|
+
config.js_notifier = true
|
131
|
+
end
|
132
|
+
|
133
|
+
should "allow ignored user agents to be appended" do
|
134
|
+
assert_appends_value :ignore_user_agent
|
135
|
+
end
|
136
|
+
|
137
|
+
should "allow backtrace filters to be appended" do
|
138
|
+
assert_appends_value(:backtrace_filters) do |config|
|
139
|
+
new_filter = lambda {}
|
140
|
+
config.filter_backtrace(&new_filter)
|
141
|
+
new_filter
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
should "allow ignore by filters to be appended" do
|
146
|
+
assert_appends_value(:ignore_by_filters) do |config|
|
147
|
+
new_filter = lambda {}
|
148
|
+
config.ignore_by_filter(&new_filter)
|
149
|
+
new_filter
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
should "allow ignored exceptions to be appended" do
|
154
|
+
config = Pulse::Configuration.new
|
155
|
+
original_filters = config.ignore.dup
|
156
|
+
new_filter = 'hello'
|
157
|
+
config.ignore << new_filter
|
158
|
+
assert_same_elements original_filters + [new_filter], config.ignore
|
159
|
+
end
|
160
|
+
|
161
|
+
should "allow ignored exceptions to be replaced" do
|
162
|
+
assert_replaces(:ignore, :ignore_only=)
|
163
|
+
end
|
164
|
+
|
165
|
+
should "allow ignored user agents to be replaced" do
|
166
|
+
assert_replaces(:ignore_user_agent, :ignore_user_agent_only=)
|
167
|
+
end
|
168
|
+
|
169
|
+
should "use development and test as development environments by default" do
|
170
|
+
config = Pulse::Configuration.new
|
171
|
+
assert_same_elements %w(development test cucumber), config.development_environments
|
172
|
+
end
|
173
|
+
|
174
|
+
should "be public in a public environment" do
|
175
|
+
config = Pulse::Configuration.new
|
176
|
+
config.development_environments = %w(development)
|
177
|
+
config.environment_name = 'production'
|
178
|
+
assert config.public?
|
179
|
+
end
|
180
|
+
|
181
|
+
should "not be public in a development environment" do
|
182
|
+
config = Pulse::Configuration.new
|
183
|
+
config.development_environments = %w(staging)
|
184
|
+
config.environment_name = 'staging'
|
185
|
+
assert !config.public?
|
186
|
+
end
|
187
|
+
|
188
|
+
should "be public without an environment name" do
|
189
|
+
config = Pulse::Configuration.new
|
190
|
+
assert config.public?
|
191
|
+
end
|
192
|
+
|
193
|
+
should "use the assigned logger if set" do
|
194
|
+
config = Pulse::Configuration.new
|
195
|
+
config.logger = "CUSTOM LOGGER"
|
196
|
+
assert_equal "CUSTOM LOGGER", config.logger
|
197
|
+
end
|
198
|
+
|
199
|
+
should 'give a new instance if non defined' do
|
200
|
+
Pulse.configuration = nil
|
201
|
+
assert_kind_of Pulse::Configuration, Pulse.configuration
|
202
|
+
end
|
203
|
+
|
204
|
+
def assert_config_default(option, default_value, config = nil)
|
205
|
+
config ||= Pulse::Configuration.new
|
206
|
+
assert_equal default_value, config.send(option)
|
207
|
+
end
|
208
|
+
|
209
|
+
def assert_config_overridable(option, value = 'a value')
|
210
|
+
config = Pulse::Configuration.new
|
211
|
+
config.send(:"#{option}=", value)
|
212
|
+
assert_equal value, config.send(option)
|
213
|
+
end
|
214
|
+
|
215
|
+
def assert_appends_value(option, &block)
|
216
|
+
config = Pulse::Configuration.new
|
217
|
+
original_values = config.send(option).dup
|
218
|
+
block ||= lambda do |config|
|
219
|
+
new_value = 'hello'
|
220
|
+
config.send(option) << new_value
|
221
|
+
new_value
|
222
|
+
end
|
223
|
+
new_value = block.call(config)
|
224
|
+
assert_same_elements original_values + [new_value], config.send(option)
|
225
|
+
end
|
226
|
+
|
227
|
+
def assert_replaces(option, setter)
|
228
|
+
config = Pulse::Configuration.new
|
229
|
+
new_value = 'hello'
|
230
|
+
config.send(setter, [new_value])
|
231
|
+
assert_equal [new_value], config.send(option)
|
232
|
+
config.send(setter, new_value)
|
233
|
+
assert_equal [new_value], config.send(option)
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
7
|
+
|
8
|
+
require 'thread'
|
9
|
+
|
10
|
+
require 'shoulda'
|
11
|
+
require 'mocha'
|
12
|
+
|
13
|
+
require 'action_controller'
|
14
|
+
require 'action_controller/test_process'
|
15
|
+
require 'active_record'
|
16
|
+
require 'active_support'
|
17
|
+
require 'nokogiri'
|
18
|
+
require 'rack'
|
19
|
+
require 'bourne'
|
20
|
+
require 'sham_rack'
|
21
|
+
|
22
|
+
require "pulse"
|
23
|
+
|
24
|
+
begin require 'redgreen'; rescue LoadError; end
|
25
|
+
|
26
|
+
module TestMethods
|
27
|
+
def rescue_action e
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
|
31
|
+
def do_raise
|
32
|
+
raise "Pulse"
|
33
|
+
end
|
34
|
+
|
35
|
+
def do_not_raise
|
36
|
+
render :text => "Success"
|
37
|
+
end
|
38
|
+
|
39
|
+
def do_raise_ignored
|
40
|
+
raise ActiveRecord::RecordNotFound.new("404")
|
41
|
+
end
|
42
|
+
|
43
|
+
def do_raise_not_ignored
|
44
|
+
raise ActiveRecord::StatementInvalid.new("Statement invalid")
|
45
|
+
end
|
46
|
+
|
47
|
+
def manual_notify
|
48
|
+
notify_pulse(Exception.new)
|
49
|
+
render :text => "Success"
|
50
|
+
end
|
51
|
+
|
52
|
+
def manual_notify_ignored
|
53
|
+
notify_pulse(ActiveRecord::RecordNotFound.new("404"))
|
54
|
+
render :text => "Success"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Test::Unit::TestCase
|
59
|
+
def request(action = nil, method = :get, user_agent = nil, params = {})
|
60
|
+
@request = ActionController::TestRequest.new
|
61
|
+
@request.action = action ? action.to_s : ""
|
62
|
+
|
63
|
+
if user_agent
|
64
|
+
if @request.respond_to?(:user_agent=)
|
65
|
+
@request.user_agent = user_agent
|
66
|
+
else
|
67
|
+
@request.env["HTTP_USER_AGENT"] = user_agent
|
68
|
+
end
|
69
|
+
end
|
70
|
+
@request.query_parameters = @request.query_parameters.merge(params)
|
71
|
+
@response = ActionController::TestResponse.new
|
72
|
+
@controller.process(@request, @response)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Borrowed from ActiveSupport 2.3.2
|
76
|
+
def assert_difference(expression, difference = 1, message = nil, &block)
|
77
|
+
b = block.send(:binding)
|
78
|
+
exps = Array.wrap(expression)
|
79
|
+
before = exps.map { |e| eval(e, b) }
|
80
|
+
|
81
|
+
yield
|
82
|
+
|
83
|
+
exps.each_with_index do |e, i|
|
84
|
+
error = "#{e.inspect} didn't change by #{difference}"
|
85
|
+
error = "#{message}.\n#{error}" if message
|
86
|
+
assert_equal(before[i] + difference, eval(e, b), error)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def assert_no_difference(expression, message = nil, &block)
|
91
|
+
assert_difference expression, 0, message, &block
|
92
|
+
end
|
93
|
+
|
94
|
+
def stub_sender
|
95
|
+
stub('sender', :send_to_pulse => nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
def stub_sender!
|
99
|
+
Pulse.sender = stub_sender
|
100
|
+
end
|
101
|
+
|
102
|
+
def stub_notice
|
103
|
+
stub('notice', :to_xml => 'some yaml', :ignore? => false)
|
104
|
+
end
|
105
|
+
|
106
|
+
def stub_notice!
|
107
|
+
stub_notice.tap do |notice|
|
108
|
+
Pulse::Notice.stubs(:new => notice)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_dummy
|
113
|
+
Pulse::DummySender.new
|
114
|
+
end
|
115
|
+
|
116
|
+
def reset_config
|
117
|
+
Pulse.configuration = nil
|
118
|
+
Pulse.configure do |config|
|
119
|
+
config.api_key = 'abc123'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def clear_backtrace_filters
|
124
|
+
Pulse.configuration.backtrace_filters.clear
|
125
|
+
end
|
126
|
+
|
127
|
+
def build_exception(opts = {})
|
128
|
+
backtrace = ["pulse/test/helper.rb:132:in `build_exception'",
|
129
|
+
"pulse/test/backtrace.rb:4:in `build_notice_data'",
|
130
|
+
"/var/lib/gems/1.8/gems/pulse-2.4.5/rails/init.rb:2:in `send_exception'"]
|
131
|
+
opts = {:backtrace => backtrace}.merge(opts)
|
132
|
+
BacktracedException.new(opts)
|
133
|
+
end
|
134
|
+
|
135
|
+
def build_notice_data(exception = nil)
|
136
|
+
exception ||= build_exception
|
137
|
+
{
|
138
|
+
:api_key => 'abc123',
|
139
|
+
:error_class => exception.class.name,
|
140
|
+
:error_message => "#{exception.class.name}: #{exception.message}",
|
141
|
+
:backtrace => exception.backtrace,
|
142
|
+
:environment => { 'PATH' => '/bin', 'REQUEST_URI' => '/users/1' },
|
143
|
+
:request => {
|
144
|
+
:params => { 'controller' => 'users', 'action' => 'show', 'id' => '1' },
|
145
|
+
:rails_root => '/path/to/application',
|
146
|
+
:url => "http://test.host/users/1"
|
147
|
+
},
|
148
|
+
:session => {
|
149
|
+
:key => '123abc',
|
150
|
+
:data => { 'user_id' => '5', 'flash' => { 'notice' => 'Logged in successfully' } }
|
151
|
+
}
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
def assert_caught_and_sent
|
156
|
+
assert !Pulse.sender.collected.empty?
|
157
|
+
end
|
158
|
+
|
159
|
+
def assert_caught_and_not_sent
|
160
|
+
assert Pulse.sender.collected.empty?
|
161
|
+
end
|
162
|
+
|
163
|
+
def assert_array_starts_with(expected, actual)
|
164
|
+
assert_respond_to actual, :to_ary
|
165
|
+
array = actual.to_ary.reverse
|
166
|
+
expected.reverse.each_with_index do |value, i|
|
167
|
+
assert_equal value, array[i]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def assert_valid_node(document, xpath, content)
|
172
|
+
nodes = document.xpath(xpath)
|
173
|
+
assert nodes.any?{|node| node.content == content },
|
174
|
+
"Expected xpath #{xpath} to have content #{content}, " +
|
175
|
+
"but found #{nodes.map { |n| n.content }} in #{nodes.size} matching nodes." +
|
176
|
+
"Document:\n#{document.to_s}"
|
177
|
+
end
|
178
|
+
|
179
|
+
def assert_logged(expected)
|
180
|
+
assert_received(Pulse, :write_verbose_log) do |expect|
|
181
|
+
expect.with {|actual| actual =~ expected }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def assert_not_logged(expected)
|
186
|
+
assert_received(Pulse, :write_verbose_log) do |expect|
|
187
|
+
expect.with {|actual| actual =~ expected }.never
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
module DefinesConstants
|
195
|
+
def setup
|
196
|
+
@defined_constants = []
|
197
|
+
end
|
198
|
+
|
199
|
+
def teardown
|
200
|
+
@defined_constants.each do |constant|
|
201
|
+
Object.__send__(:remove_const, constant)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def define_constant(name, value)
|
206
|
+
Object.const_set(name, value)
|
207
|
+
@defined_constants << name
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Also stolen from AS 2.3.2
|
212
|
+
class Array
|
213
|
+
# Wraps the object in an Array unless it's an Array. Converts the
|
214
|
+
# object to an Array using #to_ary if it implements that.
|
215
|
+
def self.wrap(object)
|
216
|
+
case object
|
217
|
+
when nil
|
218
|
+
[]
|
219
|
+
when self
|
220
|
+
object
|
221
|
+
else
|
222
|
+
if object.respond_to?(:to_ary)
|
223
|
+
object.to_ary
|
224
|
+
else
|
225
|
+
[object]
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
class CollectingSender
|
233
|
+
attr_reader :collected
|
234
|
+
|
235
|
+
def initialize
|
236
|
+
@collected = []
|
237
|
+
end
|
238
|
+
|
239
|
+
def send_to_pulse(data)
|
240
|
+
@collected << data
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
class FakeLogger
|
245
|
+
def info(*args); end
|
246
|
+
def debug(*args); end
|
247
|
+
def warn(*args); end
|
248
|
+
def error(*args); end
|
249
|
+
def fatal(*args); end
|
250
|
+
end
|
251
|
+
|
252
|
+
class BacktracedException < Exception
|
253
|
+
attr_accessor :backtrace
|
254
|
+
def initialize(opts)
|
255
|
+
@backtrace = opts[:backtrace]
|
256
|
+
end
|
257
|
+
def set_backtrace(bt)
|
258
|
+
@backtrace = bt
|
259
|
+
end
|
260
|
+
def message
|
261
|
+
"Something went wrong. Did you press the red button?"
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
require 'pulse/rails/javascript_notifier'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
class JavascriptNotifierTest < Test::Unit::TestCase
|
6
|
+
module FakeRenderer
|
7
|
+
def javascript_tag(text)
|
8
|
+
"<script>#{text}</script>"
|
9
|
+
end
|
10
|
+
def escape_javascript(text)
|
11
|
+
"ESC#{text}ESC"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class FakeController
|
16
|
+
def self.helper_method(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
include Pulse::Rails::JavascriptNotifier
|
20
|
+
|
21
|
+
def action_name
|
22
|
+
"action"
|
23
|
+
end
|
24
|
+
|
25
|
+
def controller_name
|
26
|
+
"controller"
|
27
|
+
end
|
28
|
+
|
29
|
+
def request
|
30
|
+
@request ||= OpenStruct.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_to_string(options)
|
34
|
+
context = OpenStruct.new(options[:locals])
|
35
|
+
context.extend(FakeRenderer)
|
36
|
+
context.instance_eval do
|
37
|
+
erb = ERB.new(IO.read(options[:file]))
|
38
|
+
erb.result(binding)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
should "make sure escape_javacript is called on the request.url" do
|
44
|
+
Pulse.configure do
|
45
|
+
end
|
46
|
+
controller = FakeController.new
|
47
|
+
controller.request.url = "bad_javascript"
|
48
|
+
assert controller.send(:pulse_javascript_notifier)['"ESCbad_javascriptESC"']
|
49
|
+
assert ! controller.send(:pulse_javascript_notifier)['"bad_javascript"']
|
50
|
+
end
|
51
|
+
end
|
data/test/logger_test.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path '../helper', __FILE__
|
2
|
+
|
3
|
+
class LoggerTest < Test::Unit::TestCase
|
4
|
+
def stub_http(response, body = nil)
|
5
|
+
response.stubs(:body => body) if body
|
6
|
+
@http = stub(:post => response,
|
7
|
+
:read_timeout= => nil,
|
8
|
+
:open_timeout= => nil,
|
9
|
+
:use_ssl= => nil)
|
10
|
+
Net::HTTP.stubs(:new).returns(@http)
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_notice
|
14
|
+
Pulse.sender.send_to_pulse({'foo' => "bar"})
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_verbose_log
|
18
|
+
Pulse.stubs(:write_verbose_log)
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
Pulse.configure { |config| }
|
23
|
+
end
|
24
|
+
|
25
|
+
should "report that notifier is ready when configured" do
|
26
|
+
stub_verbose_log
|
27
|
+
configure
|
28
|
+
assert_logged /Notifier (.*) ready/
|
29
|
+
end
|
30
|
+
|
31
|
+
should "not report that notifier is ready when internally configured" do
|
32
|
+
stub_verbose_log
|
33
|
+
Pulse.configure(true) { |config| }
|
34
|
+
assert_not_logged /.*/
|
35
|
+
end
|
36
|
+
|
37
|
+
should "print environment info a successful notification without a body" do
|
38
|
+
reset_config
|
39
|
+
stub_verbose_log
|
40
|
+
stub_http(Net::HTTPSuccess)
|
41
|
+
send_notice
|
42
|
+
assert_logged /Environment Info:/
|
43
|
+
assert_not_logged /Response from Pulse:/
|
44
|
+
end
|
45
|
+
|
46
|
+
should "print environment info on a failed notification without a body" do
|
47
|
+
reset_config
|
48
|
+
stub_verbose_log
|
49
|
+
stub_http(Net::HTTPError)
|
50
|
+
send_notice
|
51
|
+
assert_logged /Environment Info:/
|
52
|
+
assert_not_logged /Response from Pulse:/
|
53
|
+
end
|
54
|
+
|
55
|
+
should "print environment info and response on a success with a body" do
|
56
|
+
reset_config
|
57
|
+
stub_verbose_log
|
58
|
+
stub_http(Net::HTTPSuccess, 'test')
|
59
|
+
send_notice
|
60
|
+
assert_logged /Environment Info:/
|
61
|
+
assert_logged /Response from Pulse:/
|
62
|
+
end
|
63
|
+
|
64
|
+
should "print environment info and response on a failure with a body" do
|
65
|
+
reset_config
|
66
|
+
stub_verbose_log
|
67
|
+
stub_http(Net::HTTPError, 'test')
|
68
|
+
send_notice
|
69
|
+
assert_logged /Environment Info:/
|
70
|
+
assert_logged /Response from Pulse:/
|
71
|
+
end
|
72
|
+
|
73
|
+
should "print information about the notice when Pulse server fails" do
|
74
|
+
stub_verbose_log
|
75
|
+
stub_http(Net::HTTPError, "test")
|
76
|
+
send_notice
|
77
|
+
assert_logged /Notice details:/
|
78
|
+
end
|
79
|
+
end
|