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,7 +65,7 @@ module BoxesHelper
65 end 65 end
66 66
67 def display_box_content(box, main_content) 67 def display_box_content(box, main_content)
68 - context = { :article => @page } 68 + context = { :article => @page, :request_path => request.path }
69 box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) 69 box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box)
70 end 70 end
71 71
app/models/block.rb
@@ -23,8 +23,12 @@ class Block < ActiveRecord::Base @@ -23,8 +23,12 @@ class Block < ActiveRecord::Base
23 if display == 'never' 23 if display == 'never'
24 return false 24 return false
25 end 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 end 32 end
29 true 33 true
30 end 34 end
test/functional/home_controller_test.rb
@@ -52,4 +52,16 @@ all_fixtures @@ -52,4 +52,16 @@ all_fixtures
52 get :index 52 get :index
53 assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} 53 assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}}
54 end 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 end 67 end
test/unit/block_test.rb
@@ -86,6 +86,13 @@ class BlockTest < Test::Unit::TestCase @@ -86,6 +86,13 @@ class BlockTest < Test::Unit::TestCase
86 assert_equal false, block.visible?(:article => Article.new) 86 assert_equal false, block.visible?(:article => Article.new)
87 end 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 should 'be able to save display setting' do 96 should 'be able to save display setting' do
90 user = create_user('testinguser').person 97 user = create_user('testinguser').person
91 box = fast_create(Box, :owner_id => user.id) 98 box = fast_create(Box, :owner_id => user.id)