From 6c6c43c55528e37a5b3ec91cb3945eb1944b1866 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 25 Mar 2025 10:01:56 +0100 Subject: [PATCH 1/4] Update integration tests to use the new routing API --- test/helper.rb | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 20d8b0b..e4bbe36 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -20,20 +20,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::Session::ActiveRecordStore, options.reverse_merge(:key => '_session_id') 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 yield(middleware) if block_given? end end + self.app = build_app(nil, {}) + private def with_test_route_set(options = {}) @@ -45,11 +71,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 - + @app = self.class.build_app(set, options) yield end end @@ -63,17 +85,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 From c19c5ea7110bce0d8260475681c1d01e8ebe3356 Mon Sep 17 00:00:00 2001 From: Steven Harman Date: Mon, 24 Mar 2025 13:49:17 -0400 Subject: [PATCH 2/4] Add Rails 7.2 and 8.0 to test matrix --- .github/workflows/ci.yml | 14 +++++++++++++- gemfiles/rails_7.2.gemfile | 11 +++++++++++ gemfiles/rails_8.0.gemfile | 11 +++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails_7.2.gemfile create mode 100644 gemfiles/rails_8.0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 544363c..5ef478a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 0000000..3b270f7 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -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 => "../" + diff --git a/gemfiles/rails_8.0.gemfile b/gemfiles/rails_8.0.gemfile new file mode 100644 index 0000000..40ce340 --- /dev/null +++ b/gemfiles/rails_8.0.gemfile @@ -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 => "../" + From e2773411c3c41ffbd1a9e17870e5b5fa89df295c Mon Sep 17 00:00:00 2001 From: Steven Harman Date: Tue, 25 Mar 2025 21:28:27 -0400 Subject: [PATCH 3/4] Build an app instance compatible with with_routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As of https://github.com/rails/rails/pull/49819 the internals of `ActionDispatch::Assertions::RoutingAssertions` changed and the way we were building our app instance was no compatible with it. This gets us back to passing tests for Rails 7.2+. I hope 🤞 --- test/helper.rb | 5 +++-- test/logger_silencer_test.rb | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index e4bbe36..e5f95a5 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -46,7 +46,6 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase def self.build_app(routes, options) RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware| - middleware.use ActionDispatch::Session::ActiveRecordStore, options.reverse_merge(:key => '_session_id') middleware.use ActionDispatch::DebugExceptions middleware.use ActionDispatch::ActionableExceptions middleware.use ActionDispatch::Callbacks @@ -54,6 +53,7 @@ def self.build_app(routes, options) 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 @@ -71,7 +71,8 @@ def with_test_route_set(options = {}) actions.each { |action| get action, controller: "#{controller_namespace}/test" } end - @app = self.class.build_app(set, options) + self.class.app = self.class.build_app(set, options) + yield end end diff --git a/test/logger_silencer_test.rb b/test/logger_silencer_test.rb index 8462fbb..6506e6f 100644 --- a/test/logger_silencer_test.rb +++ b/test/logger_silencer_test.rb @@ -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 From e77bcc33625130117500955f99a27d27ea18549a Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 26 Mar 2025 08:38:18 +0100 Subject: [PATCH 4/4] Do not leak the integration test application --- test/helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index e5f95a5..76795c4 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -71,9 +71,14 @@ def with_test_route_set(options = {}) actions.each { |action| get action, controller: "#{controller_namespace}/test" } end - self.class.app = self.class.build_app(set, options) + old_app = self.class.app + begin + self.class.app = self.class.build_app(set, options) - yield + yield + ensure + self.class.app = old_app + end end end