diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index c310a67..9007fda 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController protect 'edit_environment_design', :environment def available_blocks - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) end diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 5ee727a..96cefc4 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -9,14 +9,8 @@ class ProfileDesignController < BoxOrganizerController blocks += plugins.dispatch(:extra_blocks) - # blocks exclusive for organizations - if profile.has_members? - blocks << MembersBlock - end - # blocks exclusive to people if profile.person? - blocks << FriendsBlock blocks << FavoriteEnterprisesBlock blocks << CommunitiesBlock blocks << EnterprisesBlock diff --git a/app/helpers/sweeper_helper.rb b/app/helpers/sweeper_helper.rb index 01db9bd..bb4a6a4 100644 --- a/app/helpers/sweeper_helper.rb +++ b/app/helpers/sweeper_helper.rb @@ -18,9 +18,7 @@ module SweeperHelper expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) end - # friends blocks - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} - BlockSweeper.expire_blocks(blocks) + expire_blocks_cache(profile, [:profile]) end def expire_communities(profile) diff --git a/app/models/box.rb b/app/models/box.rb index f8022a7..4f0d11a 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -25,14 +25,11 @@ class Box < ActiveRecord::Base FansBlock, FavoriteEnterprisesBlock, FeedReaderBlock, - FriendsBlock, HighlightsBlock, LinkListBlock, LoginBlock, MainBlock, - MembersBlock, MyNetworkBlock, - PeopleBlock, ProfileImageBlock, RawHTMLBlock, RecentDocumentsBlock, @@ -52,14 +49,11 @@ class Box < ActiveRecord::Base FavoriteEnterprisesBlock, FeaturedProductsBlock, FeedReaderBlock, - FriendsBlock, HighlightsBlock, LinkListBlock, LocationBlock, LoginBlock, - MembersBlock, MyNetworkBlock, - PeopleBlock, ProductsBlock, ProfileImageBlock, ProfileInfoBlock, diff --git a/app/models/community.rb b/app/models/community.rb index 53671ec..adcffbd 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -73,7 +73,7 @@ class Community < Organization end def blocks_to_expire_cache - [MembersBlock] + [] end def each_member(offset=0) diff --git a/app/models/environment.rb b/app/models/environment.rb index 9bf013f..17ee267 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -165,7 +165,6 @@ class Environment < ActiveRecord::Base # "right" area env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6) - env.boxes[2].blocks << PeopleBlock.new(:limit => 6) end # One Environment can be reached by many domains diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb deleted file mode 100644 index 4fbde10..0000000 --- a/app/models/friends_block.rb +++ /dev/null @@ -1,26 +0,0 @@ -class FriendsBlock < ProfileListBlock - - def self.description - __('Friends') - end - - def default_title - n__('{#} friend', '{#} friends', profile_count) - end - - def help - _('This block displays your friends.') - end - - def footer - owner_id = owner.identifier - lambda do - link_to s_('friends|View all'), :profile => owner_id, :controller => 'profile', :action => 'friends' - end - end - - def profiles - owner.friends - end - -end diff --git a/app/models/members_block.rb b/app/models/members_block.rb deleted file mode 100644 index f13dfc0..0000000 --- a/app/models/members_block.rb +++ /dev/null @@ -1,26 +0,0 @@ -class MembersBlock < ProfileListBlock - - def self.description - _('Members') - end - - def default_title - _('{#} members') - end - - def help - _('This block presents the members of a collective.') - end - - def footer - profile = self.owner - lambda do - link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' - end - end - - def profiles - owner.members - end - -end diff --git a/app/models/organization.rb b/app/models/organization.rb index b00f295..294cc7d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -130,7 +130,7 @@ class Organization < Profile [ [MainBlock.new], [ProfileImageBlock.new, LinkListBlock.new(:links => links)], - [MembersBlock.new, RecentDocumentsBlock.new] + [RecentDocumentsBlock.new] ] end diff --git a/app/models/people_block.rb b/app/models/people_block.rb deleted file mode 100644 index 3b6e60a..0000000 --- a/app/models/people_block.rb +++ /dev/null @@ -1,25 +0,0 @@ -class PeopleBlock < ProfileListBlock - - def default_title - _('People') - end - - def help - _('Clicking a person takes you to his/her homepage') - end - - def self.description - _('Random people') - end - - def profiles - owner.people - end - - def footer - lambda do - link_to _('View all'), :controller => 'search', :action => 'people' - end - end - -end diff --git a/app/models/person.rb b/app/models/person.rb index 8358188..d763976 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -276,7 +276,7 @@ class Person < Profile [ [MainBlock.new], [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new], - [FriendsBlock.new, CommunitiesBlock.new] + [CommunitiesBlock.new] ] end diff --git a/app/sweepers/friendship_sweeper.rb b/app/sweepers/friendship_sweeper.rb index 400dc4e..f46b405 100644 --- a/app/sweepers/friendship_sweeper.rb +++ b/app/sweepers/friendship_sweeper.rb @@ -34,8 +34,7 @@ protected expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) end - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} - BlockSweeper.expire_blocks(blocks) + expire_blocks_cache(profile, [:profile]) end end diff --git a/plugins/people_block/lib/friends_block.rb b/plugins/people_block/lib/friends_block.rb new file mode 100644 index 0000000..d9514bd --- /dev/null +++ b/plugins/people_block/lib/friends_block.rb @@ -0,0 +1,31 @@ +class FriendsBlock < PeopleBlockBase + + def self.description + _('Friends') + end + + def help + _('Clicking a friend takes you to his/her homepage') + end + + def default_title + _('{#} Friends') + end + + def profiles + owner.friends + end + + def footer + owner = self.owner + lambda do + link_to _('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'friends' + end + end + + def self.expire_on + { :profile => [:profile] } + end + +end + diff --git a/plugins/people_block/lib/members_block.rb b/plugins/people_block/lib/members_block.rb new file mode 100644 index 0000000..7fc33b2 --- /dev/null +++ b/plugins/people_block/lib/members_block.rb @@ -0,0 +1,27 @@ +class MembersBlock < PeopleBlockBase + + def self.description + _('Members') + end + + def help + _('Clicking a member takes you to his/her homepage') + end + + def default_title + _('{#} Members') + end + + def profiles + owner.members + end + + def footer + owner = self.owner + lambda do + link_to _('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'members' + end + end + +end + diff --git a/plugins/people_block/lib/people_block.rb b/plugins/people_block/lib/people_block.rb new file mode 100644 index 0000000..a31475c --- /dev/null +++ b/plugins/people_block/lib/people_block.rb @@ -0,0 +1,25 @@ +class PeopleBlock < PeopleBlockBase + + def self.description + _('People') + end + + def help + _('Clicking a person takes you to his/her homepage') + end + + def default_title + _('{#} People') + end + + def profiles + owner.people + end + + def footer + lambda do + link_to _('View all'), :controller => 'search', :action => 'people' + end + end + +end diff --git a/plugins/people_block/lib/people_block_base.rb b/plugins/people_block/lib/people_block_base.rb new file mode 100644 index 0000000..18cc2b8 --- /dev/null +++ b/plugins/people_block/lib/people_block_base.rb @@ -0,0 +1,98 @@ +class PeopleBlockBase < Block + + settings_items :prioritize_people_with_image, :type => :boolean, :default => true + settings_items :limit, :type => :integer, :default => 6 + settings_items :name, :type => String, :default => "" + settings_items :address, :type => String, :default => "" + + def self.description + _('Random people') + end + + def help + _('Clicking on the people or groups will take you to their home page.') + end + + def default_title + _('{#} People') + end + + def view_title + title.gsub('{#}', profile_count.to_s) + end + + def profiles + owner.profiles + end + + def profile_list + result = nil + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) + if !prioritize_people_with_image + result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand } + elsif visible_profiles.with_image.count >= limit + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + else + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + end + result.slice(0..limit-1) + end + + def profile_count + profiles.visible.count + end + + def content(args={}) + + profiles = self.profile_list + title = self.view_title + + if !self.name.blank? && !self.address.blank? + name = self.name + expanded_address = expand_address(self.address) + end + + lambda do + count = 0 + list = profiles.map {|item| + count += 1 + send(:profile_image_link, item, :minor ) + }.join("\n") + if list.empty? + list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none' + else + if !name.blank? && !expanded_address.blank? + list << content_tag( + 'div', + content_tag( + 'li', + content_tag( + 'div', + link_to( + content_tag('span', name, :class => 'banner-span' ), + expanded_address, + :title => name + ), + :class => 'banner-div' + ), + :class => 'vcard' + ), + :class => 'common-profile-list-block' + ) + end + list = content_tag 'ul', list + end + block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both')) + end + end + + def expand_address(address) + if address !~ /^[a-z]+:\/\// && address !~ /^\// + 'http://' + address + else + address + end + end + +end + diff --git a/plugins/people_block/lib/people_block_plugin.rb b/plugins/people_block/lib/people_block_plugin.rb new file mode 100644 index 0000000..21c68f3 --- /dev/null +++ b/plugins/people_block/lib/people_block_plugin.rb @@ -0,0 +1,27 @@ +class PeopleBlockPlugin < Noosfero::Plugin + + def self.plugin_name + "People Block Plugin" + end + + def self.plugin_description + _("A plugin that adds a people block") + end + + def self.extra_blocks + { + PeopleBlock => {:type => Environment}, + MembersBlock => {:type => Community}, + FriendsBlock => {:type => Person} + } + end + + def self.has_admin_url? + false + end + + def stylesheet? + true + end + +end diff --git a/plugins/people_block/public/style.css b/plugins/people_block/public/style.css new file mode 100644 index 0000000..88ecedd --- /dev/null +++ b/plugins/people_block/public/style.css @@ -0,0 +1,59 @@ +/******************************************************************* + * COMMON * + *******************************************************************/ +.people-block .block-footer-content a { + position: absolute; + top: 2px; + right: 0px; + font-size: 11px; + color: #000; + text-decoration: none; + padding-right: 15px; + background: url(/designs/themes/base/imgs/arrow-right-p.png) 100% 50% no-repeat; +} + +.people-block .banner-span { + color: #000; + font-size: 14pt; + font-weight: bold; + background-color: #EEE; +} + + +/******************************************************************* + * MAIN BOX - 1 * + *******************************************************************/ +.box-1 .people-block .banner-div { + line-height: 112px; +} + +.box-1 .people-block .banner-span { + width: 204px; +} + + +/******************************************************************* + * LEFT/RIGHT BOXES * + *******************************************************************/ +.box-2 .people-block .banner-div, +.box-3 .people-block .banner-div { + line-height: 78px; +} + +.box-2 .people-block .banner-div a, +.box-3 .people-block .banner-div a { + height: 78px; +} + +.box-2 .people-block .banner-span, +.box-3 .people-block .banner-span { + width: 116px; +} + +.box-2 .people-block ul, +.box-3 .people-block ul { + min-width: 196px; + width: 192px; + margin: 0px 0px 0px -3px; + padding: 0px; +} diff --git a/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb b/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb new file mode 100644 index 0000000..aa212c1 --- /dev/null +++ b/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class EnvironmentDesignController; def rescue_action(e) raise e end; end + +class EnvironmentDesignControllerTest < ActionController::TestCase + + def setup + @controller = EnvironmentDesignController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) + end + + #attr_accessor :environment, :block + + #should 'display *block people-block* class at design blocks page' do + #get :index + #assert_tag :div, :attributes => {:class => 'block people-block'} + #end + + should 'be able to edit PeopleBlock' do + login_as(create_admin_user(Environment.default)) + b = PeopleBlock.create! + e = Environment.default + e.boxes.create! + e.boxes.first.blocks << b + get :edit, :id => b.id + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } + end + +end diff --git a/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb b/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb new file mode 100644 index 0000000..b92d580 --- /dev/null +++ b/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb @@ -0,0 +1,70 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class ProfileDesignController; def rescue_action(e) raise e end; end + +class ProfileDesignControllerTest < ActionController::TestCase + + def setup + @controller = ProfileDesignController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) + end + + should 'display *block people-block* class at design blocks page' do + user = create_user('testinguser') + login_as(user.login) + + @profile = user.person + @environment = @profile.environment + @environment.save! + + FriendsBlock.delete_all + @box1 = Box.create!(:owner => @profile) + @profile.boxes = [@box1] + + @block = FriendsBlock.new + @block.box = @box1 + @block.save! + + @profile.blocks<<@block + @profile.save! + + get :index, :profile => @profile.identifier + assert_tag :div, :attributes => {:class => 'block friends-block'} + end + + should 'the people block is available for person profile' do + profile = mock + profile.stubs(:has_members?).returns(false) + profile.stubs(:person?).returns(true) + profile.stubs(:community?).returns(false) + profile.stubs(:enterprise?).returns(false) + profile.stubs(:has_blog?).returns(false) + profile.stubs(:is_admin?).with(anything).returns(false) + environment = mock + profile.stubs(:environment).returns(environment) + environment.stubs(:enabled?).returns(false) + @controller.stubs(:profile).returns(profile) + @controller.stubs(:user).returns(profile) + assert_includes @controller.available_blocks, FriendsBlock + end + + should 'the people block is available for community profile' do + profile = mock + profile.stubs(:has_members?).returns(true) + profile.stubs(:person?).returns(false) + profile.stubs(:community?).returns(true) + profile.stubs(:enterprise?).returns(false) + profile.stubs(:has_blog?).returns(false) + profile.stubs(:is_admin?).with(anything).returns(false) + environment = mock + profile.stubs(:environment).returns(environment) + environment.stubs(:enabled?).returns(false) + @controller.stubs(:profile).returns(profile) + @controller.stubs(:user).returns(profile) + assert_includes @controller.available_blocks, MembersBlock + end + +end diff --git a/plugins/people_block/test/test_helper.rb b/plugins/people_block/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/people_block/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/people_block/test/unit/friends_block_test.rb b/plugins/people_block/test/unit/friends_block_test.rb new file mode 100644 index 0000000..0e19ae7 --- /dev/null +++ b/plugins/people_block/test/unit/friends_block_test.rb @@ -0,0 +1,156 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FriendsBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, FriendsBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, FriendsBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, FriendsBlock.description + end + + + should 'is editable' do + block = FriendsBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = FriendsBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = FriendsBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = FriendsBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = FriendsBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = FriendsBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = FriendsBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert FriendsBlock.new.prioritize_people_with_image + end + + + should 'accept a limit of people to be displayed' do + block = FriendsBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list friends from person' do + owner = fast_create(Person) + friend1 = fast_create(Person) + friend2 = fast_create(Person) + owner.add_friend(friend1) + owner.add_friend(friend2) + + block = FriendsBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) + expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) + expects(:block_title).with(anything).returns('') + + content = instance_eval(&block.content) + + assert_match(/#{friend1.name}/, content) + assert_match(/#{friend2.name}/, content) + end + + + should 'link to "all friends"' do + person1 = create_user('mytestperson').person + + block = FriendsBlock.new + block.expects(:owner).returns(person1).at_least_once + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all', :profile => 'mytestperson', :controller => 'profile', :action => 'friends').returns('link-to-friends') + + assert_equal 'link-to-friends', instance_eval(&block.footer) + end + + + should 'count number of owner friends' do + owner = fast_create(Person) + friend1 = fast_create(Person) + friend2 = fast_create(Person) + friend3 = fast_create(Person) + owner.add_friend(friend1) + owner.add_friend(friend2) + owner.add_friend(friend3) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 3, block.profile_count + end + + + should 'count number of public and private friends' do + owner = fast_create(Person) + private_p = fast_create(Person, {:public_profile => false}) + public_p = fast_create(Person, {:public_profile => true}) + + owner.add_friend(private_p) + owner.add_friend(public_p) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible friends' do + owner = fast_create(Person) + private_p = fast_create(Person, {:visible => false}) + public_p = fast_create(Person, {:visible => true}) + + owner.add_friend(private_p) + owner.add_friend(public_p) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/test/unit/members_block_test.rb b/plugins/people_block/test/unit/members_block_test.rb new file mode 100644 index 0000000..24689f1 --- /dev/null +++ b/plugins/people_block/test/unit/members_block_test.rb @@ -0,0 +1,159 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class MembersBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, MembersBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, MembersBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, MembersBlock.description + end + + + should 'is editable' do + block = MembersBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = MembersBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = MembersBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = MembersBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = MembersBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = MembersBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = MembersBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert MembersBlock.new.prioritize_people_with_image + end + + + should 'respect limit when listing members' do + community = fast_create(Community) + p1 = fast_create(Person) + p2 = fast_create(Person) + p3 = fast_create(Person) + p4 = fast_create(Person) + + community.add_member(p1) + community.add_member(p2) + community.add_member(p3) + community.add_member(p4) + + block = MembersBlock.new(:limit => 3) + block.stubs(:owner).returns(community) + + assert_equal 3, block.profile_list.size + end + + + should 'accept a limit of members to be displayed' do + block = MembersBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list members from community' do + owner = fast_create(Community) + person1 = fast_create(Person) + person2 = fast_create(Person) + owner.add_member(person1) + owner.add_member(person2) + + block = MembersBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(person1, :minor).returns(person1.name) + expects(:profile_image_link).with(person2, :minor).returns(person2.name) + expects(:block_title).with(anything).returns('') + + content = instance_eval(&block.content) + + assert_match(/#{person1.name}/, content) + assert_match(/#{person2.name}/, content) + end + + + should 'link to "all members"' do + community = fast_create(Community) + + block = MembersBlock.new + block.expects(:owner).returns(community).at_least_once + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all', :profile => community.identifier, :controller => 'profile', :action => 'members').returns('link-to-members') + + assert_equal 'link-to-members', instance_eval(&block.footer) + end + + + should 'count number of public and private members' do + owner = fast_create(Community) + private_p = fast_create(Person, {:public_profile => false}) + public_p = fast_create(Person, {:public_profile => true}) + + owner.add_member(private_p) + owner.add_member(public_p) + + block = MembersBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible members' do + owner = fast_create(Community) + private_p = fast_create(Person, {:visible => false}) + public_p = fast_create(Person, {:visible => true}) + + owner.add_member(private_p) + owner.add_member(public_p) + + block = MembersBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/test/unit/people_block_plugin_test.rb b/plugins/people_block/test/unit/people_block_plugin_test.rb new file mode 100644 index 0000000..1c84109 --- /dev/null +++ b/plugins/people_block/test/unit/people_block_plugin_test.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleBlockPluginTest < ActiveSupport::TestCase + + should "return PeopleBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(PeopleBlock) + end + + should "return MembersBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(MembersBlock) + end + + should "return FriendsBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(FriendsBlock) + end + + should "return false for class method has_admin_url?" do + assert !PeopleBlockPlugin.has_admin_url? + end + + should "return false for class method stylesheet?" do + assert PeopleBlockPlugin.new.stylesheet? + end + +end diff --git a/plugins/people_block/test/unit/people_block_test.rb b/plugins/people_block/test/unit/people_block_test.rb new file mode 100644 index 0000000..93e4989 --- /dev/null +++ b/plugins/people_block/test/unit/people_block_test.rb @@ -0,0 +1,145 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, PeopleBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, PeopleBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, PeopleBlock.description + end + + + should 'is editable' do + block = PeopleBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = PeopleBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = PeopleBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = PeopleBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = PeopleBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = PeopleBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = PeopleBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert PeopleBlock.new.prioritize_people_with_image + end + + + should 'respect limit when listing people' do + env = fast_create(Environment) + p1 = fast_create(Person, :environment_id => env.id) + p2 = fast_create(Person, :environment_id => env.id) + p3 = fast_create(Person, :environment_id => env.id) + p4 = fast_create(Person, :environment_id => env.id) + + block = PeopleBlock.new(:limit => 3) + block.stubs(:owner).returns(env) + + assert_equal 3, block.profile_list.size + end + + + should 'accept a limit of people to be displayed' do + block = PeopleBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list people from environment' do + owner = fast_create(Environment) + person1 = fast_create(Person, :environment_id => owner.id) + person2 = fast_create(Person, :environment_id => owner.id) + + block = PeopleBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(person1, :minor).returns(person1.name) + expects(:profile_image_link).with(person2, :minor).returns(person2.name) + expects(:block_title).with(anything).returns('') + + content = instance_eval(&block.content) + + assert_match(/#{person1.name}/, content) + assert_match(/#{person2.name}/, content) + end + + + should 'link to "all people"' do + env = fast_create(Environment) + + block = PeopleBlock.new + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all', :controller => 'search', :action => 'people').returns('link-to-people') + + assert_equal 'link-to-people', instance_eval(&block.footer) + end + + + should 'count number of public and private people' do + owner = fast_create(Environment) + private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id) + public_p = fast_create(Person, :public_profile => true, :environment_id => owner.id) + + block = PeopleBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible people' do + owner = fast_create(Environment) + private_p = fast_create(Person, :visible => false, :environment_id => owner.id) + public_p = fast_create(Person, :visible => true, :environment_id => owner.id) + + block = PeopleBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/views/box_organizer/_friends_block.rhtml b/plugins/people_block/views/box_organizer/_friends_block.rhtml new file mode 120000 index 0000000..cd647df --- /dev/null +++ b/plugins/people_block/views/box_organizer/_friends_block.rhtml @@ -0,0 +1 @@ +../people_block_plugin.rhtml \ No newline at end of file diff --git a/plugins/people_block/views/box_organizer/_members_block.rhtml b/plugins/people_block/views/box_organizer/_members_block.rhtml new file mode 120000 index 0000000..cd647df --- /dev/null +++ b/plugins/people_block/views/box_organizer/_members_block.rhtml @@ -0,0 +1 @@ +../people_block_plugin.rhtml \ No newline at end of file diff --git a/plugins/people_block/views/box_organizer/_people_block.rhtml b/plugins/people_block/views/box_organizer/_people_block.rhtml new file mode 120000 index 0000000..cd647df --- /dev/null +++ b/plugins/people_block/views/box_organizer/_people_block.rhtml @@ -0,0 +1 @@ +../people_block_plugin.rhtml \ No newline at end of file diff --git a/plugins/people_block/views/environment_design b/plugins/people_block/views/environment_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/people_block/views/environment_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/plugins/people_block/views/people_block_plugin.rhtml b/plugins/people_block/views/people_block_plugin.rhtml new file mode 100644 index 0000000..72cea62 --- /dev/null +++ b/plugins/people_block/views/people_block_plugin.rhtml @@ -0,0 +1,21 @@ +
+ Limit
+
+ <%= text_field_tag 'block[limit]', @block.limit, :maxlength => 2 %>
+
+ Name
+
+ <%= text_field_tag 'block[name]', @block.name %>
+
+ Address
+
+ <%= text_field_tag 'block[address]', @block.address %>
+