Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for newer Rubies/Rails. #219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ jobs:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
rails: ['7.0', '7.1', 'edge']
rails: ['7.0', '7.1', '7.2', '8.0', 'edge']
exclude:
- ruby: '2.7'
rails: '7.2'
- ruby: '2.7'
rails: '8.0'
- ruby: '2.7'
rails: 'edge'
- ruby: '3.0'
rails: '7.2'
- ruby: '3.0'
rails: '8.0'
- ruby: '3.0'
rails: 'edge'
- ruby: '3.1'
rails: '8.0'
- ruby: '3.1'
rails: 'edge'
env:
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
Expand Down
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem "sqlite3"

group :development, :test do
gem "debug"
end
11 changes: 11 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source "https://rubygems.org"

gem "actionpack", github: "rails/rails", branch: "7-2-stable"
gem "activerecord", github: "rails/rails", branch: "7-2-stable"
gem "railties", github: "rails/rails", branch: "7-2-stable"

gem "rack", ">= 2.2.4", "< 4"
gem "sqlite3"

gemspec :path => "../"

11 changes: 11 additions & 0 deletions gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source "https://rubygems.org"

gem "actionpack", github: "rails/rails", branch: "8-0-stable"
gem "activerecord", github: "rails/rails", branch: "8-0-stable"
gem "railties", github: "rails/rails", branch: "8-0-stable"

gem "rack", ">= 2.2.4", "< 4"
gem "sqlite3"

gemspec :path => "../"

61 changes: 36 additions & 25 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'bundler/setup'
require "bundler/setup"

require 'active_record'
require 'action_controller'
require 'action_dispatch'
require 'minitest/autorun'
require "active_record"
require "action_controller"
require "action_dispatch"
require "debug"
require "minitest/autorun"

require 'active_record/session_store'
require "active_record/session_store"

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

SharedTestRoutes = ActionDispatch::Routing::RouteSet.new

Expand All @@ -20,20 +21,46 @@ def before_setup
end
end

class RoutedRackApp
class Config < Struct.new(:middleware)
end

attr_reader :routes

def initialize(routes, &blk)
@routes = routes
@stack = ActionDispatch::MiddlewareStack.new(&blk)
@app = @stack.build(@routes)
end

def call(env)
@app.call(env)
end

def config
Config.new(@stack)
end
end

class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
include ActionDispatch::SharedRoutes

def self.build_app(routes = nil)
def self.build_app(routes, options)
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
middleware.use ActionDispatch::DebugExceptions
middleware.use ActionDispatch::ActionableExceptions
middleware.use ActionDispatch::Callbacks
middleware.use ActionDispatch::Cookies
middleware.use ActionDispatch::Flash
middleware.use Rack::MethodOverride
middleware.use Rack::Head
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(key: "_session_id")
yield(middleware) if block_given?
end
end

self.app = build_app(nil, {})

private

def with_test_route_set(options = {})
Expand All @@ -45,10 +72,7 @@ def with_test_route_set(options = {})
actions.each { |action| get action, controller: "#{controller_namespace}/test" }
end

@app = self.class.build_app(set) do |middleware|
middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(:key => '_session_id')
middleware.delete ActionDispatch::ShowExceptions
end
self.class.app = self.class.build_app(set, options)

yield
end
Expand All @@ -63,17 +87,4 @@ def with_store(class_name)
end
end

class RoutedRackApp
attr_reader :routes

def initialize(routes, &blk)
@routes = routes
@stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
end

def call(env)
@stack.call(env)
end
end

ActiveSupport::TestCase.test_order = :random
4 changes: 3 additions & 1 deletion test/logger_silencer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def setup
def test_log_silencer_with_logger_not_raise_exception
with_logger ActiveSupport::Logger.new(Tempfile.new("tempfile")) do
with_test_route_set do
get "/set_session_value"
assert_nothing_raised do
get "/set_session_value"
end
end
end
end
Expand Down
Loading