From 169d210187746a92b8eb8b703f76f903ee9197d7 Mon Sep 17 00:00:00 2001 From: Jolyon Pawlyn Date: Tue, 28 Dec 2021 09:08:06 +0000 Subject: [PATCH] Make Rails 7 hack specific to test controller that needs it --- test/action_controller/serialization_test.rb | 7 ++++++- test/support/rails_7_patch.rb | 13 ------------- test/test_helper.rb | 1 - 3 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 test/support/rails_7_patch.rb diff --git a/test/action_controller/serialization_test.rb b/test/action_controller/serialization_test.rb index 8d360b6f..2286309b 100644 --- a/test/action_controller/serialization_test.rb +++ b/test/action_controller/serialization_test.rb @@ -7,6 +7,7 @@ module ActionController class ImplicitSerializerTest < ActionController::TestCase class ImplicitSerializationTestController < ActionController::Base include SerializationTesting + def render_using_implicit_serializer @profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1') render json: @profile @@ -75,8 +76,12 @@ module ActionController render json: [{ error: 'Result is Invalid' }] end + # HACK: to prevent the resetting of instance variables after each request in Rails 7 + # see https://github.com/rails/rails/pull/43735 + def clear_instance_variables_between_requests; end + def update_and_render_object_with_cache_enabled - @post.updated_at = Time.zone.now + @post.updated_at = Time.zone.now # requires hack above to prevent `NoMethodError: undefined method `updated_at=' for nil:NilClass` generate_cached_serializer(@post) render json: @post diff --git a/test/support/rails_7_patch.rb b/test/support/rails_7_patch.rb deleted file mode 100644 index b2cc74ab..00000000 --- a/test/support/rails_7_patch.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# HACK: to prevent the resetting of instance variables after each request in Rails 7 -# see https://github.com/rails/rails/pull/43735 -if Rails::VERSION::MAJOR >= 7 - module ActionController - module Testing - module Functional - def clear_instance_variables_between_requests; end - end - end - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 00123504..7d8ca63e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -49,7 +49,6 @@ end require 'support/rails_app' -require 'support/rails_7_patch' require 'support/ruby_2_6_rails_4_2_patch' # require "rails/test_help"