[Git][noosfero/noosfero][master] 3 commits: Returning original image when it is reloading.

Victor Costa gitlab at mg.gitlab.com
Wed Nov 16 17:59:02 BRST 2016


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
f4cbf787 by Leonardo Soares at 2016-11-16T15:42:27-03:00
Returning original image when it is reloading.

Adjustments on tests to handle the new behavior

- - - - -
cd335426 by Victor Costa at 2016-11-16T15:54:25-03:00
Add an option to fallback to original image when processing delayed attachment

- - - - -
b92c269b by Victor Costa at 2016-11-16T19:58:47+00:00
Merge branch 'show_original_message_while_reloading' into 'master'

Show original image while reloading

See merge request !1043
- - - - -


5 changed files:

- app/models/concerns/delayed_attachment_fu.rb
- config/noosfero.yml.dist
- test/functional/content_viewer_controller_test.rb
- test/unit/image_test.rb
- test/unit/uploaded_file_test.rb


Changes:

=====================================
app/models/concerns/delayed_attachment_fu.rb
=====================================
--- a/app/models/concerns/delayed_attachment_fu.rb
+++ b/app/models/concerns/delayed_attachment_fu.rb
@@ -44,12 +44,15 @@ module DelayedAttachmentFu
         super size
       else
         size ||= :thumb
-        '/images/icons-app/image-loading-%s.png' % size
+
+        if NOOSFERO_CONF['delayed_attachment_fallback_original_image'] && self.full_filename
+          self.full_filename.to_s.gsub %r(^#{Regexp.escape(base_path)}), ''
+        else
+          '/images/icons-app/image-loading-%s.png' % size
+        end
       end
     end
 
 
   end
 end
-
-


=====================================
config/noosfero.yml.dist
=====================================
--- a/config/noosfero.yml.dist
+++ b/config/noosfero.yml.dist
@@ -14,6 +14,7 @@ development:
   api_recaptcha_site_key:      '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-'
   api_recaptcha_private_key:   '6LdsWAcTAAAAAB6maB_HalVyCc4asDAxPxloIMvY'
   api_recaptcha_verify_uri:    'https://www.google.com/recaptcha/api/siteverify'  
+  delayed_attachment_fallback_original_image: false
 
 test:
 
@@ -21,4 +22,4 @@ production:
   api_recaptcha_site_key:      '6LcLPAcTAAAAAKsd0bxY_TArhD_A7OL19SRCW7_i'
   api_recaptcha_private_key:   '6LcLPAcTAAAAAE36SN1M2w1I7Hn8upwXYZ_YQZ5-'
   api_recaptcha_verify_uri:    'https://www.google.com/recaptcha/api/siteverify'
-  
\ No newline at end of file
+  


=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -686,7 +686,6 @@ class ContentViewerControllerTest < ActionController::TestCase
     assert_select '.image-gallery-item', 0
   end
 
-
   should 'display default image in the slideshow if thumbnails were not processed' do
     @controller.stubs(:per_page).returns(1)
     folder = Gallery.create!(:name => 'gallery', :profile => profile)
@@ -698,6 +697,18 @@ class ContentViewerControllerTest < ActionController::TestCase
     assert_tag :tag => 'img', :attributes => {:src => /\/images\/icons-app\/image-loading-display.png/}
   end
 
+  should 'display original image in the slideshow if thumbnails were not processed and fallback is enabled' do
+    @controller.stubs(:per_page).returns(1)
+    folder = Gallery.create!(:name => 'gallery', :profile => profile)
+
+    NOOSFERO_CONF['delayed_attachment_fallback_original_image'] = true
+    image1 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'))
+
+    get :view_page, :profile => profile.identifier, :page => folder.path, :slideshow => true
+
+    assert_tag :tag => 'img', :attributes => {:src => /\/other-pic.jpg/}
+  end
+
   should 'display thumbnail image in the slideshow if thumbnails were processed' do
     @controller.stubs(:per_page).returns(1)
     folder = Gallery.create!(:name => 'gallery', :profile => profile)
@@ -721,6 +732,18 @@ class ContentViewerControllerTest < ActionController::TestCase
     assert_tag :tag => 'a', :attributes => {:class => 'image', :style => /background-image: url\(\/images\/icons-app\/image-loading-thumb.png\)/}
   end
 
+  should 'display original image in gallery if thumbnails were not processed and fallback is enabled' do
+    @controller.stubs(:per_page).returns(1)
+    folder = Gallery.create!(:name => 'gallery', :profile => profile)
+
+    NOOSFERO_CONF['delayed_attachment_fallback_original_image'] = true
+    image1 = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'))
+
+    get :view_page, :profile => profile.identifier, :page => folder.path
+
+    assert_tag :tag => 'a', :attributes => {:class => 'image', :style => /background-image: url\(.*\/other-pic.jpg\)/}
+  end
+
   should 'display thumbnail image in gallery if thumbnails were processed' do
     @controller.stubs(:per_page).returns(1)
     folder = Gallery.create!(:name => 'gallery', :profile => profile)


=====================================
test/unit/image_test.rb
=====================================
--- a/test/unit/image_test.rb
+++ b/test/unit/image_test.rb
@@ -63,6 +63,16 @@ class ImageTest < ActiveSupport::TestCase
     assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename(:thumb)
   end
 
+  should 'use origin image if thumbnails were not processed and fallback is enabled' do
+    NOOSFERO_CONF.expects(:[]).with('delayed_attachment_fallback_original_image').returns(true).at_least_once
+    file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+    profile.update_attribute(:image_id, file.id)
+
+    assert_match(/rails.png/, Image.find(file.id).public_filename(:thumb))
+
+    file.destroy
+  end
+
   should 'return image thumbnail if thumbnails were processed' do
     file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
     profile.update_attribute(:image_id, file.id)


=====================================
test/unit/uploaded_file_test.rb
=====================================
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -192,6 +192,15 @@ class UploadedFileTest < ActiveSupport::TestCase
     assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename
   end
 
+  should 'use origin image if thumbnails were not processed and fallback is enabled' do
+    NOOSFERO_CONF.expects(:[]).with('delayed_attachment_fallback_original_image').returns(true).at_least_once
+    file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile)
+
+    assert_match(/rails.png/, UploadedFile.find(file.id).public_filename(:thumb))
+
+    file.destroy
+  end
+
   should 'return image thumbnail if thumbnails were processed' do
     file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile)
     process_delayed_job_queue



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c6873f3558f8f653da49c8f2874c6d2f83097183...b92c269b5ec58791faae7347a73c16c1c6023dc6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20161116/76d277b3/attachment-0001.html>


More information about the Noosfero-dev mailing list