From b853d6c3eb2ec5b044b0d29a047ff65fc3368c0b Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Fri, 16 Jan 2015 23:13:23 -0300 Subject: [PATCH] [profile-suggestions] Fixes people_block test and adds a couple more --- plugins/people_block/test/functional/profile_controller_test.rb | 35 +++++++++++++++++++++++++++++++++++ plugins/people_block/test/unit/friends_block_test.rb | 28 ++++++++++++---------------- plugins/people_block/views/blocks/friends.html.erb | 2 +- 3 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 plugins/people_block/test/functional/profile_controller_test.rb diff --git a/plugins/people_block/test/functional/profile_controller_test.rb b/plugins/people_block/test/functional/profile_controller_test.rb new file mode 100644 index 0000000..5f95303 --- /dev/null +++ b/plugins/people_block/test/functional/profile_controller_test.rb @@ -0,0 +1,35 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class ProfileController; def rescue_action(e) raise e end; end + +class ProfileControllerTest < ActionController::TestCase + + def setup + @controller = ProfileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) + end + + should 'show suggestions to logged in owner' do + user = create_user('testinguser') + login_as(user.login) + owner = user.person + + suggestion1 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) + suggestion2 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) + + FriendsBlock.delete_all + block = FriendsBlock.new + block.box = owner.boxes.first + block.save! + + get :index, :profile => owner.identifier + assert_response :success + assert_tag :div, :attributes => {:class => 'profiles-suggestions'} + assert_template :partial => 'shared/_profile_suggestions_list', :locals => { :suggestions => block.suggestions } + assert_tag :a, :content => 'See all suggestions' + end + +end diff --git a/plugins/people_block/test/unit/friends_block_test.rb b/plugins/people_block/test/unit/friends_block_test.rb index 274edcb..fc5fd44 100644 --- a/plugins/people_block/test/unit/friends_block_test.rb +++ b/plugins/people_block/test/unit/friends_block_test.rb @@ -6,72 +6,60 @@ class FriendsBlockTest < ActionView::TestCase assert_kind_of Block, FriendsBlock.new end - should 'declare its default title' do FriendsBlock.any_instance.expects(:profile_count).returns(0) 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_profiles_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) @@ -92,11 +80,11 @@ class FriendsBlockTest < ActionView::TestCase assert_match(/#{friend2.name}/, content) end - should 'link to "all friends"' do person1 = create_user('mytestperson').person block = FriendsBlock.new + block.stubs(:suggestions).returns([]) block.expects(:owner).returns(person1).at_least_once instance_eval(&block.footer) @@ -105,7 +93,6 @@ class FriendsBlockTest < ActionView::TestCase end end - should 'count number of owner friends' do owner = fast_create(Person) friend1 = fast_create(Person) @@ -121,7 +108,6 @@ class FriendsBlockTest < ActionView::TestCase 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}) @@ -136,7 +122,6 @@ class FriendsBlockTest < ActionView::TestCase 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}) @@ -151,6 +136,17 @@ class FriendsBlockTest < ActionView::TestCase assert_equal 1, block.profile_count end + should 'list owner\'s friends suggestions' do + owner = fast_create(Person) + suggestion1 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) + suggestion2 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) + + block = FriendsBlock.new + block.stubs(:owner).returns(owner) + + assert_equivalent block.suggestions, [suggestion1,suggestion2] + end + protected include NoosferoTestHelper diff --git a/plugins/people_block/views/blocks/friends.html.erb b/plugins/people_block/views/blocks/friends.html.erb index 7598e8b..1908442 100644 --- a/plugins/people_block/views/blocks/friends.html.erb +++ b/plugins/people_block/views/blocks/friends.html.erb @@ -1,6 +1,6 @@ <%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> -<% if user == profile && !suggestions.empty? %> +<% if !suggestions.empty? && user == profile %>

<%= _('Some suggestions for you') %>

-- libgit2 0.21.2