raygun4ruby 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d60156ce8457a817f37b25be18c330c425168c02
4
- data.tar.gz: 6910263dfeef71f41e86faff38b0d675ca9f8a3e
3
+ metadata.gz: d9e6e07eb62a1e5b014f23705b3438154a8d5645
4
+ data.tar.gz: 1669c3ed97bc8ab9f2234db2d351e1542539136e
5
5
  SHA512:
6
- metadata.gz: 231b498a6cfa379ac0a39faf8f64aaff661c738256849db5c8b84f95272ea21d8dbf2812100e7a02f2b53e4c25e77e98a75064f3e32aee8c4f869530fc15322a
7
- data.tar.gz: 42b1dcc424ad28ca4307ab2e5cb54f18d7b184ac917ef75799fce6241e35b0bf4e03ea8892802a31d99936f73c3075f98ebf83ec869f8f77a240eeb9880a8c36
6
+ metadata.gz: 8ce62d3015545c77a1cdbdf76dc5215c9f8aa01b1ff7930d77debda1140dd267eb52cf01ee4736c10866ff8c9c67565b9de9748b74179d08477f1fc1d0edfc08
7
+ data.tar.gz: 96f8dc35a93f66b220d368f0370b413e605a080a07ee849747ef3009be7230df23ac4a401e55a657b23ecd941fdce3b7a7348df6abdfc53df2a6b45a2d319449
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ before_install:
2
+ - gem install bundler
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+
8
+ gemfile:
9
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in raygun4ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nik Wakelin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+
6
+ namespace :test do
7
+
8
+ desc "Test the basics of the adapter"
9
+ Rake::TestTask.new(:units) do |t|
10
+ t.libs << "lib/raygun"
11
+ t.test_files = FileList["test/unit/*_test.rb"]
12
+ t.verbose = true
13
+ end
14
+
15
+ desc "Run a test against the live API"
16
+ Rake::TestTask.new(:integration) do |t|
17
+ t.libs << "lib/raygun"
18
+ t.test_files = FileList["test/integration/*_test.rb"]
19
+ t.verbose = true
20
+ end
21
+
22
+ end
23
+
24
+ task default: "test:units"
data/lib/raygun/client.rb CHANGED
@@ -2,6 +2,9 @@ module Raygun
2
2
  # client for the Raygun REST APIv1
3
3
  # as per http://raygun.io/raygun-providers/rest-json-api?v=1
4
4
  class Client
5
+
6
+ ENV_IP_ADDRESS_KEYS = %w(action_dispatch.remote_ip raygun.remote_ip REMOTE_ADDR)
7
+
5
8
  include HTTParty
6
9
 
7
10
  base_uri "https://api.raygun.io/"
@@ -73,7 +76,7 @@ module Raygun
73
76
  hostName: env["SERVER_NAME"],
74
77
  url: env["PATH_INFO"],
75
78
  httpMethod: env["REQUEST_METHOD"],
76
- iPAddress: env["REMOTE_ADDR"],
79
+ iPAddress: ip_address_from(env),
77
80
  queryString: Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
78
81
  form: form_data(env),
79
82
  headers: headers(env),
@@ -142,5 +145,11 @@ module Raygun
142
145
  end
143
146
  end
144
147
 
148
+ def ip_address_from(env_hash)
149
+ ENV_IP_ADDRESS_KEYS.each do |key_to_try|
150
+ return env_hash[key_to_try] unless env_hash[key_to_try].nil? || env_hash[key_to_try] == ""
151
+ end
152
+ end
153
+
145
154
  end
146
155
  end
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'raygun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "raygun4ruby"
8
+ spec.version = Raygun::VERSION
9
+ spec.authors = ["Mindscape", "Nik Wakelin"]
10
+ spec.email = ["hello@raygun.io"]
11
+ spec.description = %q{Ruby Adapter for Raygun.io}
12
+ spec.summary = %q{This gem provides support for Ruby and Ruby on Rails for the Raygun.io error reporter}
13
+ spec.homepage = "http://raygun.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files | grep -Ev '^(test)'`.split("\n")
17
+ spec.test_files = `git ls-files -- test/*`.split("\n")
18
+
19
+ spec.executables = []
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "httparty", "~> 0.11"
23
+ spec.add_runtime_dependency "json"
24
+ spec.add_runtime_dependency "rack"
25
+
26
+ spec.add_development_dependency "bundler", ">= 1.1"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "fakeweb", ["~> 1.3"]
29
+ spec.add_development_dependency "timecop"
30
+ spec.add_development_dependency "minitest", "~> 4.2"
31
+ spec.add_development_dependency "redis-namespace", ">= 1.3.1"
32
+ spec.add_development_dependency "resque"
33
+ spec.add_development_dependency "sidekiq", "~> 3"
34
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../test_helper.rb"
2
+
3
+ class ClientTest < Raygun::IntegrationTest
4
+
5
+ class InnocentTestException < StandardError
6
+ def message
7
+ "I am nothing but a test exception"
8
+ end
9
+ end
10
+
11
+ def test_sending_a_sample_exception
12
+ begin
13
+ raise InnocentTestException.new
14
+ rescue InnocentTestException => e
15
+ response = Raygun.track_exception(e)
16
+ assert_equal 202, response.code, "Raygun Request Failed: #{response.inspect}"
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "../lib/raygun.rb"
2
+ require "minitest/autorun"
3
+ require "minitest/pride"
4
+ require "fakeweb"
5
+ require "timecop"
6
+
7
+ class NoApiKey < StandardError; end
8
+
9
+ class Raygun::IntegrationTest < Minitest::Unit::TestCase
10
+
11
+ def setup
12
+ Raygun.setup do |config|
13
+ config.api_key = File.open(File.expand_path("~/.raygun4ruby-test-key"), "rb").read
14
+ config.version = Raygun::VERSION
15
+ end
16
+
17
+ rescue Errno::ENOENT
18
+ raise NoApiKey.new("Place a valid Raygun API key into ~/.raygun4ruby-test-key to run integration tests") unless api_key
19
+ end
20
+
21
+ def teardown
22
+ end
23
+
24
+ end
25
+
26
+ class Raygun::UnitTest < MiniTest::Unit::TestCase
27
+
28
+ def setup
29
+ FakeWeb.allow_net_connect = false
30
+ Raygun.configuration.api_key = "test api key"
31
+ end
32
+
33
+ def fake_successful_entry
34
+ FakeWeb.register_uri(:post, "https://api.raygun.io/entries", body: "", status: 202)
35
+ end
36
+
37
+ def teardown
38
+ FakeWeb.clean_registry
39
+ FakeWeb.allow_net_connect = true
40
+ reset_configuration
41
+ end
42
+
43
+ def reset_configuration
44
+ Raygun.configuration = Raygun::Configuration.new
45
+ end
46
+
47
+ end
@@ -0,0 +1,275 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative "../test_helper.rb"
3
+ require 'stringio'
4
+
5
+ class ClientTest < Raygun::UnitTest
6
+
7
+ class TestException < StandardError; end
8
+
9
+ def setup
10
+ super
11
+ @client = Raygun::Client.new
12
+ fake_successful_entry
13
+ end
14
+
15
+ def test_api_key_required_exception
16
+ Raygun.configuration.api_key = nil
17
+
18
+ assert_raises Raygun::ApiKeyRequired do
19
+ second_client = Raygun::Client.new
20
+ end
21
+ end
22
+
23
+ def test_track_exception
24
+ response = Raygun.track_exceptions do
25
+ raise TestException.new
26
+ end
27
+
28
+ assert response.success?
29
+ end
30
+
31
+ def test_error_details
32
+ e = TestException.new("A test message")
33
+ e.set_backtrace(["/some/folder/some_file.rb:123:in `some_method_name'",
34
+ "/another/path/foo.rb:1234:in `block (3 levels) run'"])
35
+
36
+ expected_hash = {
37
+ className: "ClientTest::TestException",
38
+ message: e.message,
39
+ stackTrace: [
40
+ { lineNumber: "123", fileName: "/some/folder/some_file.rb", methodName: "some_method_name" },
41
+ { lineNumber: "1234", fileName: "/another/path/foo.rb", methodName: "block (3 levels) run"}
42
+ ]
43
+ }
44
+
45
+ assert_equal expected_hash, @client.send(:error_details, e)
46
+ end
47
+
48
+ def test_client_details
49
+ expected_hash = {
50
+ name: Raygun::CLIENT_NAME,
51
+ version: Raygun::VERSION,
52
+ clientUrl: Raygun::CLIENT_URL
53
+ }
54
+
55
+ assert_equal expected_hash, @client.send(:client_details)
56
+ end
57
+
58
+
59
+ def test_version
60
+ Raygun.setup do |config|
61
+ config.version = 123
62
+ end
63
+
64
+ assert_equal 123, @client.send(:version)
65
+ end
66
+
67
+ def test_affected_user
68
+ e = TestException.new("A test message")
69
+ test_env = { "raygun.affected_user" => { :identifier => "somepooruser@yourapp.com" } }
70
+ expected_hash = test_env["raygun.affected_user"]
71
+
72
+ assert_equal expected_hash, @client.send(:build_payload_hash, e, test_env)[:details][:user]
73
+ end
74
+
75
+ def test_hostname
76
+ assert_equal Socket.gethostname, @client.send(:hostname)
77
+ end
78
+
79
+ def test_unicode
80
+ e = TestException.new('日本語のメッセージ')
81
+
82
+ assert_silent { @client.track_exception(e) }
83
+ end
84
+
85
+ def test_bad_encoding
86
+ bad_message = (100..1000).to_a.pack('c*').force_encoding('utf-8')
87
+ bad_exception = TestException.new(bad_message)
88
+
89
+ assert !bad_message.valid_encoding?
90
+ assert_silent { @client.track_exception(bad_exception) }
91
+ end
92
+
93
+ def test_full_payload_hash
94
+ Timecop.freeze do
95
+ Raygun.configuration.version = 123
96
+ e = TestException.new("A test message")
97
+ e.set_backtrace(["/some/folder/some_file.rb:123:in `some_method_name'",
98
+ "/another/path/foo.rb:1234:in `block (3 levels) run'"])
99
+
100
+ expected_hash = {
101
+ occurredOn: Time.now.utc.iso8601,
102
+ details: {
103
+ machineName: Socket.gethostname,
104
+ version: 123,
105
+ client: {
106
+ name: Raygun::CLIENT_NAME,
107
+ version: Raygun::VERSION,
108
+ clientUrl: Raygun::CLIENT_URL
109
+ },
110
+ error: {
111
+ className: "ClientTest::TestException",
112
+ message: e.message,
113
+ stackTrace: [
114
+ { lineNumber: "123", fileName: "/some/folder/some_file.rb", methodName: "some_method_name" },
115
+ { lineNumber: "1234", fileName: "/another/path/foo.rb", methodName: "block (3 levels) run"}
116
+ ]
117
+ },
118
+ userCustomData: {},
119
+ request: {}
120
+ }
121
+ }
122
+
123
+ assert_equal expected_hash, @client.send(:build_payload_hash, e)
124
+ end
125
+ end
126
+
127
+ def test_getting_request_information
128
+ sample_env_hash = {
129
+ "SERVER_NAME"=>"localhost",
130
+ "REQUEST_METHOD"=>"GET",
131
+ "REQUEST_PATH"=>"/",
132
+ "PATH_INFO"=>"/",
133
+ "QUERY_STRING"=>"a=b&c=4945438",
134
+ "REQUEST_URI"=>"/?a=b&c=4945438",
135
+ "HTTP_VERSION"=>"HTTP/1.1",
136
+ "HTTP_HOST"=>"localhost:3000",
137
+ "HTTP_CONNECTION"=>"keep-alive",
138
+ "HTTP_CACHE_CONTROL"=>"max-age=0",
139
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
140
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36",
141
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch",
142
+ "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8",
143
+ "HTTP_COOKIE"=>"cookieval",
144
+ "GATEWAY_INTERFACE"=>"CGI/1.2",
145
+ "SERVER_PORT"=>"3000",
146
+ "SERVER_PROTOCOL"=>"HTTP/1.1",
147
+ "SCRIPT_NAME"=>"",
148
+ "REMOTE_ADDR"=>"127.0.0.1"
149
+ }
150
+
151
+ expected_hash = {
152
+ hostName: "localhost",
153
+ url: "/",
154
+ httpMethod: "GET",
155
+ iPAddress: "127.0.0.1",
156
+ queryString: { "a" => "b", "c" => "4945438" },
157
+ form: nil,
158
+ headers: { "Version"=>"HTTP/1.1", "Host"=>"localhost:3000", "Connection"=>"keep-alive", "Cache-Control"=>"max-age=0", "Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36", "Accept-Encoding"=>"gzip,deflate,sdch", "Accept-Language"=>"en-US,en;q=0.8", "Cookie"=>"cookieval" },
159
+ rawData: []
160
+ }
161
+
162
+ assert_equal expected_hash, @client.send(:request_information, sample_env_hash)
163
+ end
164
+
165
+ def test_getting_request_information_with_nil_env
166
+ assert_equal({}, @client.send(:request_information, nil))
167
+ end
168
+
169
+ def test_filtering_parameters
170
+ post_body_env_hash = {
171
+ "SERVER_NAME"=>"localhost",
172
+ "REQUEST_METHOD"=>"POST",
173
+ "REQUEST_PATH"=>"/",
174
+ "PATH_INFO"=>"/",
175
+ "QUERY_STRING"=>"",
176
+ "REQUEST_URI"=>"/",
177
+ "HTTP_VERSION"=>"HTTP/1.1",
178
+ "HTTP_HOST"=>"localhost:3000",
179
+ "HTTP_CONNECTION"=>"keep-alive",
180
+ "HTTP_CACHE_CONTROL"=>"max-age=0",
181
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
182
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36",
183
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch",
184
+ "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8",
185
+ "HTTP_COOKIE"=>"cookieval",
186
+ "GATEWAY_INTERFACE"=>"CGI/1.2",
187
+ "SERVER_PORT"=>"3000",
188
+ "SERVER_PROTOCOL"=>"HTTP/1.1",
189
+ "SCRIPT_NAME"=>"",
190
+ "REMOTE_ADDR"=>"127.0.0.1",
191
+ "rack.input"=>StringIO.new("a=b&c=4945438&password=swordfish")
192
+ }
193
+
194
+ expected_form_hash = { "a" => "b", "c" => "4945438", "password" => "[FILTERED]" }
195
+
196
+ assert_equal expected_form_hash, @client.send(:request_information, post_body_env_hash)[:form]
197
+ end
198
+
199
+ def test_filtering_nested_params
200
+ post_body_env_hash = {
201
+ "SERVER_NAME"=>"localhost",
202
+ "REQUEST_METHOD"=>"POST",
203
+ "REQUEST_PATH"=>"/",
204
+ "PATH_INFO"=>"/",
205
+ "QUERY_STRING"=>"",
206
+ "REQUEST_URI"=>"/",
207
+ "HTTP_VERSION"=>"HTTP/1.1",
208
+ "HTTP_HOST"=>"localhost:3000",
209
+ "HTTP_CONNECTION"=>"keep-alive",
210
+ "HTTP_CACHE_CONTROL"=>"max-age=0",
211
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
212
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36",
213
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch",
214
+ "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8",
215
+ "HTTP_COOKIE"=>"cookieval",
216
+ "GATEWAY_INTERFACE"=>"CGI/1.2",
217
+ "SERVER_PORT"=>"3000",
218
+ "SERVER_PROTOCOL"=>"HTTP/1.1",
219
+ "SCRIPT_NAME"=>"",
220
+ "REMOTE_ADDR"=>"127.0.0.1",
221
+ "rack.input"=>StringIO.new("a=b&bank%5Bcredit_card%5D%5Bcard_number%5D=my_secret_bank_number&bank%5Bname%5D=something&c=123456&user%5Bpassword%5D=my_fancy_password")
222
+ }
223
+
224
+ expected_form_hash = { "a" => "b", "bank" => { "credit_card" => { "card_number" => "[FILTERED]" }, "name" => "something" }, "c" => "123456", "user" => { "password" => "[FILTERED]" } }
225
+
226
+ assert_equal expected_form_hash, @client.send(:request_information, post_body_env_hash)[:form]
227
+ end
228
+
229
+ def test_ip_address_from_action_dispatch
230
+ sample_env_hash = {
231
+ "HTTP_VERSION"=>"HTTP/1.1",
232
+ "HTTP_HOST"=>"localhost:3000",
233
+ "HTTP_CONNECTION"=>"keep-alive",
234
+ "HTTP_CACHE_CONTROL"=>"max-age=0",
235
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
236
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36",
237
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch",
238
+ "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8",
239
+ "HTTP_COOKIE"=>"cookieval",
240
+ "GATEWAY_INTERFACE"=>"CGI/1.2",
241
+ "SERVER_PORT"=>"3000",
242
+ "SERVER_PROTOCOL"=>"HTTP/1.1",
243
+ "SCRIPT_NAME"=>"",
244
+ "REMOTE_ADDR"=>"127.0.0.1",
245
+ "action_dispatch.remote_ip"=>"123.456.789.012"
246
+ }
247
+
248
+ assert_equal "123.456.789.012", @client.send(:ip_address_from, sample_env_hash)
249
+ assert_equal "123.456.789.012", @client.send(:request_information, sample_env_hash)[:iPAddress]
250
+ end
251
+
252
+ def test_ip_address_from_raygun_specific_key
253
+ sample_env_hash = {
254
+ "HTTP_VERSION"=>"HTTP/1.1",
255
+ "HTTP_HOST"=>"localhost:3000",
256
+ "HTTP_CONNECTION"=>"keep-alive",
257
+ "HTTP_CACHE_CONTROL"=>"max-age=0",
258
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
259
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36",
260
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch",
261
+ "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8",
262
+ "HTTP_COOKIE"=>"cookieval",
263
+ "GATEWAY_INTERFACE"=>"CGI/1.2",
264
+ "SERVER_PORT"=>"3000",
265
+ "SERVER_PROTOCOL"=>"HTTP/1.1",
266
+ "SCRIPT_NAME"=>"",
267
+ "REMOTE_ADDR"=>"127.0.0.1",
268
+ "raygun.remote_ip"=>"123.456.789.012"
269
+ }
270
+
271
+ assert_equal "123.456.789.012", @client.send(:ip_address_from, sample_env_hash)
272
+ assert_equal "123.456.789.012", @client.send(:request_information, sample_env_hash)[:iPAddress]
273
+ end
274
+
275
+ end
@@ -0,0 +1,63 @@
1
+ require_relative "../test_helper.rb"
2
+
3
+ class ConfigurationTest < Raygun::UnitTest
4
+
5
+ class TestException < StandardError; end
6
+ class Test2Exception < StandardError; end
7
+
8
+ def setup
9
+ Raygun.setup do |config|
10
+ config.api_key = "a test api key"
11
+ config.version = 9.9
12
+ end
13
+ end
14
+
15
+ def test_setting_api_key_and_version
16
+ assert_equal 9.9, Raygun.configuration.version
17
+ assert_equal "a test api key", Raygun.configuration.api_key
18
+ end
19
+
20
+ def test_hash_style_access
21
+ assert_equal 9.9, Raygun.configuration[:version]
22
+ end
23
+
24
+ def test_enable_reporting
25
+ Raygun.configuration.enable_reporting = false
26
+
27
+ # should be no API call
28
+ assert_nil Raygun.track_exception(TestException.new)
29
+ end
30
+
31
+ def test_silence_reporting
32
+ Raygun.configuration.silence_reporting = true
33
+
34
+ # nothing returned as there's no HTTP call
35
+ assert_nil Raygun.track_exception(TestException.new)
36
+ end
37
+
38
+ def test_ignoring_exceptions
39
+ Raygun.configuration.ignore << TestException.to_s
40
+
41
+ assert_nil Raygun.track_exception(TestException.new)
42
+ end
43
+
44
+ def test_ignoring_multiple_exceptions
45
+ Raygun.configuration.ignore << [TestException.to_s, Test2Exception.to_s]
46
+
47
+ assert_nil Raygun.track_exception(TestException.new)
48
+ assert_nil Raygun.track_exception(Test2Exception.new)
49
+ end
50
+
51
+ def test_default_values
52
+ assert_equal({}, Raygun.configuration.custom_data)
53
+ end
54
+
55
+ def test_overriding_defaults
56
+ Raygun.default_configuration.custom_data = { robby: "robot" }
57
+ assert_equal({ robby: "robot" }, Raygun.configuration.custom_data)
58
+
59
+ Raygun.configuration.custom_data = { sally: "stegosaurus" }
60
+ assert_equal({ sally: "stegosaurus" }, Raygun.configuration.custom_data)
61
+ end
62
+
63
+ end
@@ -0,0 +1,95 @@
1
+ require_relative "../test_helper.rb"
2
+ require 'ostruct'
3
+ require 'raygun/middleware/rails_insert_affected_user'
4
+
5
+ class ClientTest < Raygun::UnitTest
6
+
7
+ class TestException < StandardError; end
8
+
9
+ class MockController
10
+
11
+ def user_with_email
12
+ OpenStruct.new(email: "testemail@something.com")
13
+ end
14
+
15
+ def user_with_login
16
+ OpenStruct.new(login: "topsecret")
17
+ end
18
+
19
+ def user_as_string
20
+ "some-string-identifier"
21
+ end
22
+
23
+ def no_logged_in_user
24
+ end
25
+ end
26
+
27
+ class MockApp
28
+ attr_accessor :env
29
+
30
+ def call(env)
31
+ @env = env
32
+ raise TestException.new
33
+ end
34
+ end
35
+
36
+ def setup
37
+ super
38
+ @client = Raygun::Client.new
39
+ fake_successful_entry
40
+
41
+ @app = MockApp.new
42
+ @controller = MockController.new
43
+ @middleware = Raygun::Middleware::RailsInsertAffectedUser.new(@app)
44
+ end
45
+
46
+ def test_inserting_user_object_with_email
47
+ Raygun.configuration.affected_user_method = :user_with_email
48
+ assert @controller.respond_to?(Raygun.configuration.affected_user_method)
49
+
50
+ begin
51
+ @middleware.call("action_controller.instance" => @controller)
52
+ rescue TestException
53
+ user_hash = { :identifier => "testemail@something.com" }
54
+ assert_equal user_hash, @app.env["raygun.affected_user"]
55
+ end
56
+ end
57
+
58
+ def test_inserting_user_object_with_login
59
+ Raygun.configuration.affected_user_method = :user_with_login
60
+ Raygun.configuration.affected_user_identifier_methods << :login
61
+
62
+ assert @controller.respond_to?(Raygun.configuration.affected_user_method)
63
+
64
+ begin
65
+ @middleware.call("action_controller.instance" => @controller)
66
+ rescue TestException
67
+ user_hash = { :identifier => "topsecret" }
68
+ assert_equal user_hash, @app.env["raygun.affected_user"]
69
+ end
70
+ end
71
+
72
+ def test_inserting_user_as_plain_string
73
+ Raygun.configuration.affected_user_method = :user_as_string
74
+ assert @controller.respond_to?(Raygun.configuration.affected_user_method)
75
+
76
+ begin
77
+ @middleware.call("action_controller.instance" => @controller)
78
+ rescue TestException
79
+ user_hash = { :identifier => "some-string-identifier" }
80
+ assert_equal user_hash, @app.env["raygun.affected_user"]
81
+ end
82
+ end
83
+
84
+ def test_with_a_nil_user
85
+ Raygun.configuration.affected_user_method = :no_logged_in_user
86
+ assert @controller.respond_to?(Raygun.configuration.affected_user_method)
87
+
88
+ begin
89
+ @middleware.call("action_controller.instance" => @controller)
90
+ rescue TestException
91
+ assert_nil @app.env["raygun.affected_user"]
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "../test_helper.rb"
2
+
3
+ # Very simple test
4
+ class ResqueFailureTest < Raygun::UnitTest
5
+
6
+ require "resque/failure/raygun"
7
+
8
+ def setup
9
+ super
10
+ fake_successful_entry
11
+ end
12
+
13
+ def test_failure_backend_appears_to_work
14
+ assert Resque::Failure::Raygun.new(
15
+ StandardError.new("Worker Problem"),
16
+ "TestWorker PID 123",
17
+ "super_important_jobs",
18
+ class: "SendCookies", args: [ "nik" ]
19
+ ).save.success?
20
+ end
21
+
22
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../test_helper.rb"
2
+
3
+ require "sidekiq"
4
+ # Convince Sidekiq it's on a server :)
5
+ module Sidekiq
6
+ def self.server?
7
+ true
8
+ end
9
+ end
10
+ require "raygun/sidekiq"
11
+
12
+ class SidekiqFailureTest < Raygun::UnitTest
13
+
14
+ def setup
15
+ super
16
+ fake_successful_entry
17
+ end
18
+
19
+ def test_failure_backend_appears_to_work
20
+ assert Raygun::SidekiqReporter.call(
21
+ StandardError.new("Oh no! Your Sidekiq has failed!"),
22
+ sidekick_name: "robin"
23
+ ).success?
24
+ end
25
+
26
+ def test_we_are_in_sidekiqs_list_of_error_handlers
27
+ assert Sidekiq.error_handlers.include?(Raygun::SidekiqReporter)
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindscape
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-27 00:00:00.000000000 Z
12
+ date: 2014-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -172,7 +172,12 @@ executables: []
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
+ - .gitignore
176
+ - .travis.yml
177
+ - Gemfile
178
+ - LICENSE.txt
175
179
  - README.md
180
+ - Rakefile
176
181
  - lib/generators/raygun/install_generator.rb
177
182
  - lib/raygun.rb
178
183
  - lib/raygun/client.rb
@@ -186,6 +191,14 @@ files:
186
191
  - lib/raygun4ruby.rb
187
192
  - lib/resque/failure/raygun.rb
188
193
  - lib/tasks/raygun.tasks
194
+ - raygun4ruby.gemspec
195
+ - test/integration/client_test.rb
196
+ - test/test_helper.rb
197
+ - test/unit/client_test.rb
198
+ - test/unit/configuration_test.rb
199
+ - test/unit/rails_insert_affected_user_test.rb
200
+ - test/unit/resque_failure_test.rb
201
+ - test/unit/sidekiq_failure_test.rb
189
202
  homepage: http://raygun.io
190
203
  licenses:
191
204
  - MIT
@@ -206,9 +219,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
219
  version: '0'
207
220
  requirements: []
208
221
  rubyforge_project:
209
- rubygems_version: 2.2.2
222
+ rubygems_version: 2.3.0
210
223
  signing_key:
211
224
  specification_version: 4
212
225
  summary: This gem provides support for Ruby and Ruby on Rails for the Raygun.io error
213
226
  reporter
214
- test_files: []
227
+ test_files:
228
+ - test/integration/client_test.rb
229
+ - test/test_helper.rb
230
+ - test/unit/client_test.rb
231
+ - test/unit/configuration_test.rb
232
+ - test/unit/rails_insert_affected_user_test.rb
233
+ - test/unit/resque_failure_test.rb
234
+ - test/unit/sidekiq_failure_test.rb