I have the following function in JS for a drag and drop file uploader:
function uploadFile(file){
var xhr = new XMLHttpRequest(); var upload = xhr.upload; var uri = "/imagebooks/upload_supporting_image/?authenticity_token=" + $('meta[name=csrf-token]').attr("content");
xhr.open('POST', uri, true); xhr.setRequestHeader('X-Filename', file.fileName);
xhr.send(file);
}
This works properly. I'm trying to create a spec to test the function with rspec- anyone know how I can mimic this? I've tried:
before(:each) do @image = File.open("#{Rails.root}/public/images/test/test.jpg", 'rb')
end
describe 'Upload Supporting Image method' do it 'should read a binary string and write a file with it' do request.env['X-Filename'] = 'test.jpg' xhr :post, :upload_supporting_image, @image end end
But it doesn't work as expected. Any help is greatly appreciated!