From ffe658f027dda4f8b09929c0f6e2e856fe5f6b8b Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Tue, 19 Sep 2017 08:43:03 -0500 Subject: [PATCH] Shim rails5 http test methods --- test/support/rails5_shims.rb | 53 ++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 test/support/rails5_shims.rb diff --git a/test/support/rails5_shims.rb b/test/support/rails5_shims.rb new file mode 100644 index 00000000..03a036da --- /dev/null +++ b/test/support/rails5_shims.rb @@ -0,0 +1,53 @@ +module Rails5Shims + module ControllerTests + # https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb + REQUEST_KWARGS = [:params, :headers, :session, :flash, :method, :body, :xhr].freeze + + def get(path, *args) + fold_kwargs!(args) + super + end + + def post(path, *args) + fold_kwargs!(args) + super + end + + def patch(path, *args) + fold_kwargs!(args) + super + end + + def put(path, *args) + fold_kwargs!(args) + super + end + + # Fold kwargs from test request into args + # Band-aid for DEPRECATION WARNING + def fold_kwargs!(args) + hash = args && args[0] + return unless hash.respond_to?(:key) + Rails5Shims::ControllerTests::REQUEST_KWARGS.each do |kwarg| + next unless hash.key?(kwarg) + value = hash.delete(kwarg) + if value.is_a? String + args.insert(0, value) + else + hash.merge! value + end + end + end + + # Uncomment for debugging where the kwargs warnings come from + # def non_kwarg_request_warning + # super.tap do + # STDOUT.puts caller[2..3] + # end + # end + end +end +if Rails::VERSION::MAJOR < 5 + ActionController::TestCase.send :include, Rails5Shims::ControllerTests + ActionDispatch::IntegrationTest.send :include, Rails5Shims::ControllerTests +end diff --git a/test/test_helper.rb b/test/test_helper.rb index b7b3f2e9..061f64fa 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -53,3 +53,5 @@ end class Object undef_method :id if respond_to?(:id) end + +require "support/rails5_shims"