Mocking file uploads in Rails 3.1 controller tests

前端 未结 3 1109
旧时难觅i
旧时难觅i 2021-02-15 04:08

My controller accesses the tempfile attribute of an uploaded file and passes it to another mocked component. My test code has

  @file = mock(Object)         


        
3条回答
  •  爱一瞬间的悲伤
    2021-02-15 04:51

    I went around this way

    upload_file = fixture_file_upload('files/stats_upload.csv', 'text/csv')
    upload_file.stubs(:tempfile).returns(upload_file)
    

提交回复
热议问题