Commit a9e829e6c307ca8a74c108244cc5d4b8823df82d

Authored by AntonioTerceiro
1 parent 9a5e1c66

ActionItem601: implemented "My Network" block

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2348 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -16,6 +16,7 @@ class ProfileDesignController < BoxOrganizerController
16 16 if profile.person?
17 17 blocks << FriendsBlock
18 18 blocks << FavoriteEnterprisesBlock
  19 + blocks << MyNetworkBlock
19 20 end
20 21  
21 22 # blocks exclusive for enterprises
... ...
app/controllers/public/profile_controller.rb
... ... @@ -9,6 +9,10 @@ class ProfileController &lt; ApplicationController
9 9 @tags = profile.tags
10 10 end
11 11  
  12 + def tags
  13 + @tags = profile.tags
  14 + end
  15 +
12 16 def tag
13 17 @tag = params[:id]
14 18 @tagged = profile.find_tagged_with(@tag)
... ...
app/models/my_network_block.rb 0 → 100644
... ... @@ -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
... ... @@ -278,7 +278,7 @@ class Profile &lt; ActiveRecord::Base
278 278 end
279 279  
280 280 # FIXME this can be SLOW
281   - def tags(public_only = false)
  281 + def tags
282 282 totals = {}
283 283 articles.each do |article|
284 284 article.tags.each do |tag|
... ...
app/views/profile/tags.rhtml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h1><%= _("%s's tags") % @profile.name %></h1>
  2 +
  3 +<%= tag_cloud(@tags, :id, { :action => :tag}, {:show_count => true} ) %>
... ...
lib/zen3_terminology.rb
... ... @@ -38,6 +38,10 @@ class Zen3Terminology &lt; 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 &lt; 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
... ...
test/unit/my_network_block_test.rb 0 → 100644
... ... @@ -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 &lt; 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
... ...