Commit ee0a5c0fcc4555b1597557bb1974c9aea6f80578
Exists in
staging
and in
4 other branches
Merge branch 'stable' of gitlab.com:participa/noosfero into stable
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,18 +72,23 @@ class Block < ActiveRecord::Base | ||
72 | end | 72 | end |
73 | 73 | ||
74 | def display_home_page_only(context) | 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 | else | 79 | else |
78 | return context[:request_path] == '/' | 80 | return context[:request_path] == '/' |
79 | end | 81 | end |
80 | end | 82 | end |
81 | 83 | ||
82 | def display_except_home_page(context) | 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 | else | 90 | else |
86 | - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '') | 91 | + return context[:request_path] != '/' |
87 | end | 92 | end |
88 | end | 93 | end |
89 | 94 |
test/unit/block_test.rb
@@ -83,6 +83,16 @@ class BlockTest < ActiveSupport::TestCase | @@ -83,6 +83,16 @@ class BlockTest < ActiveSupport::TestCase | ||
83 | assert_equal false, block.visible?(:article => Article.new) | 83 | assert_equal false, block.visible?(:article => Article.new) |
84 | end | 84 | end |
85 | 85 | ||
86 | + should 'be able to be displayed only in the default profile homepage when home page is nil' do | ||
87 | + profile = build(Profile, :identifier => 'testinguser') | ||
88 | + profile.home_page = nil | ||
89 | + block = build(Block, :display => 'home_page_only') | ||
90 | + block.stubs(:owner).returns(profile) | ||
91 | + | ||
92 | + assert_equal true, block.visible?(:request_path => '/profile/testinguser') | ||
93 | + assert_equal false, block.visible?(:article => Article.new) | ||
94 | + end | ||
95 | + | ||
86 | should 'be able to be displayed only in the homepage (index) of the environment' do | 96 | should 'be able to be displayed only in the homepage (index) of the environment' do |
87 | block = build(Block, :display => 'home_page_only') | 97 | block = build(Block, :display => 'home_page_only') |
88 | 98 | ||
@@ -103,6 +113,8 @@ class BlockTest < ActiveSupport::TestCase | @@ -103,6 +113,8 @@ class BlockTest < ActiveSupport::TestCase | ||
103 | 113 | ||
104 | should 'be able to be displayed everywhere except on profile index' do | 114 | should 'be able to be displayed everywhere except on profile index' do |
105 | profile = build(Profile, :identifier => 'testinguser') | 115 | profile = build(Profile, :identifier => 'testinguser') |
116 | + home_page = Article.new | ||
117 | + profile.home_page = home_page | ||
106 | block = build(Block, :display => 'except_home_page') | 118 | block = build(Block, :display => 'except_home_page') |
107 | block.stubs(:owner).returns(profile) | 119 | block.stubs(:owner).returns(profile) |
108 | 120 | ||
@@ -110,6 +122,15 @@ class BlockTest < ActiveSupport::TestCase | @@ -110,6 +122,15 @@ class BlockTest < ActiveSupport::TestCase | ||
110 | assert_equal true, block.visible?(:article => nil) | 122 | assert_equal true, block.visible?(:article => nil) |
111 | end | 123 | end |
112 | 124 | ||
125 | + should 'be able to be displayed everywhere except on default profile index' do | ||
126 | + profile = build(Profile, :identifier => 'testinguser') | ||
127 | + block = build(Block, :display => 'except_home_page') | ||
128 | + block.stubs(:owner).returns(profile) | ||
129 | + | ||
130 | + assert_equal false, block.visible?(:article => nil, :request_path => '/profile/testinguser') | ||
131 | + assert_equal true, block.visible?(:article => nil) | ||
132 | + end | ||
133 | + | ||
113 | should 'be able to save display setting' do | 134 | should 'be able to save display setting' do |
114 | user = create_user('testinguser').person | 135 | user = create_user('testinguser').person |
115 | box = fast_create(Box, :owner_id => user.id, :owner_type => 'Profile') | 136 | box = fast_create(Box, :owner_id => user.id, :owner_type => 'Profile') |