From 422ec4cb78cc9c10af97ddf958d477ce604b4506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 3 Aug 2017 16:22:58 -0400 Subject: Make sure Action View doesn't break with Active Storage When Active Storage is not loaded and direct_upload is used on file_field_tag we should not raise an exception. --- actionview/lib/action_view/helpers/form_tag_helper.rb | 2 +- actionview/lib/action_view/test_case.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'actionview/lib/action_view') diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 83b600d871..fd7184f8d3 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -906,7 +906,7 @@ module ActionView end def convert_direct_upload_option_to_url(options) - options.merge('data-direct-upload-url': options.delete(:direct_upload) ? rails_direct_uploads_url : nil).compact + options.merge('data-direct-upload-url': options.delete(:direct_upload) && respond_to?(:rails_direct_uploads_url) ? rails_direct_uploads_url : nil).compact end end end diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index efe8c87b9b..6913c31a20 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -281,6 +281,18 @@ module ActionView super end end + + def respond_to_missing?(name, include_private = false) + begin + routes = @controller.respond_to?(:_routes) && @controller._routes + rescue + # Dont call routes, if there is an error on _routes call + end + + routes && + (routes.named_routes.route_defined?(name) || + routes.mounted_helpers.method_defined?(name)) + end end include Behavior -- cgit v1.2.3