Skip to content

Commit

Permalink
Provide workaround for Rails 5 TestRequest
Browse files Browse the repository at this point in the history
Rails 5 introduces changes to the TestRequest api, it no
longer supports creating a TestRequest without providing
args to the initializer however we can imitate the
original behaviour using .create instead.

This commit maintains backwards compatibility with older
versions of ActionController.
  • Loading branch information
Dan Palmer committed May 27, 2016
1 parent 4ccbc9d commit 530a5c0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/cell/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,24 @@ def controller_for(controller_class)
return unless controller_class

controller_class.new.tap do |ctl|
ctl.request = ::ActionController::TestRequest.new
ctl.request = action_controller_test_request
ctl.instance_variable_set :@routes, ::Rails.application.routes.url_helpers
end
end

# Rails specific.
def action_controller_test_request
## Rails 5 no longer supports creating a TestRequest without
## providing args to the initializer however we can imitate the
## original behaviour using .create whilst allowing fallbacks
## to the original for older versions of Rails.
if ::Rails.version.start_with?('5')
::ActionController::TestRequest.create
else
::ActionController::TestRequest.new
end
end

def controller # FIXME: this won't allow us using let(:controller) in MiniTest.
controller_for(self.class.controller_class)
end
Expand Down

0 comments on commit 530a5c0

Please sign in to comment.