Commit b853d6c3eb2ec5b044b0d29a047ff65fc3368c0b
1 parent
1d813b00
Exists in
master
and in
29 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 @@ | @@ -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,72 +6,60 @@ class FriendsBlockTest < ActionView::TestCase | ||
6 | assert_kind_of Block, FriendsBlock.new | 6 | assert_kind_of Block, FriendsBlock.new |
7 | end | 7 | end |
8 | 8 | ||
9 | - | ||
10 | should 'declare its default title' do | 9 | should 'declare its default title' do |
11 | FriendsBlock.any_instance.expects(:profile_count).returns(0) | 10 | FriendsBlock.any_instance.expects(:profile_count).returns(0) |
12 | assert_not_equal Block.new.default_title, FriendsBlock.new.default_title | 11 | assert_not_equal Block.new.default_title, FriendsBlock.new.default_title |
13 | end | 12 | end |
14 | 13 | ||
15 | - | ||
16 | should 'describe itself' do | 14 | should 'describe itself' do |
17 | assert_not_equal Block.description, FriendsBlock.description | 15 | assert_not_equal Block.description, FriendsBlock.description |
18 | end | 16 | end |
19 | 17 | ||
20 | - | ||
21 | should 'is editable' do | 18 | should 'is editable' do |
22 | block = FriendsBlock.new | 19 | block = FriendsBlock.new |
23 | assert block.editable? | 20 | assert block.editable? |
24 | end | 21 | end |
25 | 22 | ||
26 | - | ||
27 | should 'have field limit' do | 23 | should 'have field limit' do |
28 | block = FriendsBlock.new | 24 | block = FriendsBlock.new |
29 | assert_respond_to block, :limit | 25 | assert_respond_to block, :limit |
30 | end | 26 | end |
31 | 27 | ||
32 | - | ||
33 | should 'default value of limit' do | 28 | should 'default value of limit' do |
34 | block = FriendsBlock.new | 29 | block = FriendsBlock.new |
35 | assert_equal 6, block.limit | 30 | assert_equal 6, block.limit |
36 | end | 31 | end |
37 | 32 | ||
38 | - | ||
39 | should 'have field name' do | 33 | should 'have field name' do |
40 | block = FriendsBlock.new | 34 | block = FriendsBlock.new |
41 | assert_respond_to block, :name | 35 | assert_respond_to block, :name |
42 | end | 36 | end |
43 | 37 | ||
44 | - | ||
45 | should 'default value of name' do | 38 | should 'default value of name' do |
46 | block = FriendsBlock.new | 39 | block = FriendsBlock.new |
47 | assert_equal "", block.name | 40 | assert_equal "", block.name |
48 | end | 41 | end |
49 | 42 | ||
50 | - | ||
51 | should 'have field address' do | 43 | should 'have field address' do |
52 | block = FriendsBlock.new | 44 | block = FriendsBlock.new |
53 | assert_respond_to block, :address | 45 | assert_respond_to block, :address |
54 | end | 46 | end |
55 | 47 | ||
56 | - | ||
57 | should 'default value of address' do | 48 | should 'default value of address' do |
58 | block = FriendsBlock.new | 49 | block = FriendsBlock.new |
59 | assert_equal "", block.address | 50 | assert_equal "", block.address |
60 | end | 51 | end |
61 | 52 | ||
62 | - | ||
63 | should 'prioritize profiles with image by default' do | 53 | should 'prioritize profiles with image by default' do |
64 | assert FriendsBlock.new.prioritize_profiles_with_image | 54 | assert FriendsBlock.new.prioritize_profiles_with_image |
65 | end | 55 | end |
66 | 56 | ||
67 | - | ||
68 | should 'accept a limit of people to be displayed' do | 57 | should 'accept a limit of people to be displayed' do |
69 | block = FriendsBlock.new | 58 | block = FriendsBlock.new |
70 | block.limit = 20 | 59 | block.limit = 20 |
71 | assert_equal 20, block.limit | 60 | assert_equal 20, block.limit |
72 | end | 61 | end |
73 | 62 | ||
74 | - | ||
75 | should 'list friends from person' do | 63 | should 'list friends from person' do |
76 | owner = fast_create(Person) | 64 | owner = fast_create(Person) |
77 | friend1 = fast_create(Person) | 65 | friend1 = fast_create(Person) |
@@ -92,11 +80,11 @@ class FriendsBlockTest < ActionView::TestCase | @@ -92,11 +80,11 @@ class FriendsBlockTest < ActionView::TestCase | ||
92 | assert_match(/#{friend2.name}/, content) | 80 | assert_match(/#{friend2.name}/, content) |
93 | end | 81 | end |
94 | 82 | ||
95 | - | ||
96 | should 'link to "all friends"' do | 83 | should 'link to "all friends"' do |
97 | person1 = create_user('mytestperson').person | 84 | person1 = create_user('mytestperson').person |
98 | 85 | ||
99 | block = FriendsBlock.new | 86 | block = FriendsBlock.new |
87 | + block.stubs(:suggestions).returns([]) | ||
100 | block.expects(:owner).returns(person1).at_least_once | 88 | block.expects(:owner).returns(person1).at_least_once |
101 | 89 | ||
102 | instance_eval(&block.footer) | 90 | instance_eval(&block.footer) |
@@ -105,7 +93,6 @@ class FriendsBlockTest < ActionView::TestCase | @@ -105,7 +93,6 @@ class FriendsBlockTest < ActionView::TestCase | ||
105 | end | 93 | end |
106 | end | 94 | end |
107 | 95 | ||
108 | - | ||
109 | should 'count number of owner friends' do | 96 | should 'count number of owner friends' do |
110 | owner = fast_create(Person) | 97 | owner = fast_create(Person) |
111 | friend1 = fast_create(Person) | 98 | friend1 = fast_create(Person) |
@@ -121,7 +108,6 @@ class FriendsBlockTest < ActionView::TestCase | @@ -121,7 +108,6 @@ class FriendsBlockTest < ActionView::TestCase | ||
121 | assert_equal 3, block.profile_count | 108 | assert_equal 3, block.profile_count |
122 | end | 109 | end |
123 | 110 | ||
124 | - | ||
125 | should 'count number of public and private friends' do | 111 | should 'count number of public and private friends' do |
126 | owner = fast_create(Person) | 112 | owner = fast_create(Person) |
127 | private_p = fast_create(Person, {:public_profile => false}) | 113 | private_p = fast_create(Person, {:public_profile => false}) |
@@ -136,7 +122,6 @@ class FriendsBlockTest < ActionView::TestCase | @@ -136,7 +122,6 @@ class FriendsBlockTest < ActionView::TestCase | ||
136 | assert_equal 2, block.profile_count | 122 | assert_equal 2, block.profile_count |
137 | end | 123 | end |
138 | 124 | ||
139 | - | ||
140 | should 'not count number of invisible friends' do | 125 | should 'not count number of invisible friends' do |
141 | owner = fast_create(Person) | 126 | owner = fast_create(Person) |
142 | private_p = fast_create(Person, {:visible => false}) | 127 | private_p = fast_create(Person, {:visible => false}) |
@@ -151,6 +136,17 @@ class FriendsBlockTest < ActionView::TestCase | @@ -151,6 +136,17 @@ class FriendsBlockTest < ActionView::TestCase | ||
151 | assert_equal 1, block.profile_count | 136 | assert_equal 1, block.profile_count |
152 | end | 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 | protected | 150 | protected |
155 | include NoosferoTestHelper | 151 | include NoosferoTestHelper |
156 | 152 |
plugins/people_block/views/blocks/friends.html.erb
1 | <%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> | 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 | <div class='suggestions-block common-profile-list-block'> | 4 | <div class='suggestions-block common-profile-list-block'> |
5 | <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | 5 | <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> |
6 | <div class='profiles-suggestions'> | 6 | <div class='profiles-suggestions'> |