Skip to content

Commit 2bdf4ff

Browse files
committed
fix(rails): avoid filter_parameters accumulation between spec runs
1 parent f515889 commit 2bdf4ff

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

sentry-rails/spec/dummy/test_rails_app/app.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def self.name
5858
app.config.active_job.queue_adapter = :test
5959
app.config.cache_store = :memory_store
6060
app.config.action_controller.perform_caching = true
61-
app.config.filter_parameters += [:password, :secret]
6261

6362
# Eager load namespaces can be accumulated after repeated initializations and make initialization
6463
# slower after each run
@@ -70,15 +69,15 @@ def self.name
7069
configure_app(app)
7170

7271
# Configure parameter filtering for consistent test behavior
73-
app.config.filter_parameters.concat(
74-
[:custom_secret,
75-
:api_key,
76-
:credit_card,
77-
:authorization,
78-
:password,
79-
:token]
80-
)
81-
app.config.filter_parameters.uniq!
72+
app.config.filter_parameters = [
73+
:password,
74+
:secret,
75+
:custom_secret,
76+
:api_key,
77+
:credit_card,
78+
:authorization,
79+
:token
80+
]
8281

8382
app.routes.append do
8483
get "/exception", to: "hello#exception"

sentry-rails/spec/dummy/test_rails_app/configs/7-1.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def run_pre_initialize_cleanup
3030
# Rails 7.1 stores the error reporter directly under the ActiveSupport class.
3131
# So we need to make sure the subscriber is not subscribed unexpectedly before any tests
3232
ActiveSupport.error_reporter.unsubscribe(Sentry::Rails::ErrorSubscriber)
33+
34+
if ActiveSupport.respond_to?(:filter_parameters)
35+
ActiveSupport.filter_parameters.clear
36+
end
3337
end
3438

3539
def configure_app(app)

sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def run_pre_initialize_cleanup
3030
# Rails 7.1 stores the error reporter directly under the ActiveSupport class.
3131
# So we need to make sure the subscriber is not subscribed unexpectedly before any tests
3232
ActiveSupport.error_reporter.unsubscribe(Sentry::Rails::ErrorSubscriber)
33+
34+
if ActiveSupport.respond_to?(:filter_parameters)
35+
ActiveSupport.filter_parameters.clear
36+
end
3337
end
3438

3539
def configure_app(app)

sentry-rails/spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
end
6565

6666
reset_sentry_globals!
67+
68+
Rails.application = nil
6769
end
6870

6971
config.before :each do

0 commit comments

Comments
 (0)