Commit 4816c3f19826b7b3aede0716652c6719cc3026f5
1 parent
cac61e3d
Exists in
master
and in
29 other branches
Make the whole thing more robust
Showing
3 changed files
with
13 additions
and
5 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -343,7 +343,7 @@ class CmsController < MyProfileController | @@ -343,7 +343,7 @@ class CmsController < MyProfileController | ||
343 | def media_upload | 343 | def media_upload |
344 | files_uploaded = [] | 344 | files_uploaded = [] |
345 | parent = check_parent(params[:parent_id]) | 345 | parent = check_parent(params[:parent_id]) |
346 | - files = [:file1,:file2, :file3].map { |f| params[f] } | 346 | + files = [:file1,:file2, :file3].map { |f| params[f] }.compact |
347 | if request.post? | 347 | if request.post? |
348 | files.each do |file| | 348 | files.each do |file| |
349 | files_uploaded << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => parent) unless file == '' | 349 | files_uploaded << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => parent) unless file == '' |
@@ -401,7 +401,7 @@ class CmsController < MyProfileController | @@ -401,7 +401,7 @@ class CmsController < MyProfileController | ||
401 | list.map do |item| | 401 | list.map do |item| |
402 | { | 402 | { |
403 | 'title' => item.title, | 403 | 'title' => item.title, |
404 | - 'url' => url_for(item.url), | 404 | + 'url' => item.image? ? item.public_filename(:uploaded) : url_for(item.url), |
405 | :icon => icon_for_article(item), | 405 | :icon => icon_for_article(item), |
406 | :content_type => item.mime_type | 406 | :content_type => item.mime_type |
407 | } | 407 | } |
lib/delayed_attachment_fu.rb
@@ -38,7 +38,11 @@ module DelayedAttachmentFu | @@ -38,7 +38,11 @@ module DelayedAttachmentFu | ||
38 | end | 38 | end |
39 | 39 | ||
40 | def public_filename(size=nil) | 40 | def public_filename(size=nil) |
41 | - if !self.thumbnailable? || self.thumbnails_processed | 41 | + force = (size == :uploaded) |
42 | + if force | ||
43 | + size = nil | ||
44 | + end | ||
45 | + if !self.thumbnailable? || self.thumbnails_processed || force | ||
42 | super(size) | 46 | super(size) |
43 | else | 47 | else |
44 | size ||= 'thumb' | 48 | size ||= 'thumb' |
test/functional/cms_controller_test.rb
@@ -1632,7 +1632,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -1632,7 +1632,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
1632 | end | 1632 | end |
1633 | 1633 | ||
1634 | should 'upload media by AJAX' do | 1634 | should 'upload media by AJAX' do |
1635 | - post :media_upload, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), fixture_file_upload('/files/rails.png', 'image/png')] | 1635 | + post :media_upload, :profile => profile.identifier, :file1 => fixture_file_upload('/files/test.txt', 'text/plain'), :file2 => fixture_file_upload('/files/rails.png', 'image/png'), :file3 => '' |
1636 | assert_match 'test.txt', @response.body | 1636 | assert_match 'test.txt', @response.body |
1637 | assert_equal 'application/json', @response.content_type | 1637 | assert_equal 'application/json', @response.content_type |
1638 | 1638 | ||
@@ -1644,10 +1644,14 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -1644,10 +1644,14 @@ class CmsControllerTest < Test::Unit::TestCase | ||
1644 | assert_match /text/, data[0]['content_type'] | 1644 | assert_match /text/, data[0]['content_type'] |
1645 | 1645 | ||
1646 | assert_equal 'rails.png', data[1]['title'] | 1646 | assert_equal 'rails.png', data[1]['title'] |
1647 | - assert_match /\/testinguser\/rails.png$/, data[1]['url'] | 1647 | + assert_no_match /\/public\/articles\/.*\/rails.png$/, data[1]['url'] |
1648 | assert_match /png$/, data[1]['icon'] | 1648 | assert_match /png$/, data[1]['icon'] |
1649 | assert_match /image/, data[1]['content_type'] | 1649 | assert_match /image/, data[1]['content_type'] |
1650 | 1650 | ||
1651 | end | 1651 | end |
1652 | 1652 | ||
1653 | + should 'not when media upload via AJAX contains empty files' do | ||
1654 | + post :media_upload, :profile => @profile.identifier | ||
1655 | + end | ||
1656 | + | ||
1653 | end | 1657 | end |