@@ -859,6 +859,58 @@ module Helpers
859859 it { should match /example_name_eq/ }
860860 end
861861
862+ describe '#search_form_with with default format' do
863+ subject { @controller . view_context
864+ . search_form_with ( model : Person . ransack ) { } }
865+ it { should match /action="\/ people"/ }
866+ end
867+
868+ describe '#search_form_with with pdf format' do
869+ subject {
870+ @controller . view_context
871+ . search_form_with ( model : Person . ransack , format : :pdf ) { }
872+ }
873+ it { should match /action="\/ people.pdf"/ }
874+ end
875+
876+ describe '#search_form_with with json format' do
877+ subject {
878+ @controller . view_context
879+ . search_form_with ( model : Person . ransack , format : :json ) { }
880+ }
881+ it { should match /action="\/ people.json"/ }
882+ end
883+
884+ describe '#search_form_with with an array of routes' do
885+ subject {
886+ @controller . view_context
887+ . search_form_with ( model : [ :admin , Comment . ransack ] ) { }
888+ }
889+ it { should match /action="\/ admin\/ comments"/ }
890+ end
891+
892+ describe '#search_form_with with custom default search key' do
893+ before do
894+ Ransack . configure { |c | c . search_key = :example }
895+ end
896+ after do
897+ Ransack . configure { |c | c . search_key = :q }
898+ end
899+ subject {
900+ @controller . view_context
901+ . search_form_with ( model : Person . ransack ) { |f | f . text_field :name_eq }
902+ }
903+ it { should match /example\[ name_eq\] / }
904+ end
905+
906+ describe '#search_form_with without Ransack::Search object' do
907+ it 'raises ArgumentError' do
908+ expect {
909+ @controller . view_context . search_form_with ( model : "not a search object" ) { }
910+ } . to raise_error ( ArgumentError , 'No Ransack::Search object was provided to search_form_with!' )
911+ end
912+ end
913+
862914 describe '#turbo_search_form_for with default options' do
863915 subject {
864916 @controller . view_context
@@ -994,6 +1046,28 @@ module Helpers
9941046 helper . send ( :extract_search_and_set_url , "invalid" , options , 'turbo_search_form_for' )
9951047 } . to raise_error ( ArgumentError , 'No Ransack::Search object was provided to turbo_search_form_for!' )
9961048 end
1049+
1050+ it 'extracts search from Ransack::Search object for search_form_with' do
1051+ options = { }
1052+ result = helper . send ( :extract_search_and_set_url , search , options , 'search_form_with' )
1053+ expect ( result ) . to eq ( search )
1054+ expect ( options [ :url ] ) . to match ( /people/ )
1055+ end
1056+
1057+ it 'extracts search from array with Search object for search_form_with' do
1058+ options = { }
1059+ comment_search = Comment . ransack
1060+ result = helper . send ( :extract_search_and_set_url , [ :admin , comment_search ] , options , 'search_form_with' )
1061+ expect ( result ) . to eq ( comment_search )
1062+ expect ( options [ :url ] ) . to match ( /admin/ )
1063+ end
1064+
1065+ it 'raises error for invalid record with correct method name for search_form_with' do
1066+ options = { }
1067+ expect {
1068+ helper . send ( :extract_search_and_set_url , "invalid" , options , 'search_form_with' )
1069+ } . to raise_error ( ArgumentError , 'No Ransack::Search object was provided to search_form_with!' )
1070+ end
9971071 end
9981072 end
9991073 end
0 commit comments