raygun4ruby 3.2.0 → 3.2.5.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +21 -18
- data/.rspec +1 -1
- data/.travis.yml +20 -12
- data/CHANGELOG.md +130 -117
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +420 -420
- data/Rakefile +27 -27
- data/examples/sinatras_raygun.rb +17 -17
- data/lib/generators/raygun/install_generator.rb +26 -26
- data/lib/raygun.rb +179 -179
- data/lib/raygun/affected_user.rb +59 -59
- data/lib/raygun/breadcrumbs.rb +34 -34
- data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
- data/lib/raygun/breadcrumbs/store.rb +86 -86
- data/lib/raygun/client.rb +308 -303
- data/lib/raygun/configuration.rb +194 -194
- data/lib/raygun/error.rb +10 -10
- data/lib/raygun/javascript_tracker.rb +42 -42
- data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
- data/lib/raygun/middleware/javascript_exception_tracking.rb +32 -32
- data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
- data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
- data/lib/raygun/railtie.rb +39 -39
- data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
- data/lib/raygun/sidekiq.rb +71 -67
- data/lib/raygun/version.rb +3 -3
- data/lib/raygun4ruby.rb +1 -1
- data/lib/resque/failure/raygun.rb +25 -25
- data/lib/tasks/raygun.tasks +7 -7
- data/raygun4ruby.gemspec +45 -45
- data/spec/dummy/.gitignore +17 -0
- data/spec/dummy/Gemfile +47 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -6
- data/spec/dummy/app/assets/config/manifest.js +3 -3
- data/spec/dummy/app/assets/javascripts/application.js +13 -15
- data/spec/dummy/app/assets/stylesheets/application.css +15 -15
- data/spec/dummy/app/controllers/application_controller.rb +5 -2
- data/spec/dummy/app/controllers/home_controller.rb +4 -4
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/{assets/javascripts/channels → mailers}/.keep +0 -0
- data/spec/dummy/{storage → app/models}/.keep +0 -0
- data/spec/dummy/app/views/home/index.html.erb +3 -3
- data/spec/dummy/app/views/home/index.json.erb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +14 -15
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +9 -4
- data/spec/dummy/bin/rake +9 -4
- data/spec/dummy/bin/setup +29 -36
- data/spec/dummy/bin/spring +17 -0
- data/spec/dummy/config.ru +4 -5
- data/spec/dummy/config/application.rb +26 -18
- data/spec/dummy/config/boot.rb +3 -5
- data/spec/dummy/config/database.yml +25 -25
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +41 -61
- data/spec/dummy/config/environments/production.rb +79 -94
- data/spec/dummy/config/initializers/assets.rb +11 -14
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/mime_types.rb +4 -4
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +23 -33
- data/spec/dummy/config/routes.rb +58 -3
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/{db/test.sqlite3 → lib/tasks/.keep} +0 -0
- data/spec/dummy/public/404.html +67 -67
- data/spec/dummy/public/422.html +67 -67
- data/spec/dummy/public/500.html +66 -66
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/{public/apple-touch-icon-precomposed.png → vendor/assets/javascripts/.keep} +0 -0
- data/spec/dummy/{public/apple-touch-icon.png → vendor/assets/stylesheets/.keep} +0 -0
- data/spec/features/javascript_spec.rb +48 -48
- data/spec/rails_helper.rb +4 -4
- data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
- data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
- data/spec/raygun/raygun_spec.rb +47 -47
- data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
- data/spec/spec_helper.rb +24 -24
- data/spec/support/fake_logger.rb +17 -17
- data/test/integration/client_test.rb +19 -19
- data/test/test_helper.rb +72 -72
- data/test/unit/affected_user_test.rb +136 -136
- data/test/unit/client_test.rb +812 -790
- data/test/unit/configuration_test.rb +206 -206
- data/test/unit/raygun_test.rb +25 -25
- data/test/unit/resque_failure_test.rb +24 -24
- data/test/unit/sidekiq_failure_test.rb +32 -32
- metadata +36 -49
- data/lib/raygun/testable.rb +0 -23
- data/spec/dummy/.ruby-version +0 -1
- data/spec/dummy/app/assets/javascripts/cable.js +0 -13
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
- data/spec/dummy/app/jobs/application_job.rb +0 -2
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/bin/update +0 -31
- data/spec/dummy/bin/yarn +0 -11
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/environments/test.rb +0 -46
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/spec/dummy/config/initializers/content_security_policy.rb +0 -25
- data/spec/dummy/config/puma.rb +0 -34
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/config/storage.yml +0 -34
- data/spec/dummy/db/schema.rb +0 -15
- data/spec/dummy/package.json +0 -5
data/spec/spec_helper.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
#require 'rubygems'
|
2
|
-
|
3
|
-
require 'timecop'
|
4
|
-
require 'webmock/rspec'
|
5
|
-
|
6
|
-
# Coverage
|
7
|
-
require 'simplecov'
|
8
|
-
SimpleCov.start do
|
9
|
-
add_filter '/spec/'
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'support/fake_logger'
|
13
|
-
|
14
|
-
RSpec.configure do |config|
|
15
|
-
# Enable flags like --only-failures and --next-failure
|
16
|
-
# config.example_status_persistence_file_path = ".rspec_status"
|
17
|
-
|
18
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
19
|
-
# config.disable_monkey_patching!
|
20
|
-
|
21
|
-
config.expect_with :rspec do |c|
|
22
|
-
c.syntax = :expect
|
23
|
-
end
|
24
|
-
end
|
1
|
+
#require 'rubygems'
|
2
|
+
|
3
|
+
require 'timecop'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
# Coverage
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'support/fake_logger'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
# Enable flags like --only-failures and --next-failure
|
16
|
+
# config.example_status_persistence_file_path = ".rspec_status"
|
17
|
+
|
18
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
19
|
+
# config.disable_monkey_patching!
|
20
|
+
|
21
|
+
config.expect_with :rspec do |c|
|
22
|
+
c.syntax = :expect
|
23
|
+
end
|
24
|
+
end
|
data/spec/support/fake_logger.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
class FakeLogger
|
2
|
-
def initialize
|
3
|
-
@logger = StringIO.new
|
4
|
-
end
|
5
|
-
|
6
|
-
def info(message)
|
7
|
-
@logger.write(message)
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
@logger.string = ""
|
12
|
-
end
|
13
|
-
|
14
|
-
def get
|
15
|
-
@logger.string
|
16
|
-
end
|
17
|
-
end
|
1
|
+
class FakeLogger
|
2
|
+
def initialize
|
3
|
+
@logger = StringIO.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def info(message)
|
7
|
+
@logger.write(message)
|
8
|
+
end
|
9
|
+
|
10
|
+
def reset
|
11
|
+
@logger.string = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def get
|
15
|
+
@logger.string
|
16
|
+
end
|
17
|
+
end
|
@@ -1,20 +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
|
-
|
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
20
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,72 +1,72 @@
|
|
1
|
-
ENV['RACK_ENV'] = 'test'
|
2
|
-
require_relative "../lib/raygun.rb"
|
3
|
-
require "minitest/autorun"
|
4
|
-
require "minitest/pride"
|
5
|
-
require "timecop"
|
6
|
-
require "mocha/
|
7
|
-
require 'stringio'
|
8
|
-
require 'webmock/minitest'
|
9
|
-
|
10
|
-
class FakeLogger
|
11
|
-
def initialize
|
12
|
-
@logger = StringIO.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def info(message)
|
16
|
-
@logger.write(message)
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset
|
20
|
-
@logger.string = ""
|
21
|
-
end
|
22
|
-
|
23
|
-
def get
|
24
|
-
@logger.string
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class NoApiKey < StandardError; end
|
29
|
-
|
30
|
-
class Raygun::IntegrationTest < Minitest::
|
31
|
-
|
32
|
-
def setup
|
33
|
-
Raygun.setup do |config|
|
34
|
-
config.api_key = File.open(File.expand_path("~/.raygun4ruby-test-key"), "rb").read
|
35
|
-
config.version = Raygun::VERSION
|
36
|
-
end
|
37
|
-
|
38
|
-
rescue Errno::ENOENT
|
39
|
-
raise NoApiKey.new("Place a valid Raygun API key into ~/.raygun4ruby-test-key to run integration tests") unless api_key
|
40
|
-
end
|
41
|
-
|
42
|
-
def teardown
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
class Raygun::UnitTest < MiniTest::
|
48
|
-
|
49
|
-
def setup
|
50
|
-
Raygun.configuration.api_key = "test api key"
|
51
|
-
end
|
52
|
-
|
53
|
-
def teardown
|
54
|
-
reset_configuration
|
55
|
-
end
|
56
|
-
|
57
|
-
def fake_successful_entry
|
58
|
-
stub_request(:post, 'https://api.raygun.
|
59
|
-
end
|
60
|
-
|
61
|
-
def reset_configuration
|
62
|
-
Raygun.configuration = Raygun::Configuration.new
|
63
|
-
end
|
64
|
-
|
65
|
-
def setup_logging
|
66
|
-
logger = FakeLogger.new
|
67
|
-
Raygun.configuration.debug = true
|
68
|
-
Raygun.configuration.logger = logger
|
69
|
-
|
70
|
-
logger
|
71
|
-
end
|
72
|
-
end
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require_relative "../lib/raygun.rb"
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "minitest/pride"
|
5
|
+
require "timecop"
|
6
|
+
require "mocha/minitest"
|
7
|
+
require 'stringio'
|
8
|
+
require 'webmock/minitest'
|
9
|
+
|
10
|
+
class FakeLogger
|
11
|
+
def initialize
|
12
|
+
@logger = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def info(message)
|
16
|
+
@logger.write(message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
@logger.string = ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def get
|
24
|
+
@logger.string
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class NoApiKey < StandardError; end
|
29
|
+
|
30
|
+
class Raygun::IntegrationTest < Minitest::Test
|
31
|
+
|
32
|
+
def setup
|
33
|
+
Raygun.setup do |config|
|
34
|
+
config.api_key = File.open(File.expand_path("~/.raygun4ruby-test-key"), "rb").read
|
35
|
+
config.version = Raygun::VERSION
|
36
|
+
end
|
37
|
+
|
38
|
+
rescue Errno::ENOENT
|
39
|
+
raise NoApiKey.new("Place a valid Raygun API key into ~/.raygun4ruby-test-key to run integration tests") unless api_key
|
40
|
+
end
|
41
|
+
|
42
|
+
def teardown
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class Raygun::UnitTest < MiniTest::Test
|
48
|
+
|
49
|
+
def setup
|
50
|
+
Raygun.configuration.api_key = "test api key"
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
reset_configuration
|
55
|
+
end
|
56
|
+
|
57
|
+
def fake_successful_entry
|
58
|
+
stub_request(:post, 'https://api.raygun.com/entries').to_return(status: 202)
|
59
|
+
end
|
60
|
+
|
61
|
+
def reset_configuration
|
62
|
+
Raygun.configuration = Raygun::Configuration.new
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup_logging
|
66
|
+
logger = FakeLogger.new
|
67
|
+
Raygun.configuration.debug = true
|
68
|
+
Raygun.configuration.logger = logger
|
69
|
+
|
70
|
+
logger
|
71
|
+
end
|
72
|
+
end
|
@@ -1,136 +1,136 @@
|
|
1
|
-
require_relative "../test_helper.rb"
|
2
|
-
require 'ostruct'
|
3
|
-
require 'raygun/middleware/rails_insert_affected_user'
|
4
|
-
|
5
|
-
class AffectedUserTest < Raygun::UnitTest
|
6
|
-
|
7
|
-
class TestException < StandardError; end
|
8
|
-
|
9
|
-
class MockController
|
10
|
-
|
11
|
-
def user_with_email
|
12
|
-
OpenStruct.new(id: 123, email: "testemail@something.com")
|
13
|
-
end
|
14
|
-
|
15
|
-
def user_with_login
|
16
|
-
OpenStruct.new(login: "topsecret")
|
17
|
-
end
|
18
|
-
|
19
|
-
def user_with_full_details
|
20
|
-
OpenStruct.new(id: 123, email: "testemail@something.com", first_name: "Taylor", last_name: "Lodge")
|
21
|
-
end
|
22
|
-
|
23
|
-
def user_as_string
|
24
|
-
"some-string-identifier"
|
25
|
-
end
|
26
|
-
|
27
|
-
def no_logged_in_user
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def private_current_user
|
33
|
-
user_with_email
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
class MockApp
|
39
|
-
attr_accessor :env
|
40
|
-
|
41
|
-
def call(env)
|
42
|
-
@env = env
|
43
|
-
raise TestException.new
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup
|
48
|
-
super
|
49
|
-
@client = Raygun::Client.new
|
50
|
-
fake_successful_entry
|
51
|
-
|
52
|
-
@app = MockApp.new
|
53
|
-
@controller = MockController.new
|
54
|
-
@middleware = Raygun::Middleware::RailsInsertAffectedUser.new(@app)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_inserting_user_object_with_email
|
58
|
-
Raygun.configuration.affected_user_method = :user_with_email
|
59
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
60
|
-
|
61
|
-
begin
|
62
|
-
@middleware.call("action_controller.instance" => @controller)
|
63
|
-
rescue TestException
|
64
|
-
user_hash = { :identifier => 123, :email => "testemail@something.com", :isAnonymous => false }
|
65
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_changing_method_mapping
|
70
|
-
Raygun.configuration.affected_user_method = :user_with_login
|
71
|
-
Raygun.configuration.affected_user_mapping = {
|
72
|
-
identifier: :login
|
73
|
-
}
|
74
|
-
|
75
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
76
|
-
|
77
|
-
begin
|
78
|
-
@middleware.call("action_controller.instance" => @controller)
|
79
|
-
rescue TestException
|
80
|
-
user_hash = { :identifier => "topsecret", :isAnonymous => false }
|
81
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_inserting_user_as_plain_string
|
86
|
-
Raygun.configuration.affected_user_method = :user_as_string
|
87
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
88
|
-
|
89
|
-
begin
|
90
|
-
@middleware.call("action_controller.instance" => @controller)
|
91
|
-
rescue TestException
|
92
|
-
user_hash = { :identifier => "some-string-identifier", :isAnonymous => true }
|
93
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_with_a_nil_user
|
98
|
-
Raygun.configuration.affected_user_method = :no_logged_in_user
|
99
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
100
|
-
|
101
|
-
begin
|
102
|
-
@middleware.call("action_controller.instance" => @controller)
|
103
|
-
rescue TestException
|
104
|
-
user_hash = { :isAnonymous => true }
|
105
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_with_private_method
|
110
|
-
Raygun.configuration.affected_user_method = :private_current_user
|
111
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method, true)
|
112
|
-
|
113
|
-
begin
|
114
|
-
@middleware.call("action_controller.instance" => @controller)
|
115
|
-
rescue TestException
|
116
|
-
user_hash = {:isAnonymous=>false, :identifier=>123, :email=>"testemail@something.com"}
|
117
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_with_proc_for_mapping
|
122
|
-
Raygun.configuration.affected_user_method = :user_with_full_details
|
123
|
-
Raygun.configuration.affected_user_mapping = Raygun::AffectedUser::DEFAULT_MAPPING.merge({
|
124
|
-
full_name: ->(user) { "#{user.first_name} #{user.last_name}" }
|
125
|
-
})
|
126
|
-
|
127
|
-
assert @controller.respond_to?(Raygun.configuration.affected_user_method, true)
|
128
|
-
|
129
|
-
begin
|
130
|
-
@middleware.call("action_controller.instance" => @controller)
|
131
|
-
rescue TestException
|
132
|
-
user_hash = {:isAnonymous=>false, :identifier=>123, :email=>"testemail@something.com", :fullName => "Taylor Lodge", :firstName => "Taylor"}
|
133
|
-
assert_equal user_hash, @app.env["raygun.affected_user"]
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
1
|
+
require_relative "../test_helper.rb"
|
2
|
+
require 'ostruct'
|
3
|
+
require 'raygun/middleware/rails_insert_affected_user'
|
4
|
+
|
5
|
+
class AffectedUserTest < Raygun::UnitTest
|
6
|
+
|
7
|
+
class TestException < StandardError; end
|
8
|
+
|
9
|
+
class MockController
|
10
|
+
|
11
|
+
def user_with_email
|
12
|
+
OpenStruct.new(id: 123, email: "testemail@something.com")
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_with_login
|
16
|
+
OpenStruct.new(login: "topsecret")
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_with_full_details
|
20
|
+
OpenStruct.new(id: 123, email: "testemail@something.com", first_name: "Taylor", last_name: "Lodge")
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_as_string
|
24
|
+
"some-string-identifier"
|
25
|
+
end
|
26
|
+
|
27
|
+
def no_logged_in_user
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def private_current_user
|
33
|
+
user_with_email
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class MockApp
|
39
|
+
attr_accessor :env
|
40
|
+
|
41
|
+
def call(env)
|
42
|
+
@env = env
|
43
|
+
raise TestException.new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup
|
48
|
+
super
|
49
|
+
@client = Raygun::Client.new
|
50
|
+
fake_successful_entry
|
51
|
+
|
52
|
+
@app = MockApp.new
|
53
|
+
@controller = MockController.new
|
54
|
+
@middleware = Raygun::Middleware::RailsInsertAffectedUser.new(@app)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_inserting_user_object_with_email
|
58
|
+
Raygun.configuration.affected_user_method = :user_with_email
|
59
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
60
|
+
|
61
|
+
begin
|
62
|
+
@middleware.call("action_controller.instance" => @controller)
|
63
|
+
rescue TestException
|
64
|
+
user_hash = { :identifier => 123, :email => "testemail@something.com", :isAnonymous => false }
|
65
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_changing_method_mapping
|
70
|
+
Raygun.configuration.affected_user_method = :user_with_login
|
71
|
+
Raygun.configuration.affected_user_mapping = {
|
72
|
+
identifier: :login
|
73
|
+
}
|
74
|
+
|
75
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
76
|
+
|
77
|
+
begin
|
78
|
+
@middleware.call("action_controller.instance" => @controller)
|
79
|
+
rescue TestException
|
80
|
+
user_hash = { :identifier => "topsecret", :isAnonymous => false }
|
81
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_inserting_user_as_plain_string
|
86
|
+
Raygun.configuration.affected_user_method = :user_as_string
|
87
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
88
|
+
|
89
|
+
begin
|
90
|
+
@middleware.call("action_controller.instance" => @controller)
|
91
|
+
rescue TestException
|
92
|
+
user_hash = { :identifier => "some-string-identifier", :isAnonymous => true }
|
93
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_with_a_nil_user
|
98
|
+
Raygun.configuration.affected_user_method = :no_logged_in_user
|
99
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method)
|
100
|
+
|
101
|
+
begin
|
102
|
+
@middleware.call("action_controller.instance" => @controller)
|
103
|
+
rescue TestException
|
104
|
+
user_hash = { :isAnonymous => true }
|
105
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_with_private_method
|
110
|
+
Raygun.configuration.affected_user_method = :private_current_user
|
111
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method, true)
|
112
|
+
|
113
|
+
begin
|
114
|
+
@middleware.call("action_controller.instance" => @controller)
|
115
|
+
rescue TestException
|
116
|
+
user_hash = {:isAnonymous=>false, :identifier=>123, :email=>"testemail@something.com"}
|
117
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_with_proc_for_mapping
|
122
|
+
Raygun.configuration.affected_user_method = :user_with_full_details
|
123
|
+
Raygun.configuration.affected_user_mapping = Raygun::AffectedUser::DEFAULT_MAPPING.merge({
|
124
|
+
full_name: ->(user) { "#{user.first_name} #{user.last_name}" }
|
125
|
+
})
|
126
|
+
|
127
|
+
assert @controller.respond_to?(Raygun.configuration.affected_user_method, true)
|
128
|
+
|
129
|
+
begin
|
130
|
+
@middleware.call("action_controller.instance" => @controller)
|
131
|
+
rescue TestException
|
132
|
+
user_hash = {:isAnonymous=>false, :identifier=>123, :email=>"testemail@something.com", :fullName => "Taylor Lodge", :firstName => "Taylor"}
|
133
|
+
assert_equal user_hash, @app.env["raygun.affected_user"]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|