diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 2bbde8b..9285a2b 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -65,7 +65,7 @@ module BoxesHelper end def display_box_content(box, main_content) - context = { :article => @page } + context = { :article => @page, :request_path => request.path } box_decorator.select_blocks(box.blocks, context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) end diff --git a/app/models/block.rb b/app/models/block.rb index 8588ae8..b25d364 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -23,8 +23,12 @@ class Block < ActiveRecord::Base if display == 'never' return false end - if context && context[:article] && display == 'home_page_only' - return context[:article] == owner.home_page + if context && display == 'home_page_only' + if context[:article] + return context[:article] == owner.home_page + else + return context[:request_path] == '/' + end end true end diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index ca12cc9..dc73f67 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -52,4 +52,16 @@ all_fixtures get :index assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} end + + should 'display block in index page if it\'s configured to display on homepage and its an environment block' do + env = Environment.default + box = Box.create(:owner_type => 'Environment', :owner_id => env.id) + block = Block.create(:title => "Index Block", :box_id => box.id, :display => 'home_page_only') + env.save! + + get :index + assert block.visible? + end + + end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index 2c40972..1c69c1e 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -86,6 +86,13 @@ class BlockTest < Test::Unit::TestCase assert_equal false, block.visible?(:article => Article.new) end + should 'be able to be displayed only in the homepage (index) of the environment' do + block = Block.new(:display => 'home_page_only') + + assert_equal true, block.visible?(:article => nil, :request_path => '/') + assert_equal false, block.visible?(:article => nil) + end + should 'be able to save display setting' do user = create_user('testinguser').person box = fast_create(Box, :owner_id => user.id) -- libgit2 0.21.2