Nested simple_form calls no longer lose reference to original error proc.
This commit is contained in:
parent
18306d8a77
commit
1db2571827
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue