Commit b853d6c3eb2ec5b044b0d29a047ff65fc3368c0b
1 parent
1d813b00
Exists in
master
and in
21 other branches
[profile-suggestions] Fixes people_block test and adds a couple more
`instance_eval` in FriendsBlockTest chokes on `user` so we avoid this `people_block` test from crashing by checking if suggestions exist first. Therefore this unit test is only testing for a view all link, so I wrote a couple more tests to test the added suggestion feature inside the block. I wasn't sure where to put a test to actually test that the suggestions are being rendered so I created a ProfileControllerTest, but I'm open to suggestions on where it would be best :)
Showing
3 changed files
with
48 additions
and
17 deletions
Show diff stats
plugins/people_block/test/functional/profile_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +# Re-raise errors caught by the controller. | |
| 4 | +class ProfileController; def rescue_action(e) raise e end; end | |
| 5 | + | |
| 6 | +class ProfileControllerTest < ActionController::TestCase | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + @controller = ProfileController.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 'show suggestions to logged in owner' do | |
| 16 | + user = create_user('testinguser') | |
| 17 | + login_as(user.login) | |
| 18 | + owner = user.person | |
| 19 | + | |
| 20 | + suggestion1 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) | |
| 21 | + suggestion2 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) | |
| 22 | + | |
| 23 | + FriendsBlock.delete_all | |
| 24 | + block = FriendsBlock.new | |
| 25 | + block.box = owner.boxes.first | |
| 26 | + block.save! | |
| 27 | + | |
| 28 | + get :index, :profile => owner.identifier | |
| 29 | + assert_response :success | |
| 30 | + assert_tag :div, :attributes => {:class => 'profiles-suggestions'} | |
| 31 | + assert_template :partial => 'shared/_profile_suggestions_list', :locals => { :suggestions => block.suggestions } | |
| 32 | + assert_tag :a, :content => 'See all suggestions' | |
| 33 | + end | |
| 34 | + | |
| 35 | +end | ... | ... |
plugins/people_block/test/unit/friends_block_test.rb
| ... | ... | @@ -6,72 +6,60 @@ class FriendsBlockTest < ActionView::TestCase |
| 6 | 6 | assert_kind_of Block, FriendsBlock.new |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | - | |
| 10 | 9 | should 'declare its default title' do |
| 11 | 10 | FriendsBlock.any_instance.expects(:profile_count).returns(0) |
| 12 | 11 | assert_not_equal Block.new.default_title, FriendsBlock.new.default_title |
| 13 | 12 | end |
| 14 | 13 | |
| 15 | - | |
| 16 | 14 | should 'describe itself' do |
| 17 | 15 | assert_not_equal Block.description, FriendsBlock.description |
| 18 | 16 | end |
| 19 | 17 | |
| 20 | - | |
| 21 | 18 | should 'is editable' do |
| 22 | 19 | block = FriendsBlock.new |
| 23 | 20 | assert block.editable? |
| 24 | 21 | end |
| 25 | 22 | |
| 26 | - | |
| 27 | 23 | should 'have field limit' do |
| 28 | 24 | block = FriendsBlock.new |
| 29 | 25 | assert_respond_to block, :limit |
| 30 | 26 | end |
| 31 | 27 | |
| 32 | - | |
| 33 | 28 | should 'default value of limit' do |
| 34 | 29 | block = FriendsBlock.new |
| 35 | 30 | assert_equal 6, block.limit |
| 36 | 31 | end |
| 37 | 32 | |
| 38 | - | |
| 39 | 33 | should 'have field name' do |
| 40 | 34 | block = FriendsBlock.new |
| 41 | 35 | assert_respond_to block, :name |
| 42 | 36 | end |
| 43 | 37 | |
| 44 | - | |
| 45 | 38 | should 'default value of name' do |
| 46 | 39 | block = FriendsBlock.new |
| 47 | 40 | assert_equal "", block.name |
| 48 | 41 | end |
| 49 | 42 | |
| 50 | - | |
| 51 | 43 | should 'have field address' do |
| 52 | 44 | block = FriendsBlock.new |
| 53 | 45 | assert_respond_to block, :address |
| 54 | 46 | end |
| 55 | 47 | |
| 56 | - | |
| 57 | 48 | should 'default value of address' do |
| 58 | 49 | block = FriendsBlock.new |
| 59 | 50 | assert_equal "", block.address |
| 60 | 51 | end |
| 61 | 52 | |
| 62 | - | |
| 63 | 53 | should 'prioritize profiles with image by default' do |
| 64 | 54 | assert FriendsBlock.new.prioritize_profiles_with_image |
| 65 | 55 | end |
| 66 | 56 | |
| 67 | - | |
| 68 | 57 | should 'accept a limit of people to be displayed' do |
| 69 | 58 | block = FriendsBlock.new |
| 70 | 59 | block.limit = 20 |
| 71 | 60 | assert_equal 20, block.limit |
| 72 | 61 | end |
| 73 | 62 | |
| 74 | - | |
| 75 | 63 | should 'list friends from person' do |
| 76 | 64 | owner = fast_create(Person) |
| 77 | 65 | friend1 = fast_create(Person) |
| ... | ... | @@ -92,11 +80,11 @@ class FriendsBlockTest < ActionView::TestCase |
| 92 | 80 | assert_match(/#{friend2.name}/, content) |
| 93 | 81 | end |
| 94 | 82 | |
| 95 | - | |
| 96 | 83 | should 'link to "all friends"' do |
| 97 | 84 | person1 = create_user('mytestperson').person |
| 98 | 85 | |
| 99 | 86 | block = FriendsBlock.new |
| 87 | + block.stubs(:suggestions).returns([]) | |
| 100 | 88 | block.expects(:owner).returns(person1).at_least_once |
| 101 | 89 | |
| 102 | 90 | instance_eval(&block.footer) |
| ... | ... | @@ -105,7 +93,6 @@ class FriendsBlockTest < ActionView::TestCase |
| 105 | 93 | end |
| 106 | 94 | end |
| 107 | 95 | |
| 108 | - | |
| 109 | 96 | should 'count number of owner friends' do |
| 110 | 97 | owner = fast_create(Person) |
| 111 | 98 | friend1 = fast_create(Person) |
| ... | ... | @@ -121,7 +108,6 @@ class FriendsBlockTest < ActionView::TestCase |
| 121 | 108 | assert_equal 3, block.profile_count |
| 122 | 109 | end |
| 123 | 110 | |
| 124 | - | |
| 125 | 111 | should 'count number of public and private friends' do |
| 126 | 112 | owner = fast_create(Person) |
| 127 | 113 | private_p = fast_create(Person, {:public_profile => false}) |
| ... | ... | @@ -136,7 +122,6 @@ class FriendsBlockTest < ActionView::TestCase |
| 136 | 122 | assert_equal 2, block.profile_count |
| 137 | 123 | end |
| 138 | 124 | |
| 139 | - | |
| 140 | 125 | should 'not count number of invisible friends' do |
| 141 | 126 | owner = fast_create(Person) |
| 142 | 127 | private_p = fast_create(Person, {:visible => false}) |
| ... | ... | @@ -151,6 +136,17 @@ class FriendsBlockTest < ActionView::TestCase |
| 151 | 136 | assert_equal 1, block.profile_count |
| 152 | 137 | end |
| 153 | 138 | |
| 139 | + should 'list owner\'s friends suggestions' do | |
| 140 | + owner = fast_create(Person) | |
| 141 | + suggestion1 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) | |
| 142 | + suggestion2 = owner.profile_suggestions.create(:suggestion => fast_create(Person)) | |
| 143 | + | |
| 144 | + block = FriendsBlock.new | |
| 145 | + block.stubs(:owner).returns(owner) | |
| 146 | + | |
| 147 | + assert_equivalent block.suggestions, [suggestion1,suggestion2] | |
| 148 | + end | |
| 149 | + | |
| 154 | 150 | protected |
| 155 | 151 | include NoosferoTestHelper |
| 156 | 152 | ... | ... |
plugins/people_block/views/blocks/friends.html.erb
| 1 | 1 | <%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> |
| 2 | 2 | |
| 3 | -<% if user == profile && !suggestions.empty? %> | |
| 3 | +<% if !suggestions.empty? && user == profile %> | |
| 4 | 4 | <div class='suggestions-block common-profile-list-block'> |
| 5 | 5 | <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> |
| 6 | 6 | <div class='profiles-suggestions'> | ... | ... |