Commit 74a61295d8e5bda43670d2cc283b0fe473b69929
1 parent
5f1ce128
Exists in
master
and in
21 other branches
Fix highlights_block error on add Noosfero.root
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com>
Showing
2 changed files
with
16 additions
and
1 deletions
Show diff stats
app/models/highlights_block.rb
| ... | ... | @@ -12,7 +12,9 @@ class HighlightsBlock < Block |
| 12 | 12 | block.images.each do |i| |
| 13 | 13 | i[:image_id] = i[:image_id].to_i |
| 14 | 14 | i[:position] = i[:position].to_i |
| 15 | - i[:address] = Noosfero.root + i[:address] unless Noosfero.root.nil? | |
| 15 | + if !Noosfero.root.nil? and !i[:address].start_with?(Noosfero.root + '/') | |
| 16 | + i[:address] = Noosfero.root + i[:address] | |
| 17 | + end | |
| 16 | 18 | begin |
| 17 | 19 | file = UploadedFile.find(i[:image_id]) |
| 18 | 20 | i[:image_src] = file.public_filename | ... | ... |
test/unit/highlights_block_test.rb
| ... | ... | @@ -132,6 +132,19 @@ class HighlightsBlockTest < ActiveSupport::TestCase |
| 132 | 132 | assert_equal block.images.first[:address], "/social/address" |
| 133 | 133 | end |
| 134 | 134 | |
| 135 | + should 'not duplicate sub-dir address before save' do | |
| 136 | + Noosfero.stubs(:root).returns("/social") | |
| 137 | + f1 = mock() | |
| 138 | + f1.expects(:public_filename).returns('address') | |
| 139 | + UploadedFile.expects(:find).with(1).returns(f1) | |
| 140 | + block = HighlightsBlock.new | |
| 141 | + i1 = {:image_id => 1, :address => '/social/address', :position => 3, :title => 'address'} | |
| 142 | + block.images = [i1] | |
| 143 | + block.save! | |
| 144 | + block.reload | |
| 145 | + assert_equal block.images.first[:address], "/social/address" | |
| 146 | + end | |
| 147 | + | |
| 135 | 148 | should 'display images with subdir src' do |
| 136 | 149 | Noosfero.stubs(:root).returns("/social") |
| 137 | 150 | f1 = mock() | ... | ... |