I'm trying to test a multipart/form post with RSPEC with the following code:
@req = { :post => @attr }
lambda {
post :create, :POSTDATA => @req, :format => :json
}.should change(Post, :count).by(1)
but I get the following error:
undefined method `stringify_keys' for "post":String
POSTDATA is the multipart form name.
what is the correct way for testing multipart requests ?
EDIT:
I figured out that building the request like I did in the above just builds a nested JSON request. how do I build a multipost/form request ?
I want to build a multipart request that looks like that:
POST /api/posts.json HTTP/1.1
Accepts: application/json
X-API-KEY: 7d867d16a5e25337b6d7857965f812bee73b76ac
Content-Length: 288
Content-Type: multipart/form-data; boundary=syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Host: 10.0.2.2:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Content-Disposition: form-data; name="POSTDATA"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}}
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS--