Commit d4f19d98fea7bd12493bbbd34e64ffca27aebf8f

Authored by Francisco Marcelo A. Lima Júnior
Committed by Victor Costa
1 parent 0b8db772

Added people_block plugin

Showing 37 changed files with 889 additions and 313 deletions   Show diff stats
app/controllers/admin/environment_design_controller.rb
@@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController
3 protect 'edit_environment_design', :environment 3 protect 'edit_environment_design', :environment
4 4
5 def available_blocks 5 def available_blocks
6 - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] 6 + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
7 @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) 7 @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment)
8 end 8 end
9 9
app/controllers/my_profile/profile_design_controller.rb
@@ -9,14 +9,8 @@ class ProfileDesignController < BoxOrganizerController @@ -9,14 +9,8 @@ class ProfileDesignController < BoxOrganizerController
9 9
10 blocks += plugins.dispatch(:extra_blocks) 10 blocks += plugins.dispatch(:extra_blocks)
11 11
12 - # blocks exclusive for organizations  
13 - if profile.has_members?  
14 - blocks << MembersBlock  
15 - end  
16 -  
17 # blocks exclusive to people 12 # blocks exclusive to people
18 if profile.person? 13 if profile.person?
19 - blocks << FriendsBlock  
20 blocks << FavoriteEnterprisesBlock 14 blocks << FavoriteEnterprisesBlock
21 blocks << CommunitiesBlock 15 blocks << CommunitiesBlock
22 blocks << EnterprisesBlock 16 blocks << EnterprisesBlock
app/helpers/sweeper_helper.rb
@@ -18,9 +18,7 @@ module SweeperHelper @@ -18,9 +18,7 @@ module SweeperHelper
18 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) 18 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s))
19 end 19 end
20 20
21 - # friends blocks  
22 - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}  
23 - BlockSweeper.expire_blocks(blocks) 21 + expire_blocks_cache(profile, [:profile])
24 end 22 end
25 23
26 def expire_communities(profile) 24 def expire_communities(profile)
app/models/box.rb
@@ -25,14 +25,11 @@ class Box &lt; ActiveRecord::Base @@ -25,14 +25,11 @@ class Box &lt; ActiveRecord::Base
25 FansBlock, 25 FansBlock,
26 FavoriteEnterprisesBlock, 26 FavoriteEnterprisesBlock,
27 FeedReaderBlock, 27 FeedReaderBlock,
28 - FriendsBlock,  
29 HighlightsBlock, 28 HighlightsBlock,
30 LinkListBlock, 29 LinkListBlock,
31 LoginBlock, 30 LoginBlock,
32 MainBlock, 31 MainBlock,
33 - MembersBlock,  
34 MyNetworkBlock, 32 MyNetworkBlock,
35 - PeopleBlock,  
36 ProfileImageBlock, 33 ProfileImageBlock,
37 RawHTMLBlock, 34 RawHTMLBlock,
38 RecentDocumentsBlock, 35 RecentDocumentsBlock,
@@ -52,14 +49,11 @@ class Box &lt; ActiveRecord::Base @@ -52,14 +49,11 @@ class Box &lt; ActiveRecord::Base
52 FavoriteEnterprisesBlock, 49 FavoriteEnterprisesBlock,
53 FeaturedProductsBlock, 50 FeaturedProductsBlock,
54 FeedReaderBlock, 51 FeedReaderBlock,
55 - FriendsBlock,  
56 HighlightsBlock, 52 HighlightsBlock,
57 LinkListBlock, 53 LinkListBlock,
58 LocationBlock, 54 LocationBlock,
59 LoginBlock, 55 LoginBlock,
60 - MembersBlock,  
61 MyNetworkBlock, 56 MyNetworkBlock,
62 - PeopleBlock,  
63 ProductsBlock, 57 ProductsBlock,
64 ProfileImageBlock, 58 ProfileImageBlock,
65 ProfileInfoBlock, 59 ProfileInfoBlock,
app/models/community.rb
@@ -73,7 +73,7 @@ class Community &lt; Organization @@ -73,7 +73,7 @@ class Community &lt; Organization
73 end 73 end
74 74
75 def blocks_to_expire_cache 75 def blocks_to_expire_cache
76 - [MembersBlock] 76 + []
77 end 77 end
78 78
79 def each_member(offset=0) 79 def each_member(offset=0)
app/models/environment.rb
@@ -165,7 +165,6 @@ class Environment &lt; ActiveRecord::Base @@ -165,7 +165,6 @@ class Environment &lt; ActiveRecord::Base
165 165
166 # "right" area 166 # "right" area
167 env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6) 167 env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6)
168 - env.boxes[2].blocks << PeopleBlock.new(:limit => 6)  
169 end 168 end
170 169
171 # One Environment can be reached by many domains 170 # One Environment can be reached by many domains
app/models/friends_block.rb
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -class FriendsBlock < ProfileListBlock  
2 -  
3 - def self.description  
4 - __('Friends')  
5 - end  
6 -  
7 - def default_title  
8 - n__('{#} friend', '{#} friends', profile_count)  
9 - end  
10 -  
11 - def help  
12 - _('This block displays your friends.')  
13 - end  
14 -  
15 - def footer  
16 - owner_id = owner.identifier  
17 - lambda do  
18 - link_to s_('friends|View all'), :profile => owner_id, :controller => 'profile', :action => 'friends'  
19 - end  
20 - end  
21 -  
22 - def profiles  
23 - owner.friends  
24 - end  
25 -  
26 -end  
app/models/members_block.rb
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -class MembersBlock < ProfileListBlock  
2 -  
3 - def self.description  
4 - _('Members')  
5 - end  
6 -  
7 - def default_title  
8 - _('{#} members')  
9 - end  
10 -  
11 - def help  
12 - _('This block presents the members of a collective.')  
13 - end  
14 -  
15 - def footer  
16 - profile = self.owner  
17 - lambda do  
18 - link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members'  
19 - end  
20 - end  
21 -  
22 - def profiles  
23 - owner.members  
24 - end  
25 -  
26 -end  
app/models/organization.rb
@@ -130,7 +130,7 @@ class Organization &lt; Profile @@ -130,7 +130,7 @@ class Organization &lt; Profile
130 [ 130 [
131 [MainBlock.new], 131 [MainBlock.new],
132 [ProfileImageBlock.new, LinkListBlock.new(:links => links)], 132 [ProfileImageBlock.new, LinkListBlock.new(:links => links)],
133 - [MembersBlock.new, RecentDocumentsBlock.new] 133 + [RecentDocumentsBlock.new]
134 ] 134 ]
135 end 135 end
136 136
app/models/people_block.rb
@@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
1 -class PeopleBlock < ProfileListBlock  
2 -  
3 - def default_title  
4 - _('People')  
5 - end  
6 -  
7 - def help  
8 - _('Clicking a person takes you to his/her homepage')  
9 - end  
10 -  
11 - def self.description  
12 - _('Random people')  
13 - end  
14 -  
15 - def profiles  
16 - owner.people  
17 - end  
18 -  
19 - def footer  
20 - lambda do  
21 - link_to _('View all'), :controller => 'search', :action => 'people'  
22 - end  
23 - end  
24 -  
25 -end  
app/models/person.rb
@@ -276,7 +276,7 @@ class Person &lt; Profile @@ -276,7 +276,7 @@ class Person &lt; Profile
276 [ 276 [
277 [MainBlock.new], 277 [MainBlock.new],
278 [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new], 278 [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new],
279 - [FriendsBlock.new, CommunitiesBlock.new] 279 + [CommunitiesBlock.new]
280 ] 280 ]
281 end 281 end
282 282
app/sweepers/friendship_sweeper.rb
@@ -34,8 +34,7 @@ protected @@ -34,8 +34,7 @@ protected
34 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) 34 expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s))
35 end 35 end
36 36
37 - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)}  
38 - BlockSweeper.expire_blocks(blocks) 37 + expire_blocks_cache(profile, [:profile])
39 end 38 end
40 39
41 end 40 end
plugins/people_block/lib/friends_block.rb 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +class FriendsBlock < PeopleBlockBase
  2 +
  3 + def self.description
  4 + _('Friends')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a friend takes you to his/her homepage')
  9 + end
  10 +
  11 + def default_title
  12 + _('{#} Friends')
  13 + end
  14 +
  15 + def profiles
  16 + owner.friends
  17 + end
  18 +
  19 + def footer
  20 + owner = self.owner
  21 + lambda do
  22 + link_to _('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'friends'
  23 + end
  24 + end
  25 +
  26 + def self.expire_on
  27 + { :profile => [:profile] }
  28 + end
  29 +
  30 +end
  31 +
plugins/people_block/lib/members_block.rb 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +class MembersBlock < PeopleBlockBase
  2 +
  3 + def self.description
  4 + _('Members')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a member takes you to his/her homepage')
  9 + end
  10 +
  11 + def default_title
  12 + _('{#} Members')
  13 + end
  14 +
  15 + def profiles
  16 + owner.members
  17 + end
  18 +
  19 + def footer
  20 + owner = self.owner
  21 + lambda do
  22 + link_to _('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'members'
  23 + end
  24 + end
  25 +
  26 +end
  27 +
plugins/people_block/lib/people_block.rb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +class PeopleBlock < PeopleBlockBase
  2 +
  3 + def self.description
  4 + _('People')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a person takes you to his/her homepage')
  9 + end
  10 +
  11 + def default_title
  12 + _('{#} People')
  13 + end
  14 +
  15 + def profiles
  16 + owner.people
  17 + end
  18 +
  19 + def footer
  20 + lambda do
  21 + link_to _('View all'), :controller => 'search', :action => 'people'
  22 + end
  23 + end
  24 +
  25 +end
plugins/people_block/lib/people_block_base.rb 0 → 100644
@@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
  1 +class PeopleBlockBase < Block
  2 +
  3 + settings_items :prioritize_people_with_image, :type => :boolean, :default => true
  4 + settings_items :limit, :type => :integer, :default => 6
  5 + settings_items :name, :type => String, :default => ""
  6 + settings_items :address, :type => String, :default => ""
  7 +
  8 + def self.description
  9 + _('Random people')
  10 + end
  11 +
  12 + def help
  13 + _('Clicking on the people or groups will take you to their home page.')
  14 + end
  15 +
  16 + def default_title
  17 + _('{#} People')
  18 + end
  19 +
  20 + def view_title
  21 + title.gsub('{#}', profile_count.to_s)
  22 + end
  23 +
  24 + def profiles
  25 + owner.profiles
  26 + end
  27 +
  28 + def profile_list
  29 + result = nil
  30 + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
  31 + if !prioritize_people_with_image
  32 + result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand }
  33 + elsif visible_profiles.with_image.count >= limit
  34 + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  35 + else
  36 + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand }
  37 + end
  38 + result.slice(0..limit-1)
  39 + end
  40 +
  41 + def profile_count
  42 + profiles.visible.count
  43 + end
  44 +
  45 + def content(args={})
  46 +
  47 + profiles = self.profile_list
  48 + title = self.view_title
  49 +
  50 + if !self.name.blank? && !self.address.blank?
  51 + name = self.name
  52 + expanded_address = expand_address(self.address)
  53 + end
  54 +
  55 + lambda do
  56 + count = 0
  57 + list = profiles.map {|item|
  58 + count += 1
  59 + send(:profile_image_link, item, :minor )
  60 + }.join("\n")
  61 + if list.empty?
  62 + list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none'
  63 + else
  64 + if !name.blank? && !expanded_address.blank?
  65 + list << content_tag(
  66 + 'div',
  67 + content_tag(
  68 + 'li',
  69 + content_tag(
  70 + 'div',
  71 + link_to(
  72 + content_tag('span', name, :class => 'banner-span' ),
  73 + expanded_address,
  74 + :title => name
  75 + ),
  76 + :class => 'banner-div'
  77 + ),
  78 + :class => 'vcard'
  79 + ),
  80 + :class => 'common-profile-list-block'
  81 + )
  82 + end
  83 + list = content_tag 'ul', list
  84 + end
  85 + block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both'))
  86 + end
  87 + end
  88 +
  89 + def expand_address(address)
  90 + if address !~ /^[a-z]+:\/\// && address !~ /^\//
  91 + 'http://' + address
  92 + else
  93 + address
  94 + end
  95 + end
  96 +
  97 +end
  98 +
plugins/people_block/lib/people_block_plugin.rb 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +class PeopleBlockPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "People Block Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that adds a people block")
  9 + end
  10 +
  11 + def self.extra_blocks
  12 + {
  13 + PeopleBlock => {:type => Environment},
  14 + MembersBlock => {:type => Community},
  15 + FriendsBlock => {:type => Person}
  16 + }
  17 + end
  18 +
  19 + def self.has_admin_url?
  20 + false
  21 + end
  22 +
  23 + def stylesheet?
  24 + true
  25 + end
  26 +
  27 +end
plugins/people_block/public/style.css 0 → 100644
@@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
  1 +/*******************************************************************
  2 + * COMMON *
  3 + *******************************************************************/
  4 +.people-block .block-footer-content a {
  5 + position: absolute;
  6 + top: 2px;
  7 + right: 0px;
  8 + font-size: 11px;
  9 + color: #000;
  10 + text-decoration: none;
  11 + padding-right: 15px;
  12 + background: url(/designs/themes/base/imgs/arrow-right-p.png) 100% 50% no-repeat;
  13 +}
  14 +
  15 +.people-block .banner-span {
  16 + color: #000;
  17 + font-size: 14pt;
  18 + font-weight: bold;
  19 + background-color: #EEE;
  20 +}
  21 +
  22 +
  23 +/*******************************************************************
  24 + * MAIN BOX - 1 *
  25 + *******************************************************************/
  26 +.box-1 .people-block .banner-div {
  27 + line-height: 112px;
  28 +}
  29 +
  30 +.box-1 .people-block .banner-span {
  31 + width: 204px;
  32 +}
  33 +
  34 +
  35 +/*******************************************************************
  36 + * LEFT/RIGHT BOXES *
  37 + *******************************************************************/
  38 +.box-2 .people-block .banner-div,
  39 +.box-3 .people-block .banner-div {
  40 + line-height: 78px;
  41 +}
  42 +
  43 +.box-2 .people-block .banner-div a,
  44 +.box-3 .people-block .banner-div a {
  45 + height: 78px;
  46 +}
  47 +
  48 +.box-2 .people-block .banner-span,
  49 +.box-3 .people-block .banner-span {
  50 + width: 116px;
  51 +}
  52 +
  53 +.box-2 .people-block ul,
  54 +.box-3 .people-block ul {
  55 + min-width: 196px;
  56 + width: 192px;
  57 + margin: 0px 0px 0px -3px;
  58 + padding: 0px;
  59 +}
plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class EnvironmentDesignController; def rescue_action(e) raise e end; end
  5 +
  6 +class EnvironmentDesignControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = EnvironmentDesignController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new])
  13 + end
  14 +
  15 + #attr_accessor :environment, :block
  16 +
  17 + #should 'display *block people-block* class at design blocks page' do
  18 + #get :index
  19 + #assert_tag :div, :attributes => {:class => 'block people-block'}
  20 + #end
  21 +
  22 + should 'be able to edit PeopleBlock' do
  23 + login_as(create_admin_user(Environment.default))
  24 + b = PeopleBlock.create!
  25 + e = Environment.default
  26 + e.boxes.create!
  27 + e.boxes.first.blocks << b
  28 + get :edit, :id => b.id
  29 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  30 + end
  31 +
  32 +end
plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb 0 → 100644
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class ProfileDesignController; def rescue_action(e) raise e end; end
  5 +
  6 +class ProfileDesignControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = ProfileDesignController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new])
  13 + end
  14 +
  15 + should 'display *block people-block* class at design blocks page' do
  16 + user = create_user('testinguser')
  17 + login_as(user.login)
  18 +
  19 + @profile = user.person
  20 + @environment = @profile.environment
  21 + @environment.save!
  22 +
  23 + FriendsBlock.delete_all
  24 + @box1 = Box.create!(:owner => @profile)
  25 + @profile.boxes = [@box1]
  26 +
  27 + @block = FriendsBlock.new
  28 + @block.box = @box1
  29 + @block.save!
  30 +
  31 + @profile.blocks<<@block
  32 + @profile.save!
  33 +
  34 + get :index, :profile => @profile.identifier
  35 + assert_tag :div, :attributes => {:class => 'block friends-block'}
  36 + end
  37 +
  38 + should 'the people block is available for person profile' do
  39 + profile = mock
  40 + profile.stubs(:has_members?).returns(false)
  41 + profile.stubs(:person?).returns(true)
  42 + profile.stubs(:community?).returns(false)
  43 + profile.stubs(:enterprise?).returns(false)
  44 + profile.stubs(:has_blog?).returns(false)
  45 + profile.stubs(:is_admin?).with(anything).returns(false)
  46 + environment = mock
  47 + profile.stubs(:environment).returns(environment)
  48 + environment.stubs(:enabled?).returns(false)
  49 + @controller.stubs(:profile).returns(profile)
  50 + @controller.stubs(:user).returns(profile)
  51 + assert_includes @controller.available_blocks, FriendsBlock
  52 + end
  53 +
  54 + should 'the people block is available for community profile' do
  55 + profile = mock
  56 + profile.stubs(:has_members?).returns(true)
  57 + profile.stubs(:person?).returns(false)
  58 + profile.stubs(:community?).returns(true)
  59 + profile.stubs(:enterprise?).returns(false)
  60 + profile.stubs(:has_blog?).returns(false)
  61 + profile.stubs(:is_admin?).with(anything).returns(false)
  62 + environment = mock
  63 + profile.stubs(:environment).returns(environment)
  64 + environment.stubs(:enabled?).returns(false)
  65 + @controller.stubs(:profile).returns(profile)
  66 + @controller.stubs(:user).returns(profile)
  67 + assert_includes @controller.available_blocks, MembersBlock
  68 + end
  69 +
  70 +end
plugins/people_block/test/test_helper.rb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
plugins/people_block/test/unit/friends_block_test.rb 0 → 100644
@@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class FriendsBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, FriendsBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, FriendsBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, FriendsBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = FriendsBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = FriendsBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = FriendsBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = FriendsBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = FriendsBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = FriendsBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = FriendsBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert FriendsBlock.new.prioritize_people_with_image
  64 + end
  65 +
  66 +
  67 + should 'accept a limit of people to be displayed' do
  68 + block = FriendsBlock.new
  69 + block.limit = 20
  70 + assert_equal 20, block.limit
  71 + end
  72 +
  73 +
  74 + should 'list friends from person' do
  75 + owner = fast_create(Person)
  76 + friend1 = fast_create(Person)
  77 + friend2 = fast_create(Person)
  78 + owner.add_friend(friend1)
  79 + owner.add_friend(friend2)
  80 +
  81 + block = FriendsBlock.new
  82 +
  83 + block.expects(:owner).returns(owner).at_least_once
  84 + expects(:profile_image_link).with(friend1, :minor).returns(friend1.name)
  85 + expects(:profile_image_link).with(friend2, :minor).returns(friend2.name)
  86 + expects(:block_title).with(anything).returns('')
  87 +
  88 + content = instance_eval(&block.content)
  89 +
  90 + assert_match(/#{friend1.name}/, content)
  91 + assert_match(/#{friend2.name}/, content)
  92 + end
  93 +
  94 +
  95 + should 'link to "all friends"' do
  96 + person1 = create_user('mytestperson').person
  97 +
  98 + block = FriendsBlock.new
  99 + block.expects(:owner).returns(person1).at_least_once
  100 +
  101 + expects(:_).with('View all').returns('View all')
  102 + expects(:link_to).with('View all', :profile => 'mytestperson', :controller => 'profile', :action => 'friends').returns('link-to-friends')
  103 +
  104 + assert_equal 'link-to-friends', instance_eval(&block.footer)
  105 + end
  106 +
  107 +
  108 + should 'count number of owner friends' do
  109 + owner = fast_create(Person)
  110 + friend1 = fast_create(Person)
  111 + friend2 = fast_create(Person)
  112 + friend3 = fast_create(Person)
  113 + owner.add_friend(friend1)
  114 + owner.add_friend(friend2)
  115 + owner.add_friend(friend3)
  116 +
  117 + block = FriendsBlock.new
  118 + block.expects(:owner).returns(owner).at_least_once
  119 +
  120 + assert_equal 3, block.profile_count
  121 + end
  122 +
  123 +
  124 + should 'count number of public and private friends' do
  125 + owner = fast_create(Person)
  126 + private_p = fast_create(Person, {:public_profile => false})
  127 + public_p = fast_create(Person, {:public_profile => true})
  128 +
  129 + owner.add_friend(private_p)
  130 + owner.add_friend(public_p)
  131 +
  132 + block = FriendsBlock.new
  133 + block.expects(:owner).returns(owner).at_least_once
  134 +
  135 + assert_equal 2, block.profile_count
  136 + end
  137 +
  138 +
  139 + should 'not count number of invisible friends' do
  140 + owner = fast_create(Person)
  141 + private_p = fast_create(Person, {:visible => false})
  142 + public_p = fast_create(Person, {:visible => true})
  143 +
  144 + owner.add_friend(private_p)
  145 + owner.add_friend(public_p)
  146 +
  147 + block = FriendsBlock.new
  148 + block.expects(:owner).returns(owner).at_least_once
  149 +
  150 + assert_equal 1, block.profile_count
  151 + end
  152 +
  153 + protected
  154 + include NoosferoTestHelper
  155 +
  156 +end
plugins/people_block/test/unit/members_block_test.rb 0 → 100644
@@ -0,0 +1,159 @@ @@ -0,0 +1,159 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class MembersBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, MembersBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, MembersBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, MembersBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = MembersBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = MembersBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = MembersBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = MembersBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = MembersBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = MembersBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = MembersBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert MembersBlock.new.prioritize_people_with_image
  64 + end
  65 +
  66 +
  67 + should 'respect limit when listing members' do
  68 + community = fast_create(Community)
  69 + p1 = fast_create(Person)
  70 + p2 = fast_create(Person)
  71 + p3 = fast_create(Person)
  72 + p4 = fast_create(Person)
  73 +
  74 + community.add_member(p1)
  75 + community.add_member(p2)
  76 + community.add_member(p3)
  77 + community.add_member(p4)
  78 +
  79 + block = MembersBlock.new(:limit => 3)
  80 + block.stubs(:owner).returns(community)
  81 +
  82 + assert_equal 3, block.profile_list.size
  83 + end
  84 +
  85 +
  86 + should 'accept a limit of members to be displayed' do
  87 + block = MembersBlock.new
  88 + block.limit = 20
  89 + assert_equal 20, block.limit
  90 + end
  91 +
  92 +
  93 + should 'list members from community' do
  94 + owner = fast_create(Community)
  95 + person1 = fast_create(Person)
  96 + person2 = fast_create(Person)
  97 + owner.add_member(person1)
  98 + owner.add_member(person2)
  99 +
  100 + block = MembersBlock.new
  101 +
  102 + block.expects(:owner).returns(owner).at_least_once
  103 + expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  104 + expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  105 + expects(:block_title).with(anything).returns('')
  106 +
  107 + content = instance_eval(&block.content)
  108 +
  109 + assert_match(/#{person1.name}/, content)
  110 + assert_match(/#{person2.name}/, content)
  111 + end
  112 +
  113 +
  114 + should 'link to "all members"' do
  115 + community = fast_create(Community)
  116 +
  117 + block = MembersBlock.new
  118 + block.expects(:owner).returns(community).at_least_once
  119 +
  120 + expects(:_).with('View all').returns('View all')
  121 + expects(:link_to).with('View all', :profile => community.identifier, :controller => 'profile', :action => 'members').returns('link-to-members')
  122 +
  123 + assert_equal 'link-to-members', instance_eval(&block.footer)
  124 + end
  125 +
  126 +
  127 + should 'count number of public and private members' do
  128 + owner = fast_create(Community)
  129 + private_p = fast_create(Person, {:public_profile => false})
  130 + public_p = fast_create(Person, {:public_profile => true})
  131 +
  132 + owner.add_member(private_p)
  133 + owner.add_member(public_p)
  134 +
  135 + block = MembersBlock.new
  136 + block.expects(:owner).returns(owner).at_least_once
  137 +
  138 + assert_equal 2, block.profile_count
  139 + end
  140 +
  141 +
  142 + should 'not count number of invisible members' do
  143 + owner = fast_create(Community)
  144 + private_p = fast_create(Person, {:visible => false})
  145 + public_p = fast_create(Person, {:visible => true})
  146 +
  147 + owner.add_member(private_p)
  148 + owner.add_member(public_p)
  149 +
  150 + block = MembersBlock.new
  151 + block.expects(:owner).returns(owner).at_least_once
  152 +
  153 + assert_equal 1, block.profile_count
  154 + end
  155 +
  156 + protected
  157 + include NoosferoTestHelper
  158 +
  159 +end
plugins/people_block/test/unit/people_block_plugin_test.rb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class PeopleBlockPluginTest < ActiveSupport::TestCase
  4 +
  5 + should "return PeopleBlock in extra_blocks class method" do
  6 + assert PeopleBlockPlugin.extra_blocks.keys.include?(PeopleBlock)
  7 + end
  8 +
  9 + should "return MembersBlock in extra_blocks class method" do
  10 + assert PeopleBlockPlugin.extra_blocks.keys.include?(MembersBlock)
  11 + end
  12 +
  13 + should "return FriendsBlock in extra_blocks class method" do
  14 + assert PeopleBlockPlugin.extra_blocks.keys.include?(FriendsBlock)
  15 + end
  16 +
  17 + should "return false for class method has_admin_url?" do
  18 + assert !PeopleBlockPlugin.has_admin_url?
  19 + end
  20 +
  21 + should "return false for class method stylesheet?" do
  22 + assert PeopleBlockPlugin.new.stylesheet?
  23 + end
  24 +
  25 +end
plugins/people_block/test/unit/people_block_test.rb 0 → 100644
@@ -0,0 +1,145 @@ @@ -0,0 +1,145 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class PeopleBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from Block' do
  6 + assert_kind_of Block, PeopleBlock.new
  7 + end
  8 +
  9 +
  10 + should 'declare its default title' do
  11 + assert_not_equal Block.new.default_title, PeopleBlock.new.default_title
  12 + end
  13 +
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal Block.description, PeopleBlock.description
  17 + end
  18 +
  19 +
  20 + should 'is editable' do
  21 + block = PeopleBlock.new
  22 + assert block.editable?
  23 + end
  24 +
  25 +
  26 + should 'have field limit' do
  27 + block = PeopleBlock.new
  28 + assert_respond_to block, :limit
  29 + end
  30 +
  31 +
  32 + should 'default value of limit' do
  33 + block = PeopleBlock.new
  34 + assert_equal 6, block.limit
  35 + end
  36 +
  37 +
  38 + should 'have field name' do
  39 + block = PeopleBlock.new
  40 + assert_respond_to block, :name
  41 + end
  42 +
  43 +
  44 + should 'default value of name' do
  45 + block = PeopleBlock.new
  46 + assert_equal "", block.name
  47 + end
  48 +
  49 +
  50 + should 'have field address' do
  51 + block = PeopleBlock.new
  52 + assert_respond_to block, :address
  53 + end
  54 +
  55 +
  56 + should 'default value of address' do
  57 + block = PeopleBlock.new
  58 + assert_equal "", block.address
  59 + end
  60 +
  61 +
  62 + should 'prioritize profiles with image by default' do
  63 + assert PeopleBlock.new.prioritize_people_with_image
  64 + end
  65 +
  66 +
  67 + should 'respect limit when listing people' do
  68 + env = fast_create(Environment)
  69 + p1 = fast_create(Person, :environment_id => env.id)
  70 + p2 = fast_create(Person, :environment_id => env.id)
  71 + p3 = fast_create(Person, :environment_id => env.id)
  72 + p4 = fast_create(Person, :environment_id => env.id)
  73 +
  74 + block = PeopleBlock.new(:limit => 3)
  75 + block.stubs(:owner).returns(env)
  76 +
  77 + assert_equal 3, block.profile_list.size
  78 + end
  79 +
  80 +
  81 + should 'accept a limit of people to be displayed' do
  82 + block = PeopleBlock.new
  83 + block.limit = 20
  84 + assert_equal 20, block.limit
  85 + end
  86 +
  87 +
  88 + should 'list people from environment' do
  89 + owner = fast_create(Environment)
  90 + person1 = fast_create(Person, :environment_id => owner.id)
  91 + person2 = fast_create(Person, :environment_id => owner.id)
  92 +
  93 + block = PeopleBlock.new
  94 +
  95 + block.expects(:owner).returns(owner).at_least_once
  96 + expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  97 + expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  98 + expects(:block_title).with(anything).returns('')
  99 +
  100 + content = instance_eval(&block.content)
  101 +
  102 + assert_match(/#{person1.name}/, content)
  103 + assert_match(/#{person2.name}/, content)
  104 + end
  105 +
  106 +
  107 + should 'link to "all people"' do
  108 + env = fast_create(Environment)
  109 +
  110 + block = PeopleBlock.new
  111 +
  112 + expects(:_).with('View all').returns('View all')
  113 + expects(:link_to).with('View all', :controller => 'search', :action => 'people').returns('link-to-people')
  114 +
  115 + assert_equal 'link-to-people', instance_eval(&block.footer)
  116 + end
  117 +
  118 +
  119 + should 'count number of public and private people' do
  120 + owner = fast_create(Environment)
  121 + private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id)
  122 + public_p = fast_create(Person, :public_profile => true, :environment_id => owner.id)
  123 +
  124 + block = PeopleBlock.new
  125 + block.expects(:owner).returns(owner).at_least_once
  126 +
  127 + assert_equal 2, block.profile_count
  128 + end
  129 +
  130 +
  131 + should 'not count number of invisible people' do
  132 + owner = fast_create(Environment)
  133 + private_p = fast_create(Person, :visible => false, :environment_id => owner.id)
  134 + public_p = fast_create(Person, :visible => true, :environment_id => owner.id)
  135 +
  136 + block = PeopleBlock.new
  137 + block.expects(:owner).returns(owner).at_least_once
  138 +
  139 + assert_equal 1, block.profile_count
  140 + end
  141 +
  142 + protected
  143 + include NoosferoTestHelper
  144 +
  145 +end
plugins/people_block/views/box_organizer/_friends_block.rhtml 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../people_block_plugin.rhtml
0 \ No newline at end of file 2 \ No newline at end of file
plugins/people_block/views/box_organizer/_members_block.rhtml 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../people_block_plugin.rhtml
0 \ No newline at end of file 2 \ No newline at end of file
plugins/people_block/views/box_organizer/_people_block.rhtml 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../people_block_plugin.rhtml
0 \ No newline at end of file 2 \ No newline at end of file
plugins/people_block/views/environment_design 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +box_organizer
0 \ No newline at end of file 2 \ No newline at end of file
plugins/people_block/views/people_block_plugin.rhtml 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +<div id="people_block_plugin">
  2 +
  3 + <p>
  4 + <span>Limit</span>
  5 + <br />
  6 + <%= text_field_tag 'block[limit]', @block.limit, :maxlength => 2 %>
  7 + </p>
  8 +
  9 + <p>
  10 + <span>Name</span>
  11 + <br />
  12 + <%= text_field_tag 'block[name]', @block.name %>
  13 + </p>
  14 +
  15 + <p>
  16 + <span>Address</span>
  17 + <br />
  18 + <%= text_field_tag 'block[address]', @block.address %>
  19 + </p>
  20 +
  21 +</div>
plugins/people_block/views/profile_design 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +box_organizer
0 \ No newline at end of file 2 \ No newline at end of file
test/functional/environment_design_controller_test.rb
@@ -6,7 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end @@ -6,7 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end
6 6
7 class EnvironmentDesignControllerTest < ActionController::TestCase 7 class EnvironmentDesignControllerTest < ActionController::TestCase
8 8
9 - ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] 9 + ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ]
10 10
11 def setup 11 def setup
12 @controller = EnvironmentDesignController.new 12 @controller = EnvironmentDesignController.new
@@ -103,16 +103,6 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase @@ -103,16 +103,6 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
103 assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } 103 assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
104 end 104 end
105 105
106 - should 'be able to edit PeopleBlock' do  
107 - login_as(create_admin_user(Environment.default))  
108 - b = PeopleBlock.create!  
109 - e = Environment.default  
110 - e.boxes.create!  
111 - e.boxes.first.blocks << b  
112 - get :edit, :id => b.id  
113 - assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }  
114 - end  
115 -  
116 should 'be able to edit SlideshowBlock' do 106 should 'be able to edit SlideshowBlock' do
117 login_as(create_admin_user(Environment.default)) 107 login_as(create_admin_user(Environment.default))
118 b = SlideshowBlock.create! 108 b = SlideshowBlock.create!
test/functional/profile_design_controller_test.rb
@@ -6,8 +6,7 @@ class ProfileDesignController; def rescue_action(e) raise e end; end @@ -6,8 +6,7 @@ class ProfileDesignController; def rescue_action(e) raise e end; end
6 class ProfileDesignControllerTest < ActionController::TestCase 6 class ProfileDesignControllerTest < ActionController::TestCase
7 7
8 COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] 8 COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ]
9 - PERSON_BLOCKS = COMMOM_BLOCKS + [FriendsBlock, FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ]  
10 - PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] 9 + PERSON_BLOCKS = COMMOM_BLOCKS + [ FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ]
11 PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] 10 PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock]
12 11
13 ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, FeaturedProductsBlock, FansBlock] 12 ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, FeaturedProductsBlock, FansBlock]
@@ -485,23 +484,6 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -485,23 +484,6 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
485 assert_equal PERSON_BLOCKS, @controller.available_blocks 484 assert_equal PERSON_BLOCKS, @controller.available_blocks
486 end 485 end
487 486
488 - should 'the person with members blocks are all available' do  
489 - profile = mock  
490 - profile.stubs(:has_members?).returns(true)  
491 - profile.stubs(:person?).returns(true)  
492 - profile.stubs(:community?).returns(true)  
493 - profile.stubs(:enterprise?).returns(false)  
494 - profile.stubs(:has_blog?).returns(false)  
495 - profile.stubs(:is_admin?).with(anything).returns(false)  
496 - environment = mock  
497 - profile.stubs(:environment).returns(environment)  
498 - environment.stubs(:enabled?).returns(false)  
499 - @controller.stubs(:profile).returns(profile)  
500 - @controller.stubs(:user).returns(profile)  
501 - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])  
502 - assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS  
503 - end  
504 -  
505 should 'the person with blog blocks are all available' do 487 should 'the person with blog blocks are all available' do
506 profile = mock 488 profile = mock
507 profile.stubs(:has_members?).returns(false) 489 profile.stubs(:has_members?).returns(false)
test/unit/box_test.rb
@@ -32,14 +32,11 @@ class BoxTest &lt; ActiveSupport::TestCase @@ -32,14 +32,11 @@ class BoxTest &lt; ActiveSupport::TestCase
32 assert blocks.include?('fans-block') 32 assert blocks.include?('fans-block')
33 assert blocks.include?('favorite-enterprises-block') 33 assert blocks.include?('favorite-enterprises-block')
34 assert blocks.include?('feed-reader-block') 34 assert blocks.include?('feed-reader-block')
35 - assert blocks.include?('friends-block')  
36 assert blocks.include?('highlights-block') 35 assert blocks.include?('highlights-block')
37 assert blocks.include?('link-list-block') 36 assert blocks.include?('link-list-block')
38 assert blocks.include?('login-block') 37 assert blocks.include?('login-block')
39 assert blocks.include?('main-block') 38 assert blocks.include?('main-block')
40 - assert blocks.include?('members-block')  
41 assert blocks.include?('my-network-block') 39 assert blocks.include?('my-network-block')
42 - assert blocks.include?('people-block')  
43 assert blocks.include?('profile-image-block') 40 assert blocks.include?('profile-image-block')
44 assert blocks.include?('raw-html-block') 41 assert blocks.include?('raw-html-block')
45 assert blocks.include?('recent-documents-block') 42 assert blocks.include?('recent-documents-block')
@@ -65,14 +62,11 @@ class BoxTest &lt; ActiveSupport::TestCase @@ -65,14 +62,11 @@ class BoxTest &lt; ActiveSupport::TestCase
65 assert blocks.include?('favorite-enterprises-block') 62 assert blocks.include?('favorite-enterprises-block')
66 assert blocks.include?('featured-products-block') 63 assert blocks.include?('featured-products-block')
67 assert blocks.include?('feed-reader-block') 64 assert blocks.include?('feed-reader-block')
68 - assert blocks.include?('friends-block')  
69 assert blocks.include?('highlights-block') 65 assert blocks.include?('highlights-block')
70 assert blocks.include?('link-list-block') 66 assert blocks.include?('link-list-block')
71 assert blocks.include?('location-block') 67 assert blocks.include?('location-block')
72 assert blocks.include?('login-block') 68 assert blocks.include?('login-block')
73 - assert blocks.include?('members-block')  
74 assert blocks.include?('my-network-block') 69 assert blocks.include?('my-network-block')
75 - assert blocks.include?('people-block')  
76 assert blocks.include?('products-block') 70 assert blocks.include?('products-block')
77 assert blocks.include?('profile-image-block') 71 assert blocks.include?('profile-image-block')
78 assert blocks.include?('profile-info-block') 72 assert blocks.include?('profile-info-block')
test/unit/friends_block_test.rb
@@ -1,86 +0,0 @@ @@ -1,86 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class FriendsBlockTest < ActiveSupport::TestCase  
4 -  
5 - should 'describe itself' do  
6 - assert_not_equal ProfileListBlock.description, FriendsBlock.description  
7 - end  
8 -  
9 - should 'declare its default title' do  
10 - FriendsBlock.any_instance.stubs(:profile_count).returns(0)  
11 - assert_not_equal ProfileListBlock.new.default_title, FriendsBlock.new.default_title  
12 - end  
13 -  
14 - should 'list owner friends' do  
15 - p1 = create_user('testuser1').person  
16 - p2 = create_user('testuser2').person  
17 - p3 = create_user('testuser3').person  
18 - p4 = create_user('testuser4').person  
19 -  
20 - p1.add_friend(p2)  
21 - p1.add_friend(p3)  
22 - p1.add_friend(p4)  
23 - p1.friends.reload  
24 -  
25 - block = FriendsBlock.new  
26 - block.expects(:owner).returns(p1)  
27 -  
28 - assert_equivalent [p2, p3, p4], block.profiles  
29 - end  
30 -  
31 - should 'point to list with all friends' do  
32 - block = FriendsBlock.new  
33 - user = mock  
34 - user.expects(:identifier).returns('theuser')  
35 - block.expects(:owner).returns(user)  
36 -  
37 - expects(:link_to).with('View all', :profile => 'theuser', :controller => 'profile', :action => 'friends')  
38 -  
39 - instance_eval(&block.footer)  
40 - end  
41 -  
42 - should 'count number of owner friends' do  
43 - p1 = create_user('testuser1').person  
44 - p2 = create_user('testuser2').person  
45 - p3 = create_user('testuser3').person  
46 - p4 = create_user('testuser4').person  
47 -  
48 - p1.add_friend(p2)  
49 - p1.add_friend(p3)  
50 - p1.add_friend(p4)  
51 -  
52 - block = FriendsBlock.new  
53 - block.expects(:owner).returns(p1)  
54 -  
55 - assert_equal 3, block.profile_count  
56 - end  
57 -  
58 - should 'count number of public and private people' do  
59 - owner = create_user('testuser1').person  
60 - private_p = fast_create(Person, {:public_profile => false})  
61 - public_p = fast_create(Person, {:public_profile => true})  
62 -  
63 - owner.add_friend(private_p)  
64 - owner.add_friend(public_p)  
65 -  
66 - block = FriendsBlock.new  
67 - block.expects(:owner).returns(owner)  
68 -  
69 - assert_equal 2, block.profile_count  
70 - end  
71 -  
72 - should 'not count number of invisible people' do  
73 - owner = create_user('testuser1').person  
74 - private_p = fast_create(Person, {:visible => false})  
75 - public_p = fast_create(Person, {:visible => true})  
76 -  
77 - owner.add_friend(private_p)  
78 - owner.add_friend(public_p)  
79 -  
80 - block = FriendsBlock.new  
81 - block.expects(:owner).returns(owner)  
82 -  
83 - assert_equal 1, block.profile_count  
84 - end  
85 -  
86 -end  
test/unit/members_block_test.rb
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class MembersBlockTest < ActiveSupport::TestCase  
4 -  
5 - should 'inherit from ProfileListBlock' do  
6 - assert_kind_of ProfileListBlock, MembersBlock.new  
7 - end  
8 -  
9 - should 'describe itself' do  
10 - assert_not_equal ProfileListBlock.description, MembersBlock.description  
11 - end  
12 -  
13 - should 'provide a default title' do  
14 - assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title  
15 - end  
16 -  
17 - should 'link to "all members" page' do  
18 - profile = create_user('mytestuser').person  
19 - block = MembersBlock.new  
20 - block.box = profile.boxes.first  
21 - block.save!  
22 -  
23 - expects(:_).with('View all').returns('View all')  
24 - expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'profile', :action => 'members').returns('link-to-members')  
25 -  
26 - assert_equal 'link-to-members', instance_eval(&block.footer)  
27 - end  
28 -  
29 - should 'pick random members' do  
30 - block = MembersBlock.new  
31 -  
32 - owner = mock  
33 - block.expects(:owner).returns(owner)  
34 -  
35 - list = []  
36 - owner.expects(:members).returns(list)  
37 -  
38 - assert_same list, block.profiles  
39 - end  
40 -  
41 -end  
42 -  
test/unit/people_block_test.rb
@@ -1,50 +0,0 @@ @@ -1,50 +0,0 @@
1 -require File.dirname(__FILE__) + '/../test_helper'  
2 -  
3 -class PeopleBlockTest < ActiveSupport::TestCase  
4 -  
5 - should 'inherit from ProfileListBlock' do  
6 - assert_kind_of ProfileListBlock, PeopleBlock.new  
7 - end  
8 -  
9 - should 'declare its default title' do  
10 - assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title  
11 - end  
12 -  
13 - should 'describe itself' do  
14 - assert_not_equal ProfileListBlock.description, PeopleBlock.description  
15 - end  
16 -  
17 - should 'give help' do  
18 - assert_not_equal ProfileListBlock.new.help, PeopleBlock.new.help  
19 - end  
20 -  
21 - should 'list people' do  
22 - owner = fast_create(Environment)  
23 - block = PeopleBlock.new  
24 - block.expects(:owner).returns(owner).at_least_once  
25 - person1 = fast_create(Person, :environment_id => owner.id)  
26 - person2 = fast_create(Person, :environment_id => owner.id)  
27 -  
28 - expects(:profile_image_link).with(person1, :minor).returns(person1.name)  
29 - expects(:profile_image_link).with(person2, :minor).returns(person2.name)  
30 - expects(:block_title).with(anything).returns('')  
31 -  
32 - content = instance_eval(&block.content)  
33 -  
34 - assert_match(/#{person1.name}/, content)  
35 - assert_match(/#{person2.name}/, content)  
36 - end  
37 -  
38 - should 'link to browse people' do  
39 - block = PeopleBlock.new  
40 - block.stubs(:owner).returns(Environment.default)  
41 -  
42 - expects(:_).with('View all').returns('View all people')  
43 - expects(:link_to).with('View all people', :controller => 'search', :action => 'people')  
44 - instance_eval(&block.footer)  
45 - end  
46 -  
47 - protected  
48 - include NoosferoTestHelper  
49 -  
50 -end