Commit 70f92430dc1ba9553f330841953d9d98662acfbc
Committed by
Thiago Ribeiro
1 parent
8b9f29ca
Exists in
stable-spb-1.4
and in
8 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
29 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,32 @@ 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 | + | |
| 148 | + should 'display images with subdir src' do | |
| 149 | + Noosfero.stubs(:root).returns("/social") | |
| 150 | + f1 = mock() | |
| 151 | + f1.expects(:public_filename).returns('/img_address') | |
| 152 | + UploadedFile.expects(:find).with(1).returns(f1) | |
| 153 | + block = HighlightsBlock.new | |
| 154 | + i1 = {:image_id => 1, :address => '/address'} | |
| 155 | + block.images = [i1] | |
| 156 | + block.save! | |
| 157 | + | |
| 158 | + assert_tag_in_string instance_eval(& block.content), :tag => 'img', :attributes => { :src => "/social/img_address" } | |
| 159 | + end | |
| 160 | + | |
| 135 | 161 | [Environment, Profile].each do |klass| |
| 136 | 162 | should "choose between owner galleries when owner is #{klass.name}" do |
| 137 | 163 | owner = fast_create(klass) | ... | ... |