Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed May 9, 2012
1 parent 0c22a25 commit 496f014
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions test/action_view_extensions/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ class FormHelperTest < ActionView::TestCase
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

swap_field_error_proc do
result = nil
simple_form_for :user do |f|
result = simple_fields_for 'address' do
Expand All @@ -117,33 +112,29 @@ class FormHelperTest < ActionView::TestCase
end

assert_equal 'hello', result
assert_equal expected_error_proc, ActionView::Base.field_error_proc

ensure
ActionView::Base.field_error_proc = previous_error_proc
end
end

test 'custom error proc survives an exception' do
previous_error_proc = ActionView::Base.field_error_proc

begin
expected_error_proc = lambda {}
ActionView::Base.field_error_proc = expected_error_proc

swap_field_error_proc do
begin
simple_form_for :user do |f|
simple_fields_for 'address' do
raise 'an exception'
end
end
rescue StandardError => e
rescue StandardError
end
end
end

assert_equal expected_error_proc, ActionView::Base.field_error_proc
private

ensure
ActionView::Base.field_error_proc = previous_error_proc
def swap_field_error_proc(expected_error_proc = lambda {})
swap ActionView::Base, :field_error_proc => expected_error_proc do
yield

assert_equal expected_error_proc, ActionView::Base.field_error_proc
end
end
end

0 comments on commit 496f014

Please sign in to comment.