Skip to content

Commit

Permalink
Update setup for Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Oct 5, 2023
1 parent 58253af commit d7b0e75
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
6 changes: 4 additions & 2 deletions sentry-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ platform :jruby do
end

rails_version = ENV["RAILS_VERSION"]
rails_version = "7.0.0" if rails_version.nil?
rails_version = "7.1.0" if rails_version.nil?
rails_version = Gem::Version.new(rails_version)

if rails_version < Gem::Version.new("6.0.0")
Expand All @@ -20,8 +20,10 @@ else
gem "sqlite3", platform: :ruby
end

if rails_version > Gem::Version.new("7.0.0")
if rails_version >= Gem::Version.new("7.2.0.alpha")
gem "rails", github: "rails/rails"
elsif rails_version >= Gem::Version.new("7.1.0")
gem "rails", "~> #{rails_version}"
else
gem "rails", "~> #{rails_version}"
gem "psych", "~> 3.0.0"
Expand Down
36 changes: 36 additions & 0 deletions sentry-rails/spec/dummy/test_rails_app/configs/7-2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "active_storage/engine"
require "action_cable/engine"
require "sentry/rails/error_subscriber"

def run_pre_initialize_cleanup
# Zeitwerk checks if registered loaders load paths repeatedly and raises error if that happens.
# And because every new Rails::Application instance registers its own loader, we need to clear previously registered ones from Zeitwerk.
Zeitwerk::Registry.loaders.clear

# Rails removes the support of multiple instances, which includes freezing some setting values.
# This is the workaround to avoid FrozenError. Related issue: https://github.com/rails/rails/issues/42319
ActiveSupport::Dependencies.autoload_once_paths = []
ActiveSupport::Dependencies.autoload_paths = []

# there are a few Rails initializers/finializers that register hook to the executor
# because the callbacks are stored inside the `ActiveSupport::Executor` class instead of an instance
# the callbacks duplicate after each time we initialize the application and cause issues when they're executed
ActiveSupport::Executor.reset_callbacks(:run)
ActiveSupport::Executor.reset_callbacks(:complete)

# Rails uses this module to set a global context for its ErrorReporter feature.
# this needs to be cleared so previously set context won't pollute later reportings (see ErrorSubscriber).
ActiveSupport::ExecutionContext.clear

ActionCable::Channel::Base.reset_callbacks(:subscribe)
ActionCable::Channel::Base.reset_callbacks(:unsubscribe)

# Rails 7.1 stores the error reporter directly under the ActiveSupport class.
# So we need to make sure the subscriber is not subscribed unexpectedly before any tests
ActiveSupport.error_reporter.unsubscribe(Sentry::Rails::ErrorSubscriber)
end

def configure_app(app)
app.config.active_storage.service = :test
app.config.enable_reloading = false
end
6 changes: 0 additions & 6 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
make_basic_app
end

after do
# We need to cleanup Rails.logger because after https://github.com/rails/rails/pull/49417
# Rails.logger could get recreated with the previous logger value and become deeply nested broadcast logger
Rails.logger = nil
end

it "has version set" do
expect(described_class::VERSION).to be_a(String)
end
Expand Down

0 comments on commit d7b0e75

Please sign in to comment.