Commit a9e829e6c307ca8a74c108244cc5d4b8823df82d
1 parent
9a5e1c66
Exists in
master
and in
29 other branches
ActionItem601: implemented "My Network" block
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2348 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
109 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
app/controllers/public/profile_controller.rb
... | ... | @@ -0,0 +1,24 @@ |
1 | +class MyNetworkBlock < Block | |
2 | + | |
3 | + include ActionController::UrlWriter | |
4 | + | |
5 | + def self.description | |
6 | + _('A block that displays a summary of your network') | |
7 | + end | |
8 | + | |
9 | + def default_title | |
10 | + _('My network') | |
11 | + end | |
12 | + | |
13 | + def content | |
14 | + block_title(title) + | |
15 | + content_tag( | |
16 | + 'ul', | |
17 | + content_tag('li', link_to(n_( 'One article published', '%d articles published', owner.articles.count) % owner.articles.count, owner.public_profile_url.merge(:action => 'sitemap') )) + | |
18 | + content_tag('li', link_to(n__('One friend', '%d friends', owner.friends.count) % owner.friends.count, owner.public_profile_url.merge(:action => 'friends'))) + | |
19 | + content_tag('li', link_to(n__('One community', '%d communities', owner.communities.count) % owner.communities.count, owner.public_profile_url.merge(:action => 'communities'))) + | |
20 | + content_tag('li', link_to(n_('One tag', '%d tags', owner.tags.count) % owner.tags.count, owner.public_profile_url.merge(:action => 'tags'))) | |
21 | + ) | |
22 | + end | |
23 | + | |
24 | +end | ... | ... |
app/models/profile.rb
lib/zen3_terminology.rb
... | ... | @@ -38,6 +38,10 @@ class Zen3Terminology < Noosfero::Terminology::Custom |
38 | 38 | 'Favorite Enterprises' => N_('Favorite Organizations'), |
39 | 39 | 'Enterprises in "%s"' => N_('Organizations in "%s"'), |
40 | 40 | 'Register a new Enterprise' => N_('Register a new organization'), |
41 | + 'One friend' => N_('One contact'), | |
42 | + '%d friends' => N_('%d contacts'), | |
43 | + 'One community' => N_('One group'), | |
44 | + '%d communities' => N_('%d groups'), | |
41 | 45 | }) |
42 | 46 | end |
43 | 47 | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -249,4 +249,12 @@ class ProfileControllerTest < Test::Unit::TestCase |
249 | 249 | assert_equal @profile.top_level_articles, assigns(:articles) |
250 | 250 | end |
251 | 251 | |
252 | + should 'list tags' do | |
253 | + Person.any_instance.stubs(:tags).returns({ 'one' => 1, 'two' => 2}) | |
254 | + get :tags, :profile => 'testuser' | |
255 | + | |
256 | + assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/one'} } | |
257 | + assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} } | |
258 | + end | |
259 | + | |
252 | 260 | end | ... | ... |
... | ... | @@ -0,0 +1,60 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class MyNetworkBlockTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @block = MyNetworkBlock.new | |
7 | + @owner = Person.new(:identifier => 'testuser') | |
8 | + @block.stubs(:owner).returns(@owner) | |
9 | + | |
10 | + owner.stubs(:environment).returns(Environment.default) | |
11 | + end | |
12 | + attr_reader :owner, :block | |
13 | + | |
14 | + should 'provide description' do | |
15 | + assert_not_equal Block.description, MyNetworkBlock.description | |
16 | + end | |
17 | + | |
18 | + should 'provide default title' do | |
19 | + assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title | |
20 | + end | |
21 | + | |
22 | + should 'count articles' do | |
23 | + mock_articles = mock | |
24 | + owner.stubs(:articles).returns(mock_articles) | |
25 | + owner.stubs(:tags).returns({}) # don't let tags call articles | |
26 | + mock_articles.stubs(:count).returns(5) | |
27 | + | |
28 | + assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '5 articles published', :attributes => { :href => /\/profile\/testuser\/sitemap$/ } } | |
29 | + end | |
30 | + | |
31 | + should 'count friends' do | |
32 | + mock_friends = mock | |
33 | + owner.stubs(:friends).returns(mock_friends) | |
34 | + mock_friends.stubs(:count).returns(8) | |
35 | + | |
36 | + assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '8 friends', :attributes => { :href => /\profile\/testuser\/friends/ }} | |
37 | + end | |
38 | + | |
39 | + should 'count communities' do | |
40 | + mock_communities = mock | |
41 | + owner.stubs(:communities).returns(mock_communities) | |
42 | + mock_communities.stubs(:count).returns(23) | |
43 | + | |
44 | + assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '23 communities', :attributes => { :href => /\profile\/testuser\/communities/ }} | |
45 | + end | |
46 | + | |
47 | + should 'count tags' do | |
48 | + mock_tags = mock | |
49 | + owner.stubs(:tags).returns(mock_tags) | |
50 | + mock_tags.stubs(:count).returns(436) | |
51 | + | |
52 | + assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '436 tags', :attributes => { :href => /\profile\/testuser\/tags/ }} | |
53 | + end | |
54 | + | |
55 | + should 'display its title' do | |
56 | + block.stubs(:title).returns('My Network') | |
57 | + assert_tag_in_string block.content, :content => 'My Network' | |
58 | + end | |
59 | + | |
60 | +end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -317,6 +317,10 @@ class ProfileTest < Test::Unit::TestCase |
317 | 317 | assert_equivalent [ third], profile.find_tagged_with('third-tag') |
318 | 318 | end |
319 | 319 | |
320 | + should 'provide tag count' do | |
321 | + assert_equal 0, Profile.new.tags.count | |
322 | + end | |
323 | + | |
320 | 324 | should 'have administator role' do |
321 | 325 | Role.expects(:find_by_key).with('profile_admin').returns(Role.new) |
322 | 326 | assert_kind_of Role, Profile::Roles.admin | ... | ... |