Commit a992dc2fad5ecec0b7de7d41a74cf7a01274d595

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent fd4c6869

"Only in the homepage" for environment blocks too

app/helpers/boxes_helper.rb
... ... @@ -65,7 +65,7 @@ module BoxesHelper
65 65 end
66 66  
67 67 def display_box_content(box, main_content)
68   - context = { :article => @page }
  68 + context = { :article => @page, :request_path => request.path }
69 69 box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box)
70 70 end
71 71  
... ...
app/models/block.rb
... ... @@ -23,8 +23,12 @@ class Block < ActiveRecord::Base
23 23 if display == 'never'
24 24 return false
25 25 end
26   - if context && context[:article] && display == 'home_page_only'
27   - return context[:article] == owner.home_page
  26 + if context && display == 'home_page_only'
  27 + if context[:article]
  28 + return context[:article] == owner.home_page
  29 + else
  30 + return context[:request_path] == '/'
  31 + end
28 32 end
29 33 true
30 34 end
... ...
test/functional/home_controller_test.rb
... ... @@ -52,4 +52,16 @@ all_fixtures
52 52 get :index
53 53 assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}}
54 54 end
  55 +
  56 + should 'display block in index page if it\'s configured to display on homepage and its an environment block' do
  57 + env = Environment.default
  58 + box = Box.create(:owner_type => 'Environment', :owner_id => env.id)
  59 + block = Block.create(:title => "Index Block", :box_id => box.id, :display => 'home_page_only')
  60 + env.save!
  61 +
  62 + get :index
  63 + assert block.visible?
  64 + end
  65 +
  66 +
55 67 end
... ...
test/unit/block_test.rb
... ... @@ -86,6 +86,13 @@ class BlockTest < Test::Unit::TestCase
86 86 assert_equal false, block.visible?(:article => Article.new)
87 87 end
88 88  
  89 + should 'be able to be displayed only in the homepage (index) of the environment' do
  90 + block = Block.new(:display => 'home_page_only')
  91 +
  92 + assert_equal true, block.visible?(:article => nil, :request_path => '/')
  93 + assert_equal false, block.visible?(:article => nil)
  94 + end
  95 +
89 96 should 'be able to save display setting' do
90 97 user = create_user('testinguser').person
91 98 box = fast_create(Box, :owner_id => user.id)
... ...