Make Rails 7 hack specific to test controller that needs it

This commit is contained in:
Jolyon Pawlyn 2021-12-28 09:08:06 +00:00
parent 5d64851ad0
commit 169d210187
3 changed files with 6 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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"