Merge remote-tracking branch 'johnedmonds/issue1144'
This commit is contained in:
commit
14842c1b43
3 changed files with 30 additions and 0 deletions
|
|
@ -71,6 +71,7 @@ class PhotosController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
|
||||
format.html{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
|
||||
end
|
||||
else
|
||||
respond_with @photo, :location => photos_path, :error => message
|
||||
|
|
@ -214,6 +215,11 @@ class PhotosController < ApplicationController
|
|||
private
|
||||
|
||||
def file_handler(params)
|
||||
# For XHR file uploads, request.params[:qqfile] will be the path to the temporary file
|
||||
# For regular form uploads (such as those made by Opera), request.params[:qqfile] will be an UploadedFile which can be returned unaltered.
|
||||
if not request.params[:qqfile].is_a?(String)
|
||||
params[:qqfile]
|
||||
else
|
||||
######################## dealing with local files #############
|
||||
# get file name
|
||||
file_name = params[:qqfile]
|
||||
|
|
@ -236,4 +242,5 @@ class PhotosController < ApplicationController
|
|||
Tempfile.send(:define_method, "original_filename") {return file_name}
|
||||
file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1017,6 +1017,7 @@ qq.extend(qq.UploadHandlerForm.prototype, {
|
|||
var iframe = this._createIframe(id);
|
||||
var form = this._createForm(iframe, params);
|
||||
form.appendChild(input);
|
||||
$(form).append($('<input type="hidden" name="authenticity_token" value="'+$("meta[name='csrf-token']").attr("content")+'"/>'));
|
||||
|
||||
var self = this;
|
||||
this._attachLoadEvent(iframe, function(){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,28 @@ describe PhotosController do
|
|||
request.env["HTTP_REFERER"] = ''
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before do
|
||||
@params = {:photo => {:aspect_ids => "all"}, :qqfile => Rack::Test::UploadedFile.new("spec/fixtures/button.png", "image/png") }
|
||||
end
|
||||
|
||||
it 'accepts a photo from a regular form submission' do
|
||||
lambda {
|
||||
post :create, @params
|
||||
}.should change(Photo, :count).by(1)
|
||||
end
|
||||
|
||||
it 'returns application/json when possible' do
|
||||
request.env['HTTP_ACCEPT'] = 'application/json'
|
||||
post(:create, @params).headers['Content-Type'].should match 'application/json.*'
|
||||
end
|
||||
|
||||
it 'returns text/html by default' do
|
||||
request.env['HTTP_ACCEPT'] = 'text/html,*/*'
|
||||
post(:create, @params).headers['Content-Type'].should match 'text/html.*'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
before do
|
||||
@controller.stub!(:file_handler).and_return(uploaded_photo)
|
||||
|
|
|
|||
Loading…
Reference in a new issue