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 %> +

+ +
diff --git a/plugins/people_block/views/profile_design b/plugins/people_block/views/profile_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/people_block/views/profile_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index 1c473fe..9e4aebf 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -6,7 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end class EnvironmentDesignControllerTest < ActionController::TestCase - ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] def setup @controller = EnvironmentDesignController.new @@ -103,16 +103,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } 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 - should 'be able to edit SlideshowBlock' do login_as(create_admin_user(Environment.default)) b = SlideshowBlock.create! diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index f0104a5..a4ba52f 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -6,8 +6,7 @@ class ProfileDesignController; def rescue_action(e) raise e end; end class ProfileDesignControllerTest < ActionController::TestCase COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] - PERSON_BLOCKS = COMMOM_BLOCKS + [FriendsBlock, FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ] - PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] + PERSON_BLOCKS = COMMOM_BLOCKS + [ FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ] PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, FeaturedProductsBlock, FansBlock] @@ -485,23 +484,6 @@ class ProfileDesignControllerTest < ActionController::TestCase assert_equal PERSON_BLOCKS, @controller.available_blocks end - should 'the person with members blocks are all available' do - profile = mock - profile.stubs(:has_members?).returns(true) - profile.stubs(:person?).returns(true) - 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) - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) - assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS - end - should 'the person with blog blocks are all available' do profile = mock profile.stubs(:has_members?).returns(false) diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb index d7b1bd7..329632d 100644 --- a/test/unit/box_test.rb +++ b/test/unit/box_test.rb @@ -32,14 +32,11 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('fans-block') assert blocks.include?('favorite-enterprises-block') assert blocks.include?('feed-reader-block') - assert blocks.include?('friends-block') assert blocks.include?('highlights-block') assert blocks.include?('link-list-block') assert blocks.include?('login-block') assert blocks.include?('main-block') - assert blocks.include?('members-block') assert blocks.include?('my-network-block') - assert blocks.include?('people-block') assert blocks.include?('profile-image-block') assert blocks.include?('raw-html-block') assert blocks.include?('recent-documents-block') @@ -65,14 +62,11 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('favorite-enterprises-block') assert blocks.include?('featured-products-block') assert blocks.include?('feed-reader-block') - assert blocks.include?('friends-block') assert blocks.include?('highlights-block') assert blocks.include?('link-list-block') assert blocks.include?('location-block') assert blocks.include?('login-block') - assert blocks.include?('members-block') assert blocks.include?('my-network-block') - assert blocks.include?('people-block') assert blocks.include?('products-block') assert blocks.include?('profile-image-block') assert blocks.include?('profile-info-block') diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb deleted file mode 100644 index 106920a..0000000 --- a/test/unit/friends_block_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class FriendsBlockTest < ActiveSupport::TestCase - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, FriendsBlock.description - end - - should 'declare its default title' do - FriendsBlock.any_instance.stubs(:profile_count).returns(0) - assert_not_equal ProfileListBlock.new.default_title, FriendsBlock.new.default_title - end - - should 'list owner friends' do - p1 = create_user('testuser1').person - p2 = create_user('testuser2').person - p3 = create_user('testuser3').person - p4 = create_user('testuser4').person - - p1.add_friend(p2) - p1.add_friend(p3) - p1.add_friend(p4) - p1.friends.reload - - block = FriendsBlock.new - block.expects(:owner).returns(p1) - - assert_equivalent [p2, p3, p4], block.profiles - end - - should 'point to list with all friends' do - block = FriendsBlock.new - user = mock - user.expects(:identifier).returns('theuser') - block.expects(:owner).returns(user) - - expects(:link_to).with('View all', :profile => 'theuser', :controller => 'profile', :action => 'friends') - - instance_eval(&block.footer) - end - - should 'count number of owner friends' do - p1 = create_user('testuser1').person - p2 = create_user('testuser2').person - p3 = create_user('testuser3').person - p4 = create_user('testuser4').person - - p1.add_friend(p2) - p1.add_friend(p3) - p1.add_friend(p4) - - block = FriendsBlock.new - block.expects(:owner).returns(p1) - - assert_equal 3, block.profile_count - end - - should 'count number of public and private people' do - owner = create_user('testuser1').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) - - assert_equal 2, block.profile_count - end - - should 'not count number of invisible people' do - owner = create_user('testuser1').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) - - assert_equal 1, block.profile_count - end - -end diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb deleted file mode 100644 index d4e877a..0000000 --- a/test/unit/members_block_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class MembersBlockTest < ActiveSupport::TestCase - - should 'inherit from ProfileListBlock' do - assert_kind_of ProfileListBlock, MembersBlock.new - end - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, MembersBlock.description - end - - should 'provide a default title' do - assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title - end - - should 'link to "all members" page' do - profile = create_user('mytestuser').person - block = MembersBlock.new - block.box = profile.boxes.first - block.save! - - expects(:_).with('View all').returns('View all') - expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'profile', :action => 'members').returns('link-to-members') - - assert_equal 'link-to-members', instance_eval(&block.footer) - end - - should 'pick random members' do - block = MembersBlock.new - - owner = mock - block.expects(:owner).returns(owner) - - list = [] - owner.expects(:members).returns(list) - - assert_same list, block.profiles - end - -end - diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb deleted file mode 100644 index 1684fc8..0000000 --- a/test/unit/people_block_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class PeopleBlockTest < ActiveSupport::TestCase - - should 'inherit from ProfileListBlock' do - assert_kind_of ProfileListBlock, PeopleBlock.new - end - - should 'declare its default title' do - assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title - end - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, PeopleBlock.description - end - - should 'give help' do - assert_not_equal ProfileListBlock.new.help, PeopleBlock.new.help - end - - should 'list people' do - owner = fast_create(Environment) - block = PeopleBlock.new - block.expects(:owner).returns(owner).at_least_once - person1 = fast_create(Person, :environment_id => owner.id) - person2 = fast_create(Person, :environment_id => owner.id) - - 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 browse people' do - block = PeopleBlock.new - block.stubs(:owner).returns(Environment.default) - - expects(:_).with('View all').returns('View all people') - expects(:link_to).with('View all people', :controller => 'search', :action => 'people') - instance_eval(&block.footer) - end - - protected - include NoosferoTestHelper - -end -- libgit2 0.21.2