Skip to content
Browse files

Merge pull request #14105 from twooster/fix-controller-tests

Fix controller test not resetting @_url_options

Conflicts:
	actionpack/CHANGELOG.md
  • Loading branch information...
1 parent 3bdf7b8 commit 86aeab3727b14fc89594ad7dbc46dde126839e95 @tenderlove tenderlove committed with carlosantoniodasilva
View
5 actionpack/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fix URL generation in controller tests with request-dependent
+ `default_url_options` methods.
+
+ *Tony Wooster*
+
* Introduce `render :html` as an option to render HTML content with a content
type of `text/html`. This rendering option calls `ERB::Util.html_escape`
internally to escape unsafe HTML string, so you will have to mark your
View
1 actionpack/lib/action_controller/metal/testing.rb
@@ -17,7 +17,6 @@ def set_response!(request)
def recycle!
@_url_options = nil
- self.response_body = nil
self.formats = nil
self.params = nil
end
View
1 actionpack/lib/action_controller/test_case.rb
@@ -568,6 +568,7 @@ def process(action, http_method = 'GET', *args)
name = @request.parameters[:action]
+ @controller.recycle!
@controller.process(name)
if cookies = @request.env['action_dispatch.cookies']
View
23 actionpack/test/controller/test_case_test.rb
@@ -163,6 +163,29 @@ def view_assigns
end
end
+ class DefaultUrlOptionsCachingController < ActionController::Base
+ before_filter { @dynamic_opt = 'opt' }
+
+ def test_url_options_reset
+ render text: url_for(params)
+ end
+
+ def default_url_options
+ if defined?(@dynamic_opt)
+ super.merge dynamic_opt: @dynamic_opt
+ else
+ super
+ end
+ end
+ end
+
+ def test_url_options_reset
+ @controller = DefaultUrlOptionsCachingController.new
+ get :test_url_options_reset
+ assert_nil @request.params['dynamic_opt']
+ assert_match(/dynamic_opt=opt/, @response.body)
+ end
+
def test_raw_post_handling
params = Hash[:page, {:name => 'page name'}, 'some key', 123]
post :render_raw_post, params.dup

0 comments on commit 86aeab3

Please sign in to comment.
Something went wrong with that request. Please try again.