Skip to content
Extraits de code Groupes Projets
Valider 14842c1b rédigé par Pistos's avatar Pistos
Parcourir les fichiers

Merge remote-tracking branch 'johnedmonds/issue1144'

parents 53dbbfbb b482d166
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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]
......@@ -235,5 +241,6 @@ class PhotosController < ApplicationController
Tempfile.send(:define_method, "content_type") {return att_content_type}
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(){
......
......@@ -13,6 +13,28 @@ describe PhotosController do
sign_in :user, alice
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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter