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!

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to