Skip to content

Commit

Permalink
Make tests pass on Rails 7.2.0.alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Apr 9, 2024
1 parent ae872bf commit 7c80c1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 15 additions & 3 deletions test/rodauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ class RodauthTest < UnitTest

if Rails.gem_version >= Gem::Version.new("5.2.0")
Rails.application.credentials.secret_key_base = "credential"
assert_equal "credential", Rodauth::Rails.secret_key_base
reset_secret_key_base do
assert_equal "credential", Rodauth::Rails.secret_key_base
end

ENV["SECRET_KEY_BASE"] = "environment"
assert_equal "environment", Rodauth::Rails.secret_key_base
reset_secret_key_base do
assert_equal "environment", Rodauth::Rails.secret_key_base
end
ENV.delete("SECRET_KEY_BASE")
end

ensure
Rails.env = "test"
end

Expand Down Expand Up @@ -114,4 +118,12 @@ class RodauthTest < UnitTest

refute_includes app.instance_methods, :render
end

def reset_secret_key_base
original_secret_key_base = Rails.configuration.secret_key_base
Rails.configuration.secret_key_base = nil
yield
ensure
Rails.configuration.secret_key_base = original_secret_key_base
end
end
8 changes: 6 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
module TestSetupTeardown
def setup
super
if ActiveRecord.version >= Gem::Version.new("5.2")
if ActiveRecord.version >= Gem::Version.new("7.2.0.alpha")
ActiveRecord::Base.connection_pool.migration_context.up
elsif ActiveRecord.version >= Gem::Version.new("5.2")
ActiveRecord::Base.connection.migration_context.up
else
ActiveRecord::Migrator.up(Rails.application.paths["db/migrate"].to_a)
Expand All @@ -25,7 +27,9 @@ def setup

def teardown
super
if ActiveRecord.version >= Gem::Version.new("5.2")
if ActiveRecord.version >= Gem::Version.new("7.2.0.alpha")
ActiveRecord::Base.connection_pool.migration_context.up
elsif ActiveRecord.version >= Gem::Version.new("5.2")
ActiveRecord::Base.connection.migration_context.down
else
ActiveRecord::Migrator.down(Rails.application.paths["db/migrate"].to_a)
Expand Down

0 comments on commit 7c80c1e

Please sign in to comment.