[Git][noosfero/noosfero][master] 2 commits: Fix highlights_block error on add Noosfero.root

Daniela Feitosa gitlab at gitlab.com
Thu Oct 8 11:52:22 BRT 2015


Daniela Feitosa pushed to branch master at Noosfero / noosfero


Commits:
74a61295 by Luciano Prestes Cavalcanti at 2015-10-08T16:46:33Z
Fix highlights_block error on add Noosfero.root

Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr at gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza at hotmail.com>

- - - - -
0fa27860 by Daniela Feitosa at 2015-10-08T14:51:50Z
Merge branch 'fix_highlight_block' into 'master'

Fix highlights_block error on add Noosfero.root

@danielafeitosa, can you review this merge request?

See merge request !701
- - - - -


2 changed files:

- app/models/highlights_block.rb
- test/unit/highlights_block_test.rb


Changes:

=====================================
app/models/highlights_block.rb
=====================================
--- a/app/models/highlights_block.rb
+++ b/app/models/highlights_block.rb
@@ -12,7 +12,9 @@ class HighlightsBlock < Block
     block.images.each do |i|
       i[:image_id] = i[:image_id].to_i
       i[:position] = i[:position].to_i
-      i[:address] = Noosfero.root + i[:address]  unless Noosfero.root.nil?
+      if !Noosfero.root.nil? and !i[:address].start_with?(Noosfero.root + '/')
+        i[:address] = Noosfero.root + i[:address]
+      end
       begin
         file = UploadedFile.find(i[:image_id])
         i[:image_src] = file.public_filename


=====================================
test/unit/highlights_block_test.rb
=====================================
--- a/test/unit/highlights_block_test.rb
+++ b/test/unit/highlights_block_test.rb
@@ -132,6 +132,19 @@ class HighlightsBlockTest < ActiveSupport::TestCase
     assert_equal block.images.first[:address], "/social/address"
   end
 
+  should 'not duplicate sub-dir address before save' do
+    Noosfero.stubs(:root).returns("/social")
+    f1 = mock()
+    f1.expects(:public_filename).returns('address')
+    UploadedFile.expects(:find).with(1).returns(f1)
+    block = HighlightsBlock.new
+    i1 = {:image_id => 1, :address => '/social/address', :position => 3, :title => 'address'}
+    block.images = [i1]
+    block.save!
+    block.reload
+    assert_equal block.images.first[:address], "/social/address"
+  end
+
   should 'display images with subdir src' do
     Noosfero.stubs(:root).returns("/social")
     f1 = mock()



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/9c9f0fbcf6f586fb71a768fd0706331fb15f228f...0fa2786025f67ed14e295a74a7e66cc773081673
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151008/0b55db81/attachment.html>


More information about the Noosfero-dev mailing list