Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs generation fails if a file is uploaded as part of a spec #39

Closed
oestrich opened this issue Jun 2, 2012 · 17 comments
Closed

Docs generation fails if a file is uploaded as part of a spec #39

oestrich opened this issue Jun 2, 2012 · 17 comments

Comments

@oestrich
Copy link
Contributor

oestrich commented Jun 2, 2012

HtmlWriter can't handle the encoding:

lib/rspec_api_documentation/html_writer.rb:25:in `write': "\x89" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

@pollingj
Copy link

pollingj commented Jul 2, 2013

I've just hit this issue. Is there a fix for it?

@oestrich
Copy link
Contributor Author

oestrich commented Jul 2, 2013

Not yet. I'm not entirely sure how we'd fix the problem. Do we snip out the upload data or leave it in bloating the docs? If we take it out then we're not really documenting the whole example response.

I thought it might be cool to detect the upload and save it out along side the docs so we can replace it with a link so people can download it.

@pollingj
Copy link

pollingj commented Jul 3, 2013

I was thinking it could detect the upload data, and just replace it with a string saying something like "upload data"?

@rogercampos
Copy link

Also hit this, a fix would be very appreciated

@jejacks0n
Copy link

I have not yet experienced this, but I will shortly.. I was here to create a different issue, but yeah, I agree with @pollingj -- replacing it with something that indicates it was a file is fine by me.

@cutalion
Copy link

Is it possible to manually add a section to docs meanwhile?

@oestrich
Copy link
Contributor Author

Sure, depends on how you're hosting them though. If you're using the HTML writer just add a new link in the index page and corresponding HTML page. The JSON writer is similar, but make sure you format the example correctly so Raddocs (or similar) can view it.

I'll look into this a little bit more and see what I can come up with.

@jejacks0n
Copy link

Keep in mind that the path is removed before rebuilding, so you would have to do this manually every time you generate the docs.

@jejacks0n
Copy link

I did something similar by adding a controller tests outside of the acceptance specs (for a real spec for it), and did the request/response in such a way in the acceptance specs that makes it appear as though there was a file attached in the request.

eg. let(:attachment) { '[File Attachment'] }, then find and update the record with an attachment manually (only works on update). It at least simulates it in the documentation.

@oestrich
Copy link
Contributor Author

I think I have a working solution for this. Could everyone check out this branch and see if it works for them?

https://github.com/zipmark/rspec_api_documentation/tree/uploaded_data

@pvertenten
Copy link

Doesn't seem to support files in nested documents.

@Ruxton
Copy link
Contributor

Ruxton commented Jan 8, 2014

@oestrich I just put a PR in to expand upon your solution that wasn't working for a few people.

@dalizard
Copy link

@oestrich I am having exactly the same problem with an uploaded file. I was thinking about opening a PR, but saw this thread. What is the current state of the issue?

P.S. The uploaded_data branch does not work for me. I had to update the File.open mode in order to avoid encoding problems. See here dalizard/rspec_api_documentation@94243ef

@oestrich
Copy link
Contributor Author

@dalizard Can you try out the branch again? Merged in @Ruxton's changes.

@dalizard
Copy link

@oestrich It works! Any idea as to when this could be pushed to master and released?

@Ruxton
Copy link
Contributor

Ruxton commented Jan 21, 2014

FWIW we've been using this as part of our CI process in 3 separate projects since I sent this PR and are yet to come across any issues

@oestrich
Copy link
Contributor Author

Awesome, I'll merge it in later today then and push a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants