Problem testing api controller method for upload

69 views
Skip to first unread message

Weverton Gomes

unread,
Sep 3, 2013, 12:22:43 PM9/3/13
to rs...@googlegroups.com
Hi,

In our app we have an API and we're creating a new method in one of controller to allow file upload. We created a test like this:

 it 'should upload and save a zip file with invoices' do
    zip = File.read('spec/support/zip-rails.zip')
        
    post :upload, registry: "11222333000144", file: zip

    response.body.should eql(true.to_s)
  end

However, when we run the tests, we getting the following error:

ArgumentError:
       invalid byte sequence in UTF-8

We have already searched and most of results tell about set content-type to  'multipart/form-data'. We don't know if is it, but we tryied set content-type by many and different ways and the error is still there.

Do somebody know about this??

Thanks,

Myron Marston

unread,
Sep 3, 2013, 12:36:18 PM9/3/13
to rs...@googlegroups.com
1) Without a backtrace it's hard to give any suggestions; your post doesn't give enough context to guess where that error is originating from.
2) rspec-rails wraps rails' test support, and things like this generally just delegate to the rails methods underneath.  I suspect that this is a general issue with rails and not an rspec-specific issue that we'd be able to solve in rspec-rails.  I encourage you to try writing your test with just rails' built-in test support and seeing if the error still happens.  From there, you can report it to rails or seek help there.

Myron 

Weverton Gomes

unread,
Sep 3, 2013, 1:08:41 PM9/3/13
to rs...@googlegroups.com
Myron,

I will try it. But, before, can you tell me the correct way to set the content-type of the request??

Thanks,

Myron Marston

unread,
Sep 3, 2013, 4:47:09 PM9/3/13
to rs...@googlegroups.com
On Tuesday, September 3, 2013 10:08:41 AM UTC-7, Weverton Gomes wrote:
Myron,

I will try it. But, before, can you tell me the correct way to set the content-type of the request??


I would if I knew.  I haven't used rails in years and don't remember how to do it.  Even if I did remember how to do it, it may have changed...

siva

unread,
Sep 4, 2013, 6:46:08 AM9/4/13
to rs...@googlegroups.com
Hi

 Checkout this method fixture_file_upload method on http://api.rubyonrails.org/. It might help you.
Reply all
Reply to author
Forward
0 new messages