Merge remote-tracking branch 'johnedmonds/issue1144'

This commit is contained in:
Pistos 2011-11-06 22:21:53 -05:00
commit 14842c1b43
3 changed files with 30 additions and 0 deletions

View file

@ -71,6 +71,7 @@ class PhotosController < ApplicationController
respond_to do |format| respond_to do |format|
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} 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 end
else else
respond_with @photo, :location => photos_path, :error => message respond_with @photo, :location => photos_path, :error => message
@ -214,6 +215,11 @@ class PhotosController < ApplicationController
private private
def file_handler(params) 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 ############# ######################## dealing with local files #############
# get file name # get file name
file_name = params[:qqfile] file_name = params[:qqfile]
@ -235,5 +241,6 @@ class PhotosController < ApplicationController
Tempfile.send(:define_method, "content_type") {return att_content_type} Tempfile.send(:define_method, "content_type") {return att_content_type}
Tempfile.send(:define_method, "original_filename") {return file_name} Tempfile.send(:define_method, "original_filename") {return file_name}
file file
end
end end
end end

View file

@ -1017,6 +1017,7 @@ qq.extend(qq.UploadHandlerForm.prototype, {
var iframe = this._createIframe(id); var iframe = this._createIframe(id);
var form = this._createForm(iframe, params); var form = this._createForm(iframe, params);
form.appendChild(input); form.appendChild(input);
$(form).append($('<input type="hidden" name="authenticity_token" value="'+$("meta[name='csrf-token']").attr("content")+'"/>'));
var self = this; var self = this;
this._attachLoadEvent(iframe, function(){ this._attachLoadEvent(iframe, function(){

View file

@ -13,6 +13,28 @@ describe PhotosController do
sign_in :user, alice sign_in :user, alice
request.env["HTTP_REFERER"] = '' request.env["HTTP_REFERER"] = ''
end 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 describe '#create' do
before do before do