From 1db257182762389e484f18ac692e493b8df35cc9 Mon Sep 17 00:00:00 2001 From: Jim Benton Date: Tue, 8 May 2012 15:07:31 -0500 Subject: [PATCH] Nested simple_form calls no longer lose reference to original error proc. --- .../action_view_extensions/form_helper.rb | 8 ++------ .../form_helper_test.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/simple_form/action_view_extensions/form_helper.rb b/lib/simple_form/action_view_extensions/form_helper.rb index d39b7cd2..136af662 100644 --- a/lib/simple_form/action_view_extensions/form_helper.rb +++ b/lib/simple_form/action_view_extensions/form_helper.rb @@ -9,10 +9,6 @@ module SimpleForm # end # module FormHelper - # based on what is done in formtastic - # http://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb#L1706 - @@default_field_error_proc = nil - # Override the default ActiveRecordHelper behaviour of wrapping the input. # This gets taken care of semantically by adding an error class to the wrapper tag # containing the input. @@ -46,10 +42,10 @@ module SimpleForm private def with_simple_form_field_error_proc - @@default_field_error_proc = ::ActionView::Base.field_error_proc + default_field_error_proc = ::ActionView::Base.field_error_proc ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC result = yield - ::ActionView::Base.field_error_proc = @@default_field_error_proc + ::ActionView::Base.field_error_proc = default_field_error_proc result end diff --git a/test/action_view_extensions/form_helper_test.rb b/test/action_view_extensions/form_helper_test.rb index 712570b1..6913ebdd 100644 --- a/test/action_view_extensions/form_helper_test.rb +++ b/test/action_view_extensions/form_helper_test.rb @@ -101,4 +101,23 @@ class FormHelperTest < ActionView::TestCase assert_select "input[name='author[name]'][value='hash backed author']" end + + test 'custom error proc is not destructive' do + previous_error_proc = ActionView::Base.field_error_proc + + begin + expected_error_proc = lambda {} + ActionView::Base.field_error_proc = expected_error_proc + + simple_form_for :user do |f| + simple_fields_for 'address' do + end + end + + assert_equal expected_error_proc, ActionView::Base.field_error_proc + + ensure + ActionView::Base.field_error_proc = previous_error_proc + end + end end