Skip to content
Browse files

Merge pull request #2307 from thoefer/3-1-stable-fix1872

Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031.
  • Loading branch information...
2 parents 7ee15e8 + 7b39dda commit 86b792d4fa213e0538915532e671964208dedfb8 @josevalim josevalim committed Aug 1, 2011
View
5 actionpack/lib/action_controller/metal/testing.rb
@@ -4,6 +4,11 @@ module Testing
include RackDelegation
+ def recycle!
+ @_url_options = nil
+ end
+
+
# TODO: Clean this up
def process_with_new_base_test(request, response)
@_request = request
View
1 actionpack/lib/action_controller/test_case.rb
@@ -447,6 +447,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@controller.params.merge!(parameters)
build_request_uri(action, parameters)
@controller.class.class_eval { include Testing }
+ @controller.recycle!
@controller.process_with_new_base_test(@request, @response)
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
@request.session.delete('flash') if @request.session['flash'].blank?
View
29 actionpack/test/controller/default_url_options_with_filter_test.rb
@@ -0,0 +1,29 @@
+require 'abstract_unit'
+
+
+class ControllerWithBeforeFilterAndDefaultUrlOptions < ActionController::Base
+
+ before_filter { I18n.locale = params[:locale] }
+ after_filter { I18n.locale = "en" }
+
+ def target
+ render :text => "final response"
+ end
+
+ def redirect
+ redirect_to :action => "target"
+ end
+
+ def default_url_options
+ {:locale => "de"}
+ end
+end
+
+class ControllerWithBeforeFilterAndDefaultUrlOptionsTest < ActionController::TestCase
+
+ # This test has it´s roots in issue #1872
+ test "should redirect with correct locale :de" do
+ get :redirect, :locale => "de"
+ assert_redirected_to "/controller_with_before_filter_and_default_url_options/target?locale=de"
+ end
+end

0 comments on commit 86b792d

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