diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-03 16:35:55 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-03 16:40:18 -0400 |
commit | f1648f6539a2fd74c9c53a08f886813b5f1c14ba (patch) | |
tree | 7850124a1c66bc22438aa39a01e77406fd9befcc /actionview/test/template | |
parent | 422ec4cb78cc9c10af97ddf958d477ce604b4506 (diff) | |
download | rails-f1648f6539a2fd74c9c53a08f886813b5f1c14ba.tar.gz rails-f1648f6539a2fd74c9c53a08f886813b5f1c14ba.tar.bz2 rails-f1648f6539a2fd74c9c53a08f886813b5f1c14ba.zip |
Refactor convert_direct_upload_option_to_url
Also make sure file_field doesn't mutate the original options passed in.
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 8d689aebeb..246f52588d 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -8,6 +8,16 @@ class FormHelperTest < ActionView::TestCase tests ActionView::Helpers::FormHelper + class WithActiveStorageRoutesControllers < ActionController::Base + test_routes do + post "/rails/active_storage/direct_uploads" => "active_storage/direct_uploads#create", as: :rails_direct_uploads + end + + def url_options + { host: "testtwo.host" } + end + end + def form_for(*) @output_buffer = super end @@ -542,6 +552,27 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, file_field("import", "file", multiple: true, name: "custom") end + def test_file_field_with_direct_upload_when_rails_direct_uploads_url_is_not_defined + expected = '<input type="file" name="import[file]" id="import_file" />' + assert_dom_equal expected, file_field("import", "file", direct_upload: true) + end + + def test_file_field_with_direct_upload_when_rails_direct_uploads_url_is_defined + @controller = WithActiveStorageRoutesControllers.new + + expected = '<input data-direct-upload-url="http://testtwo.host/rails/active_storage/direct_uploads" type="file" name="import[file]" id="import_file" />' + assert_dom_equal expected, file_field("import", "file", direct_upload: true) + end + + def test_file_field_with_direct_upload_dont_mutate_arguments + original_options = { class: "pix", direct_upload: true } + + expected = '<input class="pix" type="file" name="import[file]" id="import_file" />' + assert_dom_equal expected, file_field("import", "file", original_options) + + assert_equal({ class: "pix", direct_upload: true }, original_options) + end + def test_hidden_field assert_dom_equal( '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />', |