Commit 1aef97f126c9abc4df05ebef838c80c2f1eccf81

Authored by Arthur Esposte
Committed by Antonio Terceiro
1 parent 074bf280

Fix Block display options to work with subdirectories

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing 2 changed files with 25 additions and 8 deletions   Show diff stats
app/models/block.rb
... ... @@ -75,7 +75,7 @@ class Block &lt; ActiveRecord::Base
75 75 if context[:article]
76 76 return context[:article] == owner.home_page
77 77 else
78   - return context[:request_path] == '/'
  78 + return home_page_path?(context[:request_path])
79 79 end
80 80 end
81 81  
... ... @@ -83,7 +83,7 @@ class Block &lt; ActiveRecord::Base
83 83 if context[:article]
84 84 return context[:article] != owner.home_page
85 85 else
86   - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '')
  86 + return !home_page_path?(context[:request_path])
87 87 end
88 88 end
89 89  
... ... @@ -114,7 +114,7 @@ class Block &lt; ActiveRecord::Base
114 114 # blocks to choose one to include in the design.
115 115 #
116 116 # Must be redefined in subclasses to match the description of each block
117   - # type.
  117 + # type.
118 118 def self.description
119 119 '(dummy)'
120 120 end
... ... @@ -124,13 +124,13 @@ class Block &lt; ActiveRecord::Base
124 124 # This method can return several types of objects:
125 125 #
126 126 # * <tt>String</tt>: if the string starts with <tt>http://</tt> or <tt>https://</tt>, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML.
127   - # * <tt>Hash</tt>: the hash is used to build an URL that is used as the address for a IFRAME.
  127 + # * <tt>Hash</tt>: the hash is used to build an URL that is used as the address for a IFRAME.
128 128 # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The
129 129 # block can then use <tt>render</tt>, <tt>link_to</tt>, etc.
130 130 #
131 131 # The method can also return <tt>nil</tt>, which means "no content".
132 132 #
133   - # See BoxesHelper#extract_block_content for implementation details.
  133 + # See BoxesHelper#extract_block_content for implementation details.
134 134 def content(args={})
135 135 "This is block number %d" % self.id
136 136 end
... ... @@ -239,4 +239,21 @@ class Block &lt; ActiveRecord::Base
239 239 self.position = block.position
240 240 end
241 241  
  242 + private
  243 +
  244 + def home_page_path
  245 + home_page_url = Noosfero.root('/')
  246 +
  247 + if owner.kind_of?(Profile)
  248 + home_page_url += "profile/" if owner.home_page.nil?
  249 + home_page_url += owner.identifier
  250 + end
  251 +
  252 + return home_page_url
  253 + end
  254 +
  255 + def home_page_path? path
  256 + return path == home_page_path || path == (home_page_path + '/')
  257 + end
  258 +
242 259 end
... ...
test/unit/block_test.rb
... ... @@ -6,7 +6,7 @@ class BlockTest &lt; ActiveSupport::TestCase
6 6 should 'describe itself' do
7 7 assert_kind_of String, Block.description
8 8 end
9   -
  9 +
10 10 should 'access owner through box' do
11 11 user = create_user('testinguser').person
12 12  
... ... @@ -82,7 +82,7 @@ class BlockTest &lt; ActiveSupport::TestCase
82 82 should 'be able to be displayed only in the homepage (index) of the environment' do
83 83 block = build(Block, :display => 'home_page_only')
84 84  
85   - assert_equal true, block.visible?(:article => nil, :request_path => '/')
  85 + assert_equal true, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}")
86 86 assert_equal false, block.visible?(:article => nil)
87 87 end
88 88  
... ... @@ -102,7 +102,7 @@ class BlockTest &lt; ActiveSupport::TestCase
102 102 block = build(Block, :display => 'except_home_page')
103 103 block.stubs(:owner).returns(profile)
104 104  
105   - assert_equal false, block.visible?(:article => nil, :request_path => '/testinguser')
  105 + assert_equal false, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}profile/testinguser")
106 106 assert_equal true, block.visible?(:article => nil)
107 107 end
108 108  
... ...