{"action":"created","issue":{"url":"https://api.github.com/repos/intridea/grape/issues/1022","labels_url":"https://api.github.com/repos/intridea/grape/issues/1022/labels{/name}","comments_url":"https://api.github.com/repos/intridea/grape/issues/1022/comments","events_url":"https://api.github.com/repos/intridea/grape/issues/1022/events","html_url":"https://github.com/intridea/grape/issues/1022","id":83446086,"number":1022,"title":"Files not passed as UploadedFile","user":{"login":"NobodysNightmare","id":453584,"avatar_url":"https://avatars.githubusercontent.com/u/453584?v=3","gravatar_id":"","url":"https://api.github.com/users/NobodysNightmare","html_url":"https://github.com/NobodysNightmare","followers_url":"https://api.github.com/users/NobodysNightmare/followers","following_url":"https://api.github.com/users/NobodysNightmare/following{/other_user}","gists_url":"https://api.github.com/users/NobodysNightmare/gists{/gist_id}","starred_url":"https://api.github.com/users/NobodysNightmare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NobodysNightmare/subscriptions","organizations_url":"https://api.github.com/users/NobodysNightmare/orgs","repos_url":"https://api.github.com/users/NobodysNightmare/repos","events_url":"https://api.github.com/users/NobodysNightmare/events{/privacy}","received_events_url":"https://api.github.com/users/NobodysNightmare/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/intridea/grape/labels/bug?","name":"bug?","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-01T11:25:17Z","updated_at":"2015-06-01T15:06:38Z","closed_at":"2015-06-01T15:06:38Z","body":"Hello,\r\n\r\nI noticed that uploaded files are passed into my endpoints as `Hashie::Mash`, e.g.:\r\n\r\n````ruby\r\n#<Hashie::Mash filename=\"cat.jpg\" head=\"lots-of-headers\" name=\"file\" tempfile=#<Tempfile:/tmp/RackMultipart20150601-8540-uwm6qu> type=\"application/jpeg\">\r\n````\r\n\r\nThis was not a big deal for me while mocking around, I just \"converted\" the hash into an `UploadedFile`, by instantiating my own one, the spirit being something like:\r\n\r\n````ruby\r\nRack::Multipart::UploadedFile.new file[:tempfile].path, file[:type], true\r\n````\r\n\r\n### The moment it breaks\r\n\r\nTrying to write specs for such an endpoint using [rack-test](https://github.com/brynary/rack-test) now starts to get difficult. [The internet](http://seejohncode.com/2012/04/29/quick-tip-testing-multipart-uploads-with-rspec/) will tell me, that I want to write something like:\r\n\r\n````ruby\r\npost :photo, :file => Rack::Test::UploadedFile.new(path, mime_type)\r\n````\r\n\r\nHowever, using this in a test now leads to my endpoint code (the one converting the `Mash` into an `UploadedFile`) already receiving an `UploadedFile` instead of a `Mash`.\r\n\r\n### Questions\r\n\r\n1. Is there a setup error on my side that prevents grape from converting the `UploadedFile` into a `Hashie::Mash` during the spec? Or is this the intended behaviour?\r\n2. Why does the conversion from `UploadedFile` to `Hashie::Mash` happen in the first place? I tried searching through the codebase of this repo looking for `UploadedFile` and `tempfile`, but both keywords just gave me code that expects the conversion to have happened, I could not find the place of the actual conversion.\r\n\r\nI am admittedly rather new to `Rack`. Until now it sufficed to understand the frameworks layered on top of it. So if I am missing a very basic point here, that would be an explanation.\r\n\r\nBest regards"},"comment":{"url":"https://api.github.com/repos/intridea/grape/issues/comments/107563980","html_url":"https://github.com/intridea/grape/issues/1022#issuecomment-107563980","issue_url":"https://api.github.com/repos/intridea/grape/issues/1022","id":107563980,"user":{"login":"NobodysNightmare","id":453584,"avatar_url":"https://avatars.githubusercontent.com/u/453584?v=3","gravatar_id":"","url":"https://api.github.com/users/NobodysNightmare","html_url":"https://github.com/NobodysNightmare","followers_url":"https://api.github.com/users/NobodysNightmare/followers","following_url":"https://api.github.com/users/NobodysNightmare/following{/other_user}","gists_url":"https://api.github.com/users/NobodysNightmare/gists{/gist_id}","starred_url":"https://api.github.com/users/NobodysNightmare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NobodysNightmare/subscriptions","organizations_url":"https://api.github.com/users/NobodysNightmare/orgs","repos_url":"https://api.github.com/users/NobodysNightmare/repos","events_url":"https://api.github.com/users/NobodysNightmare/events{/privacy}","received_events_url":"https://api.github.com/users/NobodysNightmare/received_events","type":"User","site_admin":false},"created_at":"2015-06-01T15:06:38Z","updated_at":"2015-06-01T15:06:38Z","body":"Arg...\r\n\r\nSorry for bothering you, the error was on my side. Twice! But due to inability to read I did not realize it.\r\n\r\n**Fail 1:**\r\n\r\nI handcrafted a `Rack::Multipart::UploadedFile` instead of a `Rack::Test::UploadedFile`. This led to `Rack::Test` not recognizing it as a file, thus simply sticking with URL encoding for everything.\r\n\r\nAfter using `Rack::Test::UploadedFile` the spec works as it should.\r\n\r\n**Fail 2:**\r\n\r\nI did not *see* that, because I am unable to read:\r\n\r\n````ruby\r\n0> file\r\n=> \"#<Rack::Multipart::UploadedFile:0x0000000eea0318>\"\r\n````\r\n\r\nIf you look closely you will see that there are `\"` around the class name. To be more clear:\r\n\r\n````ruby\r\n0> file.class\r\n=> String\r\n````\r\nI was just seeing a string that looked as if it was a reference to an actual class.\r\n\r\nSo thanks for taking the time to help me and sorry for wasting yours. I should totally have seen this myself. :disappointed: \r\n\r\nBest regards"}}