Commit e7e132e71f3e4271d28e94784e743a644e955eb8

Authored by Daniela Feitosa
1 parent 5c42f6c1

Fix: profile_controller tests

app/helpers/profile_helper.rb
@@ -78,7 +78,9 @@ module ProfileHelper @@ -78,7 +78,9 @@ module ProfileHelper
78 entries = multiple ? value : [] << value 78 entries = multiple ? value : [] << value
79 entries.map do |entry| 79 entries.map do |entry|
80 content = self.send("treat_#{field}", entry) 80 content = self.send("treat_#{field}", entry)
81 - content_tag('tr', content_tag('td', title(field, entry), :class => 'field-name') + content_tag('td', content)) 81 + unless content.blank?
  82 + content_tag('tr', content_tag('td', title(field, entry), :class => 'field-name') + content_tag('td', content))
  83 + end
82 end.join("\n") 84 end.join("\n")
83 else 85 else
84 '' 86 ''
test/functional/profile_controller_test.rb
@@ -109,8 +109,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -109,8 +109,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
109 109
110 should 'show friends link to person' do 110 should 'show friends link to person' do
111 person = create_user('person_1').person 111 person = create_user('person_1').person
  112 + person.add_friend(profile)
112 get :index, :profile => person.identifier 113 get :index, :profile => person.identifier
113 - assert_tag :tag => 'a', :content => /#{profile.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } 114 + assert_tag :tag => 'a', :content => /#{person.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
114 end 115 end
115 116
116 should 'display tag for profile' do 117 should 'display tag for profile' do
@@ -232,6 +233,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -232,6 +233,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
232 233
233 should 'display "Products" link for enterprise' do 234 should 'display "Products" link for enterprise' do
234 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false) 235 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
  236 + product = fast_create(Product, :profile_id => ent.id)
235 237
236 get :index, :profile => 'my-test-enterprise' 238 get :index, :profile => 'my-test-enterprise'
237 assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ 239 assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
@@ -1081,8 +1083,16 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1081,8 +1083,16 @@ class ProfileControllerTest &lt; ActionController::TestCase
1081 atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id) 1083 atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id)
1082 get :index, :profile => person.identifier 1084 get :index, :profile => person.identifier
1083 assert_no_tag :tag => 'div', :attributes => {:id => 'profile-network'} 1085 assert_no_tag :tag => 'div', :attributes => {:id => 'profile-network'}
  1086 + end
  1087 +
  1088 + should "show the network activity if the viewer follows the profile" do
  1089 + login_as(profile.identifier)
  1090 + person = fast_create(Person)
  1091 + at = fast_create(ActionTracker::Record, :user_id => person.id)
  1092 + atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id)
1084 1093
1085 person.add_friend(profile) 1094 person.add_friend(profile)
  1095 + profile.add_friend(person)
1086 get :index, :profile => person.identifier 1096 get :index, :profile => person.identifier
1087 assert_tag :tag => 'div', :attributes => {:id => 'profile-network'} 1097 assert_tag :tag => 'div', :attributes => {:id => 'profile-network'}
1088 end 1098 end
@@ -1101,8 +1111,16 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1101,8 +1111,16 @@ class ProfileControllerTest &lt; ActionController::TestCase
1101 scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id) 1111 scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id)
1102 get :index, :profile => person.identifier 1112 get :index, :profile => person.identifier
1103 assert_no_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } 1113 assert_no_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} }
  1114 + end
  1115 +
  1116 + should "show the scrap area on wall if the user follows the user" do
  1117 + login_as(profile.identifier)
  1118 + person = fast_create(Person)
  1119 + scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id)
1104 1120
1105 person.add_friend(profile) 1121 person.add_friend(profile)
  1122 + profile.add_friend(person)
  1123 +
1106 get :index, :profile => person.identifier 1124 get :index, :profile => person.identifier
1107 assert_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } 1125 assert_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} }
1108 end 1126 end
@@ -1470,9 +1488,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1470,9 +1488,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1470 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } } 1488 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } }
1471 viewed.save! 1489 viewed.save!
1472 get :index, :profile => viewed.identifier 1490 get :index, :profile => viewed.identifier
1473 - assert_tag :tag => 'td', :content => 'Sex:' 1491 + assert_tag :tag => 'td', :content => 'Sex'
1474 assert_tag :tag => 'td', :content => 'Male' 1492 assert_tag :tag => 'td', :content => 'Male'
1475 - assert_tag :tag => 'td', :content => 'Date of birth:' 1493 + assert_tag :tag => 'td', :content => 'Date of birth'
1476 assert_tag :tag => 'td', :content => 'August 26, 1990' 1494 assert_tag :tag => 'td', :content => 'August 26, 1990'
1477 end 1495 end
1478 1496
@@ -1484,9 +1502,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1484,9 +1502,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1484 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1502 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1485 viewed.save! 1503 viewed.save!
1486 get :index, :profile => viewed.identifier 1504 get :index, :profile => viewed.identifier
1487 - assert_tag :tag => 'td', :content => 'Sex:' 1505 + assert_tag :tag => 'td', :content => 'Sex'
1488 assert_tag :tag => 'td', :content => 'Male' 1506 assert_tag :tag => 'td', :content => 'Male'
1489 - assert_no_tag :tag => 'td', :content => 'Date of birth:' 1507 + assert_no_tag :tag => 'td', :content => 'Date of birth'
1490 assert_no_tag :tag => 'td', :content => 'August 26, 1990' 1508 assert_no_tag :tag => 'td', :content => 'August 26, 1990'
1491 end 1509 end
1492 1510
@@ -1500,9 +1518,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1500,9 +1518,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1500 strange = create_user('person_2').person 1518 strange = create_user('person_2').person
1501 login_as(strange.identifier) 1519 login_as(strange.identifier)
1502 get :index, :profile => viewed.identifier 1520 get :index, :profile => viewed.identifier
1503 - assert_tag :tag => 'td', :content => 'Sex:' 1521 + assert_tag :tag => 'td', :content => 'Sex'
1504 assert_tag :tag => 'td', :content => 'Male' 1522 assert_tag :tag => 'td', :content => 'Male'
1505 - assert_no_tag :tag => 'td', :content => 'Date of birth:' 1523 + assert_no_tag :tag => 'td', :content => 'Date of birth'
1506 assert_no_tag :tag => 'td', :content => 'August 26, 1990' 1524 assert_no_tag :tag => 'td', :content => 'August 26, 1990'
1507 end 1525 end
1508 1526
@@ -1517,9 +1535,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1517,9 +1535,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1517 Person.any_instance.stubs(:is_a_friend?).returns(true) 1535 Person.any_instance.stubs(:is_a_friend?).returns(true)
1518 login_as(friend.identifier) 1536 login_as(friend.identifier)
1519 get :index, :profile => viewed.identifier 1537 get :index, :profile => viewed.identifier
1520 - assert_tag :tag => 'td', :content => 'Sex:' 1538 + assert_tag :tag => 'td', :content => 'Sex'
1521 assert_tag :tag => 'td', :content => 'Male' 1539 assert_tag :tag => 'td', :content => 'Male'
1522 - assert_tag :tag => 'td', :content => 'Date of birth:' 1540 + assert_tag :tag => 'td', :content => 'Date of birth'
1523 assert_tag :tag => 'td', :content => 'August 26, 1990' 1541 assert_tag :tag => 'td', :content => 'August 26, 1990'
1524 end 1542 end
1525 1543
@@ -1532,9 +1550,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1532,9 +1550,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1532 viewed.save! 1550 viewed.save!
1533 login_as(viewed.identifier) 1551 login_as(viewed.identifier)
1534 get :index, :profile => viewed.identifier 1552 get :index, :profile => viewed.identifier
1535 - assert_tag :tag => 'td', :content => 'Sex:' 1553 + assert_tag :tag => 'td', :content => 'Sex'
1536 assert_tag :tag => 'td', :content => 'Male' 1554 assert_tag :tag => 'td', :content => 'Male'
1537 - assert_tag :tag => 'td', :content => 'Date of birth:' 1555 + assert_tag :tag => 'td', :content => 'Date of birth'
1538 assert_tag :tag => 'td', :content => 'August 26, 1990' 1556 assert_tag :tag => 'td', :content => 'August 26, 1990'
1539 end 1557 end
1540 1558
@@ -1547,7 +1565,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1547,7 +1565,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1547 login_as(strange.identifier) 1565 login_as(strange.identifier)
1548 get :index, :profile => viewed.identifier 1566 get :index, :profile => viewed.identifier
1549 assert_tag :tag => 'th', :content => 'Contact' 1567 assert_tag :tag => 'th', :content => 'Contact'
1550 - assert_tag :tag => 'td', :content => 'e-Mail:' 1568 + assert_tag :tag => 'td', :content => 'e-Mail'
1551 end 1569 end
1552 1570
1553 should 'show contact to friend' do 1571 should 'show contact to friend' do
@@ -1560,7 +1578,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1560,7 +1578,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1560 login_as(friend.identifier) 1578 login_as(friend.identifier)
1561 get :index, :profile => viewed.identifier 1579 get :index, :profile => viewed.identifier
1562 assert_tag :tag => 'th', :content => 'Contact' 1580 assert_tag :tag => 'th', :content => 'Contact'
1563 - assert_tag :tag => 'td', :content => 'e-Mail:' 1581 + assert_tag :tag => 'td', :content => 'e-Mail'
1564 end 1582 end
1565 1583
1566 should 'show contact to self' do 1584 should 'show contact to self' do
@@ -1571,7 +1589,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1571,7 +1589,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1571 login_as(viewed.identifier) 1589 login_as(viewed.identifier)
1572 get :index, :profile => viewed.identifier 1590 get :index, :profile => viewed.identifier
1573 assert_tag :tag => 'th', :content => 'Contact' 1591 assert_tag :tag => 'th', :content => 'Contact'
1574 - assert_tag :tag => 'td', :content => 'e-Mail:' 1592 + assert_tag :tag => 'td', :content => 'e-Mail'
1575 end 1593 end
1576 1594
1577 should 'not show contact to non friend' do 1595 should 'not show contact to non friend' do
@@ -1583,7 +1601,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1583,7 +1601,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1583 login_as(strange.identifier) 1601 login_as(strange.identifier)
1584 get :index, :profile => viewed.identifier 1602 get :index, :profile => viewed.identifier
1585 assert_no_tag :tag => 'th', :content => 'Contact' 1603 assert_no_tag :tag => 'th', :content => 'Contact'
1586 - assert_no_tag :tag => 'td', :content => 'e-Mail:' 1604 + assert_no_tag :tag => 'td', :content => 'e-Mail'
1587 end 1605 end
1588 1606
1589 should 'show contact to friend even if private' do 1607 should 'show contact to friend even if private' do
@@ -1596,7 +1614,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1596,7 +1614,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1596 login_as(friend.identifier) 1614 login_as(friend.identifier)
1597 get :index, :profile => viewed.identifier 1615 get :index, :profile => viewed.identifier
1598 assert_tag :tag => 'th', :content => 'Contact' 1616 assert_tag :tag => 'th', :content => 'Contact'
1599 - assert_tag :tag => 'td', :content => 'e-Mail:' 1617 + assert_tag :tag => 'td', :content => 'e-Mail'
1600 end 1618 end
1601 1619
1602 should 'show contact to self even if private' do 1620 should 'show contact to self even if private' do
@@ -1607,7 +1625,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1607,7 +1625,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1607 login_as(viewed.identifier) 1625 login_as(viewed.identifier)
1608 get :index, :profile => viewed.identifier 1626 get :index, :profile => viewed.identifier
1609 assert_tag :tag => 'th', :content => 'Contact' 1627 assert_tag :tag => 'th', :content => 'Contact'
1610 - assert_tag :tag => 'td', :content => 'e-Mail:' 1628 + assert_tag :tag => 'td', :content => 'e-Mail'
1611 end 1629 end
1612 1630
1613 should 'not display list of communities to manage on menu by default' do 1631 should 'not display list of communities to manage on menu by default' do
@@ -1715,22 +1733,28 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1715,22 +1733,28 @@ class ProfileControllerTest &lt; ActionController::TestCase
1715 1733
1716 should 'show enterprises field if enterprises are enabled on environment' do 1734 should 'show enterprises field if enterprises are enabled on environment' do
1717 person = fast_create(Person) 1735 person = fast_create(Person)
  1736 + enterprise = fast_create(Enterprise)
  1737 + enterprise.add_admin person
1718 environment = person.environment 1738 environment = person.environment
1719 environment.disable('disable_asset_enterprises') 1739 environment.disable('disable_asset_enterprises')
1720 environment.save! 1740 environment.save!
1721 1741
1722 get :index, :profile => person.identifier 1742 get :index, :profile => person.identifier
1723 - assert_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } 1743 + assert_tag :tag => 'td', :content => 'Enterprises'
  1744 + assert_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }}
1724 end 1745 end
1725 1746
1726 should 'not show enterprises field if enterprises are disabled on environment' do 1747 should 'not show enterprises field if enterprises are disabled on environment' do
1727 person = fast_create(Person) 1748 person = fast_create(Person)
  1749 + enterprise = fast_create(Enterprise)
  1750 + enterprise.add_admin person
1728 environment = person.environment 1751 environment = person.environment
1729 environment.enable('disable_asset_enterprises') 1752 environment.enable('disable_asset_enterprises')
1730 environment.save! 1753 environment.save!
1731 1754
1732 get :index, :profile => person.identifier 1755 get :index, :profile => person.identifier
1733 - assert_no_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } 1756 + assert_no_tag :tag => 'td', :content => 'Enterprises'
  1757 + assert_no_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }}
1734 end 1758 end
1735 1759
1736 end 1760 end