ruby - How do I test a file upload in rails? -
I have a controller who is responsible for accepting JSON files and then to maintain some user for our application JSON is responsible for processing files. Users have been tested to upload file and processing tasks, but of course I want to automate the process of user maintenance testing in our test. How can I upload a file to an administrator in the functional testing framework?
searched for this question and did not find it, or found the answer on the stack overflow, but It got somewhere else, so I'm asking to make it available on SO. There is a function fixture_file_upload () in the Rail Framework, which will search your fixtures for the specified file and provide it as a test file for the controller in the functional test. To use it:
1) Keep your file for testing to upload in the test in your fixtures / files subdirectories.
2) In your unit test, you can get your test file by calling Fixture_file_upload ('path', 'mime-type').
Example:
bulk_json = fixture_file_upload ('files / bulk_bookmark.json', 'application / json')
3) Call the post method to hit the controller function that is going through the object returned by fixture_file_upload as the parameter for uploading.
Example:
Posted: Bookmarks: bulkfile = & gt; Bulk_json
Through this simulated post process, your fixtures will use a tamfile copy of the file in the directory and then return to your unit test so that you can start investigating the results of the post. / P>
Comments
Post a Comment