diff --git a/app/models/block.rb b/app/models/block.rb index aaf51d8..a0edb0f 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -72,18 +72,23 @@ class Block < ActiveRecord::Base end def display_home_page_only(context) - if context[:article] - return context[:article] == owner.home_page + return context[:article] == owner.home_page if context[:article] + + if owner.kind_of?(Profile) + return owner.home_page.nil? && context[:request_path] == "/profile/#{owner.identifier}" else return context[:request_path] == '/' end end def display_except_home_page(context) - if context[:article] - return context[:article] != owner.home_page + return context[:article] != owner.home_page if context[:article] + + if owner.kind_of?(Profile) + return (!owner.home_page.nil? && context[:request_path] != "/#{owner.identifier}") || + (owner.home_page.nil? && context[:request_path] != "/profile/#{owner.identifier}") else - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '') + return context[:request_path] != '/' end end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index bcf1186..10db2c7 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -79,6 +79,16 @@ class BlockTest < ActiveSupport::TestCase assert_equal false, block.visible?(:article => Article.new) end + should 'be able to be displayed only in the default profile homepage when home page is nil' do + profile = build(Profile, :identifier => 'testinguser') + profile.home_page = nil + block = build(Block, :display => 'home_page_only') + block.stubs(:owner).returns(profile) + + assert_equal true, block.visible?(:request_path => '/profile/testinguser') + 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 = build(Block, :display => 'home_page_only') @@ -99,6 +109,8 @@ class BlockTest < ActiveSupport::TestCase should 'be able to be displayed everywhere except on profile index' do profile = build(Profile, :identifier => 'testinguser') + home_page = Article.new + profile.home_page = home_page block = build(Block, :display => 'except_home_page') block.stubs(:owner).returns(profile) @@ -106,6 +118,15 @@ class BlockTest < ActiveSupport::TestCase assert_equal true, block.visible?(:article => nil) end + should 'be able to be displayed everywhere except on default profile index' do + profile = build(Profile, :identifier => 'testinguser') + block = build(Block, :display => 'except_home_page') + block.stubs(:owner).returns(profile) + + assert_equal false, block.visible?(:article => nil, :request_path => '/profile/testinguser') + assert_equal true, 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, :owner_type => 'Profile') -- libgit2 0.21.2