Commit c146c2950d5745502dfcbdbab193cbb008425315
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'fix_block_display_option' 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 | 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
... | ... | @@ -83,6 +83,16 @@ class BlockTest < ActiveSupport::TestCase |
83 | 83 | assert_equal false, block.visible?(:article => Article.new) |
84 | 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 | 96 | should 'be able to be displayed only in the homepage (index) of the environment' do |
87 | 97 | block = build(Block, :display => 'home_page_only') |
88 | 98 | |
... | ... | @@ -103,6 +113,8 @@ class BlockTest < ActiveSupport::TestCase |
103 | 113 | |
104 | 114 | should 'be able to be displayed everywhere except on profile index' do |
105 | 115 | profile = build(Profile, :identifier => 'testinguser') |
116 | + home_page = Article.new | |
117 | + profile.home_page = home_page | |
106 | 118 | block = build(Block, :display => 'except_home_page') |
107 | 119 | block.stubs(:owner).returns(profile) |
108 | 120 | |
... | ... | @@ -110,6 +122,15 @@ class BlockTest < ActiveSupport::TestCase |
110 | 122 | assert_equal true, block.visible?(:article => nil) |
111 | 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 | 134 | should 'be able to save display setting' do |
114 | 135 | user = create_user('testinguser').person |
115 | 136 | box = fast_create(Box, :owner_id => user.id, :owner_type => 'Profile') | ... | ... |