Sto usando questo blocco di codice per imitare il modo in cui i file vengono caricati:RSpec che converte i parametri POST in stringa? (File uploader test)
def mock_file
file = File.new((Rails.root + "public/checklist_items_template.csv"),"r")
image = ActionDispatch::Http::UploadedFile.new(
:filename => "checklist_items_template.csv",
:type => "text/csv",
:head => "Content-Disposition: form-data;
name=\"checklist_items_template.csv\";
filename=\"checklist_items_template.csv\"
Content-Type: text/csv\r\n",
:tempfile => file)
return image
end
Nel test RSpec è POST'd al controller:
post :create, :legal_register_id => "1", :register => {"file" => mock_file}
Ma rompe questa riga nel controller attuale:
CSV.parse(params[:register][:file].read.force_encoding('UTF-8'))
poiché params [: register] [: File] è in corso interpretato nel modo una stringa invece di un oggetto actiondispatch:
undefined method `read' for "#<ActionDispatch::Http::UploadedFile:0x00000108de3da8>":String
Questo comportamento standard per rspec? C'è un modo per passare oggetti tramite parametri?
quindi ... hai funzionato? La mia risposta è stata d'aiuto? –