Commit 9e7cf971d9ee2a7c8f7057579a99f95562890ddc

Authored by Victor Costa
1 parent 90f4f1c1

Fix block display options when a profile has no home page defined

The home_page_only and except_home_page methods should work when no home page was selected for a profile.
Showing 2 changed files with 31 additions and 5 deletions   Show diff stats
app/models/block.rb
... ... @@ -72,18 +72,23 @@ class Block < ActiveRecord::Base
72 72 end
73 73  
74 74 def display_home_page_only(context)
75   - if context[:article]
76   - return context[:article] == owner.home_page
  75 + return context[:article] == owner.home_page if context[:article]
  76 +
  77 + if owner.kind_of?(Profile)
  78 + return owner.home_page.nil? && context[:request_path] == "/profile/#{owner.identifier}"
77 79 else
78 80 return context[:request_path] == '/'
79 81 end
80 82 end
81 83  
82 84 def display_except_home_page(context)
83   - if context[:article]
84   - return context[:article] != owner.home_page
  85 + return context[:article] != owner.home_page if context[:article]
  86 +
  87 + if owner.kind_of?(Profile)
  88 + return (!owner.home_page.nil? && context[:request_path] != "/#{owner.identifier}") ||
  89 + (owner.home_page.nil? && context[:request_path] != "/profile/#{owner.identifier}")
85 90 else
86   - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '')
  91 + return context[:request_path] != '/'
87 92 end
88 93 end
89 94  
... ...
test/unit/block_test.rb
... ... @@ -79,6 +79,16 @@ class BlockTest < ActiveSupport::TestCase
79 79 assert_equal false, block.visible?(:article => Article.new)
80 80 end
81 81  
  82 + should 'be able to be displayed only in the default profile homepage when home page is nil' do
  83 + profile = build(Profile, :identifier => 'testinguser')
  84 + profile.home_page = nil
  85 + block = build(Block, :display => 'home_page_only')
  86 + block.stubs(:owner).returns(profile)
  87 +
  88 + assert_equal true, block.visible?(:request_path => '/profile/testinguser')
  89 + assert_equal false, block.visible?(:article => Article.new)
  90 + end
  91 +
82 92 should 'be able to be displayed only in the homepage (index) of the environment' do
83 93 block = build(Block, :display => 'home_page_only')
84 94  
... ... @@ -99,6 +109,8 @@ class BlockTest < ActiveSupport::TestCase
99 109  
100 110 should 'be able to be displayed everywhere except on profile index' do
101 111 profile = build(Profile, :identifier => 'testinguser')
  112 + home_page = Article.new
  113 + profile.home_page = home_page
102 114 block = build(Block, :display => 'except_home_page')
103 115 block.stubs(:owner).returns(profile)
104 116  
... ... @@ -106,6 +118,15 @@ class BlockTest < ActiveSupport::TestCase
106 118 assert_equal true, block.visible?(:article => nil)
107 119 end
108 120  
  121 + should 'be able to be displayed everywhere except on default profile index' do
  122 + profile = build(Profile, :identifier => 'testinguser')
  123 + block = build(Block, :display => 'except_home_page')
  124 + block.stubs(:owner).returns(profile)
  125 +
  126 + assert_equal false, block.visible?(:article => nil, :request_path => '/profile/testinguser')
  127 + assert_equal true, block.visible?(:article => nil)
  128 + end
  129 +
109 130 should 'be able to save display setting' do
110 131 user = create_user('testinguser').person
111 132 box = fast_create(Box, :owner_id => user.id, :owner_type => 'Profile')
... ...