From 1aef97f126c9abc4df05ebef838c80c2f1eccf81 Mon Sep 17 00:00:00 2001 From: Arthur Del Esposte Date: Tue, 6 Jan 2015 13:45:02 +0000 Subject: [PATCH] Fix Block display options to work with subdirectories --- app/models/block.rb | 27 ++++++++++++++++++++++----- test/unit/block_test.rb | 6 +++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/models/block.rb b/app/models/block.rb index aaf51d8..197c40d 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -75,7 +75,7 @@ class Block < ActiveRecord::Base if context[:article] return context[:article] == owner.home_page else - return context[:request_path] == '/' + return home_page_path?(context[:request_path]) end end @@ -83,7 +83,7 @@ class Block < ActiveRecord::Base if context[:article] return context[:article] != owner.home_page else - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '') + return !home_page_path?(context[:request_path]) end end @@ -114,7 +114,7 @@ class Block < ActiveRecord::Base # blocks to choose one to include in the design. # # Must be redefined in subclasses to match the description of each block - # type. + # type. def self.description '(dummy)' end @@ -124,13 +124,13 @@ class Block < ActiveRecord::Base # This method can return several types of objects: # # * String: if the string starts with http:// or https://, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML. - # * Hash: the hash is used to build an URL that is used as the address for a IFRAME. + # * Hash: the hash is used to build an URL that is used as the address for a IFRAME. # * Proc: the Proc is evaluated in the scope of BoxesHelper. The # block can then use render, link_to, etc. # # The method can also return nil, which means "no content". # - # See BoxesHelper#extract_block_content for implementation details. + # See BoxesHelper#extract_block_content for implementation details. def content(args={}) "This is block number %d" % self.id end @@ -239,4 +239,21 @@ class Block < ActiveRecord::Base self.position = block.position end + private + + def home_page_path + home_page_url = Noosfero.root('/') + + if owner.kind_of?(Profile) + home_page_url += "profile/" if owner.home_page.nil? + home_page_url += owner.identifier + end + + return home_page_url + end + + def home_page_path? path + return path == home_page_path || path == (home_page_path + '/') + end + end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index bcf1186..58dfa45 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -6,7 +6,7 @@ class BlockTest < ActiveSupport::TestCase should 'describe itself' do assert_kind_of String, Block.description end - + should 'access owner through box' do user = create_user('testinguser').person @@ -82,7 +82,7 @@ class BlockTest < ActiveSupport::TestCase should 'be able to be displayed only in the homepage (index) of the environment' do block = build(Block, :display => 'home_page_only') - assert_equal true, block.visible?(:article => nil, :request_path => '/') + assert_equal true, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}") assert_equal false, block.visible?(:article => nil) end @@ -102,7 +102,7 @@ class BlockTest < ActiveSupport::TestCase block = build(Block, :display => 'except_home_page') block.stubs(:owner).returns(profile) - assert_equal false, block.visible?(:article => nil, :request_path => '/testinguser') + assert_equal false, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}profile/testinguser") assert_equal true, block.visible?(:article => nil) end -- libgit2 0.21.2