Commit 0c29ae21aefd8a506678dbc290d0a72743927989

Authored by Caio Almeida
Committed by Daniela Feitosa
1 parent 27eb1487

Hide contact if no information available

app/helpers/profile_helper.rb
@@ -16,4 +16,16 @@ module ProfileHelper @@ -16,4 +16,16 @@ module ProfileHelper
16 end 16 end
17 end 17 end
18 18
  19 + def display_contact(profile)
  20 + address = display_field(_('Address:'), profile, :address)
  21 + zip = display_field(_('ZIP code:'), profile, :zip_code)
  22 + phone = display_field(_('Contact phone:'), profile, :contact_phone)
  23 + email = display_field(_('e-Mail:'), profile, :email) { |email| link_to_email(email) }
  24 + if address.blank? && zip.blank? && phone.blank? && email.blank?
  25 + ''
  26 + else
  27 + content_tag('tr', content_tag('th', _('Contact'), { :colspan => 2 })) + address + zip + phone + email
  28 + end
  29 + end
  30 +
19 end 31 end
app/views/profile/_person_profile.rhtml
@@ -13,13 +13,7 @@ @@ -13,13 +13,7 @@
13 <td><%= show_date(profile.created_at) %></td> 13 <td><%= show_date(profile.created_at) %></td>
14 </tr> 14 </tr>
15 15
16 - <tr>  
17 - <th colspan='2'><%= _('Contact')%></th>  
18 - </tr>  
19 - <%= display_field(_('Address:'), profile, :address) %>  
20 - <%= display_field(_('ZIP code:'), profile, :zip_code) %>  
21 - <%= display_field(_('Contact phone:'), profile, :contact_phone) %>  
22 - <%= display_field(_('e-Mail:'), profile, :email) { |email| link_to_email(email) } %> 16 + <%= display_contact profile %>
23 17
24 <% cache_timeout(profile.relationships_cache_key, 4.hours) do %> 18 <% cache_timeout(profile.relationships_cache_key, 4.hours) do %>
25 <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %> 19 <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %>
test/functional/profile_controller_test.rb
@@ -279,16 +279,6 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -279,16 +279,6 @@ class ProfileControllerTest &lt; ActionController::TestCase
279 assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tags/two'} } 279 assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tags/two'} }
280 end 280 end
281 281
282 - should 'show e-mail for friends on profile page' do  
283 - p1 = create_user('tusr1').person  
284 - p2 = create_user('tusr2', :email => 't2@t2.com').person  
285 - p2.add_friend p1  
286 - login_as 'tusr1'  
287 -  
288 - get :index, :profile => 'tusr2'  
289 - assert_tag :content => /t2.*t2.com/  
290 - end  
291 -  
292 should 'not show e-mail for non friends on profile page' do 282 should 'not show e-mail for non friends on profile page' do
293 p1 = create_user('tusr1').person 283 p1 = create_user('tusr1').person
294 p2 = create_user('tusr2', :email => 't2@t2.com').person 284 p2 = create_user('tusr2', :email => 't2@t2.com').person
@@ -1375,7 +1365,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1375,7 +1365,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1375 viewed = create_user('person_1').person 1365 viewed = create_user('person_1').person
1376 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date']) 1366 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
1377 Environment.any_instance.stubs(:required_person_fields).returns([]) 1367 Environment.any_instance.stubs(:required_person_fields).returns([])
1378 - viewed.birth_date = Time.now.ago(22.years) 1368 + viewed.birth_date = Time.parse('2012-08-26').ago(22.years)
1379 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } } 1369 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } }
1380 viewed.save! 1370 viewed.save!
1381 get :index, :profile => viewed.identifier 1371 get :index, :profile => viewed.identifier
@@ -1389,7 +1379,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1389,7 +1379,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1389 viewed = create_user('person_1').person 1379 viewed = create_user('person_1').person
1390 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date']) 1380 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
1391 Environment.any_instance.stubs(:required_person_fields).returns([]) 1381 Environment.any_instance.stubs(:required_person_fields).returns([])
1392 - viewed.birth_date = Time.now.ago(22.years) 1382 + viewed.birth_date = Time.parse('2012-08-26').ago(22.years)
1393 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1383 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1394 viewed.save! 1384 viewed.save!
1395 get :index, :profile => viewed.identifier 1385 get :index, :profile => viewed.identifier
@@ -1403,7 +1393,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1403,7 +1393,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1403 viewed = create_user('person_1').person 1393 viewed = create_user('person_1').person
1404 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date']) 1394 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
1405 Environment.any_instance.stubs(:required_person_fields).returns([]) 1395 Environment.any_instance.stubs(:required_person_fields).returns([])
1406 - viewed.birth_date = Time.now.ago(22.years) 1396 + viewed.birth_date = Time.parse('2012-08-26').ago(22.years)
1407 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1397 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1408 viewed.save! 1398 viewed.save!
1409 strange = create_user('person_2').person 1399 strange = create_user('person_2').person
@@ -1420,7 +1410,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1420,7 +1410,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1420 friend = create_user('person_2').person 1410 friend = create_user('person_2').person
1421 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date']) 1411 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
1422 Environment.any_instance.stubs(:required_person_fields).returns([]) 1412 Environment.any_instance.stubs(:required_person_fields).returns([])
1423 - viewed.birth_date = Time.now.ago(22.years) 1413 + viewed.birth_date = Time.parse('2012-08-26').ago(22.years)
1424 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1414 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1425 viewed.save! 1415 viewed.save!
1426 Person.any_instance.stubs(:is_a_friend?).returns(true) 1416 Person.any_instance.stubs(:is_a_friend?).returns(true)
@@ -1436,7 +1426,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1436,7 +1426,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1436 viewed = create_user('person_1').person 1426 viewed = create_user('person_1').person
1437 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date']) 1427 Environment.any_instance.stubs(:active_person_fields).returns(['sex', 'birth_date'])
1438 Environment.any_instance.stubs(:required_person_fields).returns([]) 1428 Environment.any_instance.stubs(:required_person_fields).returns([])
1439 - viewed.birth_date = Time.now.ago(22.years) 1429 + viewed.birth_date = Time.parse('2012-08-26').ago(22.years)
1440 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1430 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1441 viewed.save! 1431 viewed.save!
1442 login_as(viewed.identifier) 1432 login_as(viewed.identifier)
@@ -1447,4 +1437,76 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1447,4 +1437,76 @@ class ProfileControllerTest &lt; ActionController::TestCase
1447 assert_tag :tag => 'td', :content => 'August 26, 1990' 1437 assert_tag :tag => 'td', :content => 'August 26, 1990'
1448 end 1438 end
1449 1439
  1440 + should 'show contact to non friend' do
  1441 + viewed = create_user('person_1').person
  1442 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1443 + viewed.data = { :email => 'test@test.com', :fields_privacy => { 'email' => 'public' } }
  1444 + viewed.save!
  1445 + strange = create_user('person_2').person
  1446 + login_as(strange.identifier)
  1447 + get :index, :profile => viewed.identifier
  1448 + assert_tag :tag => 'th', :content => 'Contact'
  1449 + assert_tag :tag => 'td', :content => 'e-Mail:'
  1450 + end
  1451 +
  1452 + should 'show contact to friend' do
  1453 + viewed = create_user('person_1').person
  1454 + friend = create_user('person_2').person
  1455 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1456 + viewed.data = { :email => 'test@test.com', :fields_privacy => { 'email' => 'public' } }
  1457 + viewed.save!
  1458 + Person.any_instance.stubs(:is_a_friend?).returns(true)
  1459 + login_as(friend.identifier)
  1460 + get :index, :profile => viewed.identifier
  1461 + assert_tag :tag => 'th', :content => 'Contact'
  1462 + assert_tag :tag => 'td', :content => 'e-Mail:'
  1463 + end
  1464 +
  1465 + should 'show contact to self' do
  1466 + viewed = create_user('person_1').person
  1467 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1468 + viewed.data = { :email => 'test@test.com', :fields_privacy => { 'email' => 'public' } }
  1469 + viewed.save!
  1470 + login_as(viewed.identifier)
  1471 + get :index, :profile => viewed.identifier
  1472 + assert_tag :tag => 'th', :content => 'Contact'
  1473 + assert_tag :tag => 'td', :content => 'e-Mail:'
  1474 + end
  1475 +
  1476 + should 'not show contact to non friend' do
  1477 + viewed = create_user('person_1').person
  1478 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1479 + viewed.data = { :email => 'test@test.com', :fields_privacy => { } }
  1480 + viewed.save!
  1481 + strange = create_user('person_2').person
  1482 + login_as(strange.identifier)
  1483 + get :index, :profile => viewed.identifier
  1484 + assert_no_tag :tag => 'th', :content => 'Contact'
  1485 + assert_no_tag :tag => 'td', :content => 'e-Mail:'
  1486 + end
  1487 +
  1488 + should 'show contact to friend even if private' do
  1489 + viewed = create_user('person_1').person
  1490 + friend = create_user('person_2').person
  1491 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1492 + viewed.data = { :email => 'test@test.com', :fields_privacy => { } }
  1493 + viewed.save!
  1494 + Person.any_instance.stubs(:is_a_friend?).returns(true)
  1495 + login_as(friend.identifier)
  1496 + get :index, :profile => viewed.identifier
  1497 + assert_tag :tag => 'th', :content => 'Contact'
  1498 + assert_tag :tag => 'td', :content => 'e-Mail:'
  1499 + end
  1500 +
  1501 + should 'show contact to self even if private' do
  1502 + viewed = create_user('person_1').person
  1503 + Environment.any_instance.stubs(:required_person_fields).returns([])
  1504 + viewed.data = { :email => 'test@test.com', :fields_privacy => { } }
  1505 + viewed.save!
  1506 + login_as(viewed.identifier)
  1507 + get :index, :profile => viewed.identifier
  1508 + assert_tag :tag => 'th', :content => 'Contact'
  1509 + assert_tag :tag => 'td', :content => 'e-Mail:'
  1510 + end
  1511 +
1450 end 1512 end