Commit 29aa1c0d9b76fca30053670ac0457b13dc84bcfc

Authored by Daniela Feitosa
1 parent ed749ee3

Added option to not display block on profile homepage

(ActionItem1981)
app/models/block.rb
... ... @@ -34,6 +34,12 @@ class Block < ActiveRecord::Base
34 34 else
35 35 return context[:request_path] == '/'
36 36 end
  37 + elsif display == 'except_home_page'
  38 + if context[:article]
  39 + return context[:article] != owner.home_page
  40 + else
  41 + return context[:request_path] != '/' + owner.identifier
  42 + end
37 43 end
38 44 end
39 45 true
... ... @@ -45,6 +51,8 @@ class Block < ActiveRecord::Base
45 51 # * <tt>'never'</tt>: the block is hidden (it does not appear for visitors)
46 52 # * <tt>'home_page_only'</tt> the block is displayed only when viewing the
47 53 # homepage of its owner.
  54 + # * <tt>'except_home_page'</tt> the block is displayed only when viewing
  55 + # the homepage of its owner.
48 56 settings_items :display, :type => :string, :default => 'always'
49 57  
50 58 # The block can be configured to be displayed in all languages or in just one language. It can assume any locale of the environment:
... ...
app/views/box_organizer/edit.rhtml
... ... @@ -14,6 +14,9 @@
14 14 <%= radio_button(:block, :display, 'home_page_only') %>
15 15 <%= label_tag('block_display_home_page_only', _('Only in the homepage')) %>
16 16 <br/>
  17 + <%= radio_button(:block, :display, 'except_home_page') %>
  18 + <%= label_tag('block_display_except_home_page', _('In all pages, except in the homepage')) %>
  19 + <br/>
17 20 <%= radio_button(:block, :display, 'never') %>
18 21 <%= label_tag('block_display_never', _("Don't display")) %>
19 22 </div>
... ...
test/functional/profile_design_controller_test.rb
... ... @@ -171,6 +171,13 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
171 171 end
172 172 end
173 173  
  174 + should 'have options to display blocks' do
  175 + get :edit, :profile => 'designtestuser', :id => @b1.id
  176 + %w[always home_page_only except_home_page never].each do |option|
  177 + assert_tag :input, :attributes => { :type => 'radio', :value => option}
  178 + end
  179 + end
  180 +
174 181 ######################################################
175 182 # END - tests for BoxOrganizerController features
176 183 ######################################################
... ...
test/unit/block_test.rb
... ... @@ -85,6 +85,26 @@ class BlockTest &lt; Test::Unit::TestCase
85 85 assert_equal false, block.visible?(:article => nil)
86 86 end
87 87  
  88 + should 'be able to be displayed everywhere except in the homepage' do
  89 + profile = Profile.new
  90 + home_page = Article.new
  91 + profile.home_page = home_page
  92 + block = Block.new(:display => 'except_home_page')
  93 + block.stubs(:owner).returns(profile)
  94 +
  95 + assert_equal false, block.visible?(:article => home_page)
  96 + assert_equal true, block.visible?(:article => Article.new)
  97 + end
  98 +
  99 + should 'be able to be displayed everywhere except on profile index' do
  100 + profile = Profile.new(:identifier => 'testinguser')
  101 + block = Block.new(:display => 'except_home_page')
  102 + block.stubs(:owner).returns(profile)
  103 +
  104 + assert_equal false, block.visible?(:article => nil, :request_path => '/testinguser')
  105 + assert_equal true, block.visible?(:article => nil)
  106 + end
  107 +
88 108 should 'be able to save display setting' do
89 109 user = create_user('testinguser').person
90 110 box = fast_create(Box, :owner_id => user.id)
... ...