raygun4ruby 3.2.5.pre → 4.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +48 -0
- data/.gitignore +22 -21
- data/.rspec +1 -1
- data/Appraisals +19 -0
- data/CHANGELOG.md +169 -130
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +424 -420
- data/Rakefile +32 -27
- data/examples/sinatras_raygun.rb +17 -17
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_7.gemfile +10 -0
- data/gemfiles/rails_7_sidekiq_6.gemfile +10 -0
- data/lib/generators/raygun/install_generator.rb +26 -26
- data/lib/raygun/affected_user.rb +59 -59
- data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
- data/lib/raygun/breadcrumbs/store.rb +86 -86
- data/lib/raygun/breadcrumbs.rb +34 -34
- data/lib/raygun/client.rb +313 -308
- data/lib/raygun/configuration.rb +197 -194
- data/lib/raygun/demo_exception.rb +23 -0
- data/lib/raygun/error.rb +10 -10
- data/lib/raygun/error_subscriber.rb +21 -0
- 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 +40 -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 +47 -39
- data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
- data/lib/raygun/sidekiq.rb +51 -71
- data/lib/raygun/version.rb +3 -3
- data/lib/raygun.rb +197 -179
- data/lib/raygun4ruby.rb +1 -1
- data/lib/resque/failure/raygun.rb +25 -25
- data/lib/tasks/raygun.tasks +7 -7
- data/raygun4ruby.gemspec +43 -45
- data/spec/features/javascript_spec.rb +48 -48
- data/spec/rails_applications/6.1.4/Gemfile +56 -0
- data/spec/{dummy/README.rdoc → rails_applications/6.1.4/README.md} +24 -28
- data/spec/{dummy → rails_applications/6.1.4}/Rakefile +6 -6
- data/spec/rails_applications/6.1.4/app/assets/config/manifest.js +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/assets/stylesheets/application.css +15 -15
- data/spec/rails_applications/6.1.4/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/6.1.4/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/6.1.4/app/controllers/application_controller.rb +2 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/controllers/home_controller.rb +4 -4
- data/spec/{dummy → rails_applications/6.1.4}/app/helpers/application_helper.rb +2 -2
- data/spec/rails_applications/6.1.4/app/javascript/channels/consumer.js +6 -0
- data/spec/rails_applications/6.1.4/app/javascript/channels/index.js +5 -0
- data/spec/rails_applications/6.1.4/app/javascript/packs/application.js +13 -0
- data/spec/rails_applications/6.1.4/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/6.1.4/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/6.1.4/app/models/application_record.rb +3 -0
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.html.erb +3 -3
- data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.json.erb +1 -1
- data/spec/rails_applications/6.1.4/app/views/layouts/application.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/6.1.4/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/6.1.4/bin/rails +5 -0
- data/spec/rails_applications/6.1.4/bin/rake +5 -0
- data/spec/rails_applications/6.1.4/bin/setup +36 -0
- data/spec/rails_applications/6.1.4/bin/spring +14 -0
- data/spec/rails_applications/6.1.4/bin/yarn +17 -0
- data/spec/rails_applications/6.1.4/config/application.rb +22 -0
- data/spec/rails_applications/6.1.4/config/boot.rb +3 -0
- data/spec/rails_applications/6.1.4/config/cable.yml +10 -0
- data/spec/rails_applications/6.1.4/config/credentials.yml.enc +1 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/database.yml +25 -25
- data/spec/{dummy → rails_applications/6.1.4}/config/environment.rb +5 -5
- data/spec/rails_applications/6.1.4/config/environments/development.rb +76 -0
- data/spec/rails_applications/6.1.4/config/environments/production.rb +120 -0
- data/spec/rails_applications/6.1.4/config/environments/test.rb +60 -0
- data/spec/rails_applications/6.1.4/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/assets.rb +14 -0
- data/spec/rails_applications/6.1.4/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/rails_applications/6.1.4/config/initializers/content_security_policy.rb +30 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/cookies_serializer.rb +5 -3
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/filter_parameter_logging.rb +6 -4
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/inflections.rb +16 -16
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/mime_types.rb +4 -4
- data/spec/rails_applications/6.1.4/config/initializers/permissions_policy.rb +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/config/initializers/wrap_parameters.rb +14 -14
- data/spec/{dummy → rails_applications/6.1.4}/config/locales/en.yml +33 -23
- data/spec/rails_applications/6.1.4/config/master.key +1 -0
- data/spec/rails_applications/6.1.4/config/puma.rb +43 -0
- data/spec/rails_applications/6.1.4/config/routes.rb +4 -0
- data/spec/rails_applications/6.1.4/config/spring.rb +6 -0
- data/spec/rails_applications/6.1.4/config/storage.yml +34 -0
- data/spec/{dummy → rails_applications/6.1.4}/config.ru +6 -4
- data/spec/rails_applications/6.1.4/db/seeds.rb +7 -0
- data/spec/rails_applications/6.1.4/package.json +11 -0
- data/spec/{dummy → rails_applications/6.1.4}/public/404.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/422.html +67 -67
- data/spec/{dummy → rails_applications/6.1.4}/public/500.html +66 -66
- data/spec/rails_applications/6.1.4/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/.dockerignore +37 -0
- data/spec/rails_applications/7.1.3/.gitattributes +9 -0
- data/spec/rails_applications/7.1.3/.gitignore +35 -0
- data/spec/rails_applications/7.1.3/.ruby-version +1 -0
- data/spec/rails_applications/7.1.3/Dockerfile +62 -0
- data/spec/rails_applications/7.1.3/Gemfile +67 -0
- data/spec/rails_applications/7.1.3/README.md +24 -0
- data/spec/rails_applications/7.1.3/Rakefile +6 -0
- data/spec/rails_applications/7.1.3/app/assets/config/manifest.js +4 -0
- data/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails_applications/7.1.3/app/controllers/application_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/controllers/concerns/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/controllers/home_controller.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/application_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/helpers/home_helper.rb +2 -0
- data/spec/rails_applications/7.1.3/app/javascript/application.js +3 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/application.js +9 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js +7 -0
- data/spec/rails_applications/7.1.3/app/javascript/controllers/index.js +11 -0
- data/spec/rails_applications/7.1.3/app/jobs/application_job.rb +7 -0
- data/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb +4 -0
- data/spec/rails_applications/7.1.3/app/models/application_record.rb +3 -0
- data/spec/rails_applications/7.1.3/app/models/concerns/.keep +0 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.html.erb +3 -0
- data/spec/rails_applications/7.1.3/app/views/home/index.json.erb +1 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb +16 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails_applications/7.1.3/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails_applications/7.1.3/bin/bundle +109 -0
- data/spec/rails_applications/7.1.3/bin/docker-entrypoint +8 -0
- data/spec/rails_applications/7.1.3/bin/importmap +4 -0
- data/spec/rails_applications/7.1.3/bin/rails +4 -0
- data/spec/rails_applications/7.1.3/bin/rake +4 -0
- data/spec/rails_applications/7.1.3/bin/setup +33 -0
- data/spec/rails_applications/7.1.3/config/application.rb +27 -0
- data/spec/rails_applications/7.1.3/config/boot.rb +4 -0
- data/spec/rails_applications/7.1.3/config/cable.yml +11 -0
- data/spec/rails_applications/7.1.3/config/credentials.yml.enc +1 -0
- data/spec/rails_applications/7.1.3/config/database.yml +25 -0
- data/spec/rails_applications/7.1.3/config/environment.rb +5 -0
- data/spec/rails_applications/7.1.3/config/environments/development.rb +76 -0
- data/spec/rails_applications/7.1.3/config/environments/production.rb +97 -0
- data/spec/rails_applications/7.1.3/config/environments/test.rb +64 -0
- data/spec/rails_applications/7.1.3/config/importmap.rb +7 -0
- data/spec/rails_applications/7.1.3/config/initializers/assets.rb +12 -0
- data/spec/rails_applications/7.1.3/config/initializers/content_security_policy.rb +25 -0
- data/spec/rails_applications/7.1.3/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/rails_applications/7.1.3/config/initializers/inflections.rb +16 -0
- data/spec/rails_applications/7.1.3/config/initializers/permissions_policy.rb +13 -0
- data/spec/rails_applications/7.1.3/config/locales/en.yml +31 -0
- data/spec/rails_applications/7.1.3/config/puma.rb +35 -0
- data/spec/rails_applications/7.1.3/config/routes.rb +11 -0
- data/spec/rails_applications/7.1.3/config/storage.yml +34 -0
- data/spec/rails_applications/7.1.3/config.ru +6 -0
- data/spec/rails_applications/7.1.3/db/seeds.rb +9 -0
- data/spec/rails_applications/7.1.3/lib/assets/.keep +0 -0
- data/spec/rails_applications/7.1.3/lib/tasks/.keep +0 -0
- data/spec/rails_applications/7.1.3/public/404.html +67 -0
- data/spec/rails_applications/7.1.3/public/422.html +67 -0
- data/spec/rails_applications/7.1.3/public/500.html +66 -0
- data/spec/rails_applications/7.1.3/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/rails_applications/7.1.3/public/apple-touch-icon.png +0 -0
- data/spec/rails_applications/7.1.3/public/favicon.ico +0 -0
- data/spec/rails_applications/7.1.3/public/robots.txt +1 -0
- data/spec/rails_applications/7.1.3/storage/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/application_system_test_case.rb +5 -0
- data/spec/rails_applications/7.1.3/test/channels/application_cable/connection_test.rb +13 -0
- data/spec/rails_applications/7.1.3/test/controllers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/controllers/home_controller_test.rb +7 -0
- data/spec/rails_applications/7.1.3/test/fixtures/files/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/helpers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/integration/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/mailers/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/models/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/system/.keep +0 -0
- data/spec/rails_applications/7.1.3/test/test_helper.rb +15 -0
- data/spec/rails_applications/7.1.3/vendor/.keep +0 -0
- data/spec/rails_applications/7.1.3/vendor/javascript/.keep +0 -0
- data/spec/rails_helper.rb +8 -4
- data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
- data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
- 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/rails_helper.rb +6 -0
- data/test/test_helper.rb +76 -72
- data/test/unit/affected_user_test.rb +136 -136
- data/test/unit/client_test.rb +812 -812
- data/test/unit/configuration_test.rb +202 -206
- data/test/unit/error_subscriber_test.rb +43 -0
- data/test/unit/raygun_test.rb +106 -25
- data/test/unit/resque_failure_test.rb +27 -24
- data/test/unit/sidekiq_failure_test.rb +42 -32
- metadata +186 -115
- data/.travis.yml +0 -20
- data/spec/dummy/.gitignore +0 -17
- data/spec/dummy/Gemfile +0 -47
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -3
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/raygun/raygun_spec.rb +0 -47
- /data/spec/{dummy → rails_applications/6.1.4}/app/assets/images/.keep +0 -0
- /data/spec/{dummy → rails_applications/6.1.4}/app/controllers/concerns/.keep +0 -0
- /data/spec/{dummy/app/mailers → rails_applications/6.1.4/app/models/concerns}/.keep +0 -0
- /data/spec/{dummy/app/models/.keep → rails_applications/6.1.4/db/test.sqlite3} +0 -0
- /data/spec/{dummy/app/models/concerns → rails_applications/6.1.4/lib/assets}/.keep +0 -0
- /data/spec/{dummy/lib/assets → rails_applications/6.1.4/lib/tasks}/.keep +0 -0
- /data/spec/{dummy/lib/tasks/.keep → rails_applications/6.1.4/public/apple-touch-icon-precomposed.png} +0 -0
- /data/spec/{dummy/log/.keep → rails_applications/6.1.4/public/apple-touch-icon.png} +0 -0
- /data/spec/{dummy → rails_applications/6.1.4}/public/favicon.ico +0 -0
- /data/spec/{dummy/vendor/assets/javascripts → rails_applications/6.1.4/storage}/.keep +0 -0
- /data/spec/{dummy/vendor/assets/stylesheets → rails_applications/7.1.3/app/assets/images}/.keep +0 -0
data/test/test_helper.rb
CHANGED
@@ -1,72 +1,76 @@
|
|
1
|
-
ENV['RACK_ENV'] = 'test'
|
2
|
-
|
3
|
-
require "minitest/
|
4
|
-
require "
|
5
|
-
require "
|
6
|
-
require "
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Raygun.
|
63
|
-
end
|
64
|
-
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
logger
|
71
|
-
|
72
|
-
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest/pride"
|
4
|
+
require "timecop"
|
5
|
+
require "mocha/minitest"
|
6
|
+
require "stringio"
|
7
|
+
require "webmock/minitest"
|
8
|
+
|
9
|
+
require_relative "./rails_helper"
|
10
|
+
require_relative "../lib/raygun.rb"
|
11
|
+
|
12
|
+
# Ensure we start with a known state
|
13
|
+
Raygun.reset_configuration
|
14
|
+
|
15
|
+
class FakeLogger
|
16
|
+
def initialize
|
17
|
+
@logger = StringIO.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def info(message)
|
21
|
+
@logger.write(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset
|
25
|
+
@logger.string = ""
|
26
|
+
end
|
27
|
+
|
28
|
+
def get
|
29
|
+
@logger.string
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class NoApiKey < StandardError; end
|
34
|
+
|
35
|
+
class Raygun::IntegrationTest < Minitest::Test
|
36
|
+
|
37
|
+
def setup
|
38
|
+
Raygun.setup do |config|
|
39
|
+
config.api_key = File.open(File.expand_path("~/.raygun4ruby-test-key"), "rb").read
|
40
|
+
config.version = Raygun::VERSION
|
41
|
+
end
|
42
|
+
|
43
|
+
rescue Errno::ENOENT
|
44
|
+
raise NoApiKey.new("Place a valid Raygun API key into ~/.raygun4ruby-test-key to run integration tests") unless api_key
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown
|
48
|
+
Raygun.wait_for_futures
|
49
|
+
Raygun.reset_configuration
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class Raygun::UnitTest < Minitest::Test
|
55
|
+
|
56
|
+
def setup
|
57
|
+
Raygun.configuration.api_key = "test api key"
|
58
|
+
end
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
Raygun.wait_for_futures
|
62
|
+
Raygun.reset_configuration
|
63
|
+
end
|
64
|
+
|
65
|
+
def fake_successful_entry
|
66
|
+
stub_request(:post, 'https://api.raygun.com/entries').to_return(status: 202)
|
67
|
+
end
|
68
|
+
|
69
|
+
def setup_logging
|
70
|
+
logger = FakeLogger.new
|
71
|
+
Raygun.configuration.debug = true
|
72
|
+
Raygun.configuration.logger = logger
|
73
|
+
|
74
|
+
logger
|
75
|
+
end
|
76
|
+
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
|