diff --git a/lib/draper/view_context/build_strategy.rb b/lib/draper/view_context/build_strategy.rb index 9832a05d..1b6ff47e 100644 --- a/lib/draper/view_context/build_strategy.rb +++ b/lib/draper/view_context/build_strategy.rb @@ -38,17 +38,9 @@ def call def controller Draper::ViewContext.controller ||= Draper.default_controller.new Draper::ViewContext.controller.tap do |controller| - controller.request ||= new_test_request controller if defined?(ActionController::TestRequest) + controller.request ||= ActionDispatch::TestRequest.create end end - - def new_test_request(controller) - is_above_rails_5_1 ? ActionController::TestRequest.create(controller) : ActionController::TestRequest.create - end - - def is_above_rails_5_1 - ActionController::TestRequest.method(:create).parameters.first == [:req, :controller_class] - end end end end diff --git a/spec/draper/view_context/build_strategy_spec.rb b/spec/draper/view_context/build_strategy_spec.rb index 54774926..18acdf61 100644 --- a/spec/draper/view_context/build_strategy_spec.rb +++ b/spec/draper/view_context/build_strategy_spec.rb @@ -37,7 +37,7 @@ module Draper expect(controller.request).to be_nil strategy.call - expect(controller.request).to be_an ActionController::TestRequest + expect(controller.request).to be_an ActionDispatch::TestRequest expect(controller.params).to be_empty # sanity checks @@ -45,23 +45,6 @@ module Draper expect(controller.view_context.params).to be controller.params end - it "compatible with rails 5.1 change on ActionController::TestRequest.create method" do - ActionController::TestRequest.class_eval do - if ActionController::TestRequest.method(:create).parameters.first == [] - def create controller_class - create - end - end - end - controller = Class.new(ActionController::Base).new - allow(ViewContext).to receive_messages controller: controller - strategy = ViewContext::BuildStrategy::Full.new - - expect(controller.request).to be_nil - strategy.call - expect(controller.request).to be_an ActionController::TestRequest - end - it "adds methods to the view context from the constructor block" do allow(ViewContext).to receive(:controller).and_return(fake_controller) strategy = ViewContext::BuildStrategy::Full.new do