Commit c722f4b7c436ae4bcdd717a40d2dd8bfe0460dc6
Exists in
master
and in
29 other branches
Merge branch 'stable' of https://gitlab.com/noosfero/noosfero into stable
Showing
5 changed files
with
44 additions
and
2 deletions
Show diff stats
app/models/block.rb
app/models/members_block.rb
... | ... | @@ -36,4 +36,15 @@ class MembersBlock < ProfileListBlock |
36 | 36 | } |
37 | 37 | end |
38 | 38 | |
39 | + def cache_key(language='en', user=nil) | |
40 | + logged = '' | |
41 | + if user | |
42 | + logged += '-logged-in' | |
43 | + if user.is_member_of? self.owner | |
44 | + logged += '-member' | |
45 | + end | |
46 | + end | |
47 | + super + logged | |
48 | + end | |
49 | + | |
39 | 50 | end | ... | ... |
app/views/shared/block.rhtml
test/unit/block_test.rb
... | ... | @@ -165,4 +165,11 @@ class BlockTest < ActiveSupport::TestCase |
165 | 165 | conditions = Block.expire_on |
166 | 166 | assert conditions[:environment].kind_of?(Array) |
167 | 167 | end |
168 | + | |
169 | + should 'accept user as parameter on cache_key without change its value' do | |
170 | + person = fast_create(Person) | |
171 | + block = Block.new | |
172 | + assert_equal block.cache_key('en'), block.cache_key('en', person) | |
173 | + end | |
174 | + | |
168 | 175 | end | ... | ... |
test/unit/members_block_test.rb
... | ... | @@ -35,4 +35,28 @@ class MembersBlockTest < ActiveSupport::TestCase |
35 | 35 | assert_same list, block.profiles |
36 | 36 | end |
37 | 37 | |
38 | + should 'use logged-in to compose cache key' do | |
39 | + person = fast_create(Person) | |
40 | + community = fast_create(Community) | |
41 | + block = MembersBlock.create | |
42 | + block.expects(:owner).returns(community) | |
43 | + | |
44 | + assert_match(/-logged-in/,block.cache_key('en', person)) | |
45 | + end | |
46 | + | |
47 | + should 'use logged-in and member to compose cache key for members' do | |
48 | + person = fast_create(Person) | |
49 | + community = fast_create(Community) | |
50 | + community.add_member person | |
51 | + block = MembersBlock.create | |
52 | + block.expects(:owner).returns(community) | |
53 | + | |
54 | + assert_match(/-logged-in-member/,block.cache_key('en', person)) | |
55 | + end | |
56 | + | |
57 | + should 'not change block cache key if user is nil' do | |
58 | + block = MembersBlock.new | |
59 | + assert_equal block.cache_key('en'), block.cache_key('en', nil) | |
60 | + end | |
61 | + | |
38 | 62 | end | ... | ... |