Commit 87890031d50e2b6ebde793eb7b84bdd392627fb7

Authored by Evandro Jr
2 parents f864635a ce28f728

Merge branch 'stable' of gitlab.com:participa/noosfero into stable

app/helpers/profile_helper.rb
1 module ProfileHelper 1 module ProfileHelper
2 2
3 COMMON_CATEGORIES = ActiveSupport::OrderedHash.new 3 COMMON_CATEGORIES = ActiveSupport::OrderedHash.new
4 - COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :tags] 4 + COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :article_tags]
5 COMMON_CATEGORIES[:interests] = [:interests] 5 COMMON_CATEGORIES[:interests] = [:interests]
6 COMMON_CATEGORIES[:general] = nil 6 COMMON_CATEGORIES[:general] = nil
7 7
@@ -41,6 +41,7 @@ module ProfileHelper @@ -41,6 +41,7 @@ module ProfileHelper
41 :birth_date => _('Date of birth'), 41 :birth_date => _('Date of birth'),
42 :created_at => _('Profile created at'), 42 :created_at => _('Profile created at'),
43 :members_count => _('Members'), 43 :members_count => _('Members'),
  44 + :article_tags => _('Tags')
44 } 45 }
45 46
46 EXCEPTION = { 47 EXCEPTION = {
@@ -73,14 +74,18 @@ module ProfileHelper @@ -73,14 +74,18 @@ module ProfileHelper
73 return '' 74 return ''
74 end 75 end
75 value = begin profile.send(field) rescue nil end 76 value = begin profile.send(field) rescue nil end
76 - if !value.blank? 77 + return '' if value.blank?
  78 + if value.kind_of?(Hash)
  79 + content = self.send("treat_#{field}", value)
  80 + content_tag('tr', content_tag('td', title(field), :class => 'field-name') + content_tag('td', content))
  81 + else
77 entries = multiple ? value : [] << value 82 entries = multiple ? value : [] << value
78 entries.map do |entry| 83 entries.map do |entry|
79 content = self.send("treat_#{field}", entry) 84 content = self.send("treat_#{field}", entry)
80 - content_tag('tr', content_tag('td', title(field, entry), :class => 'field-name') + content_tag('td', content)) 85 + unless content.blank?
  86 + content_tag('tr', content_tag('td', title(field, entry), :class => 'field-name') + content_tag('td', content))
  87 + end
81 end.join("\n") 88 end.join("\n")
82 - else  
83 - ''  
84 end 89 end
85 end 90 end
86 91
@@ -142,7 +147,7 @@ module ProfileHelper @@ -142,7 +147,7 @@ module ProfileHelper
142 link_to events.published.count, :controller => 'events', :action => 'events' 147 link_to events.published.count, :controller => 'events', :action => 'events'
143 end 148 end
144 149
145 - def treat_tags(tags) 150 + def treat_article_tags(tags)
146 tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10 151 tag_cloud @tags, :id, { :action => 'tags' }, :max_size => 18, :min_size => 10
147 end 152 end
148 153
app/models/external_feed.rb
@@ -13,6 +13,7 @@ class ExternalFeed &lt; ActiveRecord::Base @@ -13,6 +13,7 @@ class ExternalFeed &lt; ActiveRecord::Base
13 attr_accessible :address, :enabled 13 attr_accessible :address, :enabled
14 14
15 def add_item(title, link, date, content) 15 def add_item(title, link, date, content)
  16 + return if content.blank?
16 doc = Hpricot(content) 17 doc = Hpricot(content)
17 doc.search('*').each do |p| 18 doc.search('*').each do |p|
18 if p.instance_of? Hpricot::Elem 19 if p.instance_of? Hpricot::Elem
db/migrate/20140708121356_index_articles_filtered_fields.rb
1 class IndexArticlesFilteredFields < ActiveRecord::Migration 1 class IndexArticlesFilteredFields < ActiveRecord::Migration
2 def self.up 2 def self.up
3 %w[articles article_versions].each do |table| 3 %w[articles article_versions].each do |table|
4 - add_index table, [:path]  
5 - add_index table, [:path, :profile_id] 4 + add_index table.to_sym, [:path]
  5 + add_index table.to_sym, [:path, :profile_id]
6 end 6 end
7 add_index :articles, [:type] 7 add_index :articles, [:type]
8 add_index :articles, [:type, :parent_id] 8 add_index :articles, [:type, :parent_id]
db/migrate/20140709212646_add_spam_comments_counter_cache_to_articles.rb
@@ -2,7 +2,10 @@ class AddSpamCommentsCounterCacheToArticles &lt; ActiveRecord::Migration @@ -2,7 +2,10 @@ class AddSpamCommentsCounterCacheToArticles &lt; ActiveRecord::Migration
2 def self.up 2 def self.up
3 add_column :articles, :spam_comments_count, :integer, :default => 0 3 add_column :articles, :spam_comments_count, :integer, :default => 0
4 add_column :article_versions, :spam_comments_count, :integer, :default => 0 4 add_column :article_versions, :spam_comments_count, :integer, :default => 0
5 - execute "update articles set spam_comments_count = (select count(*) from comments where comments.source_id = articles.id and comments.source_type = 'Article' and comments.spam = 't');" 5 +
  6 + execute("SELECT comments.source_id as source_id, count(comments.id) as comments_count FROM comments LEFT OUTER JOIN articles ON articles.id = source_id WHERE comments.source_type = 'Article' AND comments.spam = 't' GROUP BY comments.source_id;").each do |data|
  7 + execute("UPDATE articles SET spam_comments_count = '#{data['comments_count']}' WHERE id = #{data['source_id']}")
  8 + end
6 end 9 end
7 10
8 def self.down 11 def self.down
db/migrate/20140709224246_create_real_relation_between_article_and_author.rb
@@ -4,8 +4,10 @@ class CreateRealRelationBetweenArticleAndAuthor &lt; ActiveRecord::Migration @@ -4,8 +4,10 @@ class CreateRealRelationBetweenArticleAndAuthor &lt; ActiveRecord::Migration
4 add_column :article_versions, :author_id, :integer 4 add_column :article_versions, :author_id, :integer
5 5
6 # Set article's author as the first version's last_changed_by_id. 6 # Set article's author as the first version's last_changed_by_id.
7 - execute "update articles set author_id = (select article_versions.last_changed_by_id from article_versions where article_versions.article_id = articles.id and article_versions.version = 1 limit 1)"  
8 - end 7 + execute("UPDATE article_versions SET author_id = last_changed_by_id")
  8 +
  9 + execute("UPDATE articles SET author_id = article_versions.author_id FROM article_versions WHERE article_versions.article_id = articles.id AND article_versions.version = 1")
  10 + end
9 11
10 def self.down 12 def self.down
11 remove_column :articles, :author_id 13 remove_column :articles, :author_id
db/migrate/20140724180943_add_index_to_blog_posts_sort.rb
1 class AddIndexToBlogPostsSort < ActiveRecord::Migration 1 class AddIndexToBlogPostsSort < ActiveRecord::Migration
2 def self.up 2 def self.up
3 %w[articles article_versions].each do |table| 3 %w[articles article_versions].each do |table|
4 - add_index table, [:published_at, :id] 4 + add_index table.to_sym, [:published_at, :id]
5 end 5 end
6 end 6 end
7 7
8 def self.down 8 def self.down
9 %w[articles article_versions].each do |table| 9 %w[articles article_versions].each do |table|
10 - remove_index table, [:published_at, :id] 10 + remove_index table.to_sym, [:published_at, :id]
11 end 11 end
12 end 12 end
13 end 13 end
features/profile_tags.feature
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -Feature: profile tags  
2 - As a Noosfero user  
3 - I want to to view content tagged  
4 - So that I can follow the subjects I care about  
5 -  
6 - Background:  
7 - Given the following users  
8 - | login |  
9 - | terceiro |  
10 - And the following articles  
11 - | owner | name | body | tag_list |  
12 - | terceiro | text 1 | text 1 content | tag1, tag2 |  
13 - | terceiro | text 2 | text 2 content | tag1, tag3 |  
14 -  
15 - Scenario: tag feed  
16 - When I go to terceiro's profile  
17 - And I follow "tag1"  
18 - And I follow "Feed for this tag"  
19 - Then I should see "text 1"  
20 - And I should see "text 2"  
plugins/pairwise/views/content_viewer/prompt.html.erb
1 <% extend PairwisePlugin::Helpers::ViewerHelper %> 1 <% extend PairwisePlugin::Helpers::ViewerHelper %>
2 2
3 -<% if embeded %>  
4 - <%= javascript_include_tag :defaults, 'jquery-latest.js',  
5 - 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'colorbox',  
6 - 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery-validation/jquery.validate',  
7 - 'jquery.cookie', 'jquery.ba-bbq.min.js', 'reflection', 'jquery.tokeninput',  
8 - 'add-and-join', 'report-abuse', 'catalog', 'manage-products',  
9 - 'jquery-ui-timepicker-addon', :cache => 'cache-general' %>  
10 -<% end %> 3 +<%= render :file => 'layouts/_javascript' if embeded %>
11 4
12 <%= render :partial => 'content_viewer/prompt_body', :locals => {:embeded => embeded, :pairwise_content => pairwise_content, :question => nil, :source => (defined?(source) ? source : '') }%> 5 <%= render :partial => 'content_viewer/prompt_body', :locals => {:embeded => embeded, :pairwise_content => pairwise_content, :question => nil, :source => (defined?(source) ? source : '') }%>
test/functional/profile_controller_test.rb
@@ -98,8 +98,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -98,8 +98,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
98 98
99 should 'show friends link to person' do 99 should 'show friends link to person' do
100 person = create_user('person_1').person 100 person = create_user('person_1').person
  101 + person.add_friend(profile)
101 get :index, :profile => person.identifier 102 get :index, :profile => person.identifier
102 - assert_tag :tag => 'a', :content => /#{profile.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } 103 + assert_tag :tag => 'a', :content => /#{person.friends.count}/, :attributes => { :href => /profile\/#{person.identifier}\/friends$/ }
103 end 104 end
104 105
105 should 'display tag for profile' do 106 should 'display tag for profile' do
@@ -221,6 +222,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -221,6 +222,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
221 222
222 should 'display "Products" link for enterprise' do 223 should 'display "Products" link for enterprise' do
223 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false) 224 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
  225 + product = fast_create(Product, :profile_id => ent.id)
224 226
225 get :index, :profile => 'my-test-enterprise' 227 get :index, :profile => 'my-test-enterprise'
226 assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ 228 assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
@@ -488,6 +490,14 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -488,6 +490,14 @@ class ProfileControllerTest &lt; ActionController::TestCase
488 assert_tag :tag => 'a', :content => 'One picture', :attributes => { :href => /\/testuser\/gallery/ } 490 assert_tag :tag => 'a', :content => 'One picture', :attributes => { :href => /\/testuser\/gallery/ }
489 end 491 end
490 492
  493 + should 'show tags in index' do
  494 + article = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => ['tag1'])
  495 +
  496 + get :index, :profile => profile.identifier
  497 +
  498 + assert_tag :tag => 'a', :content => 'tag1', :attributes => { :href => /profile\/#{profile.identifier}\/tags\/tag1$/ }
  499 + end
  500 +
491 should 'show description of orgarnization' do 501 should 'show description of orgarnization' do
492 login_as(@profile.identifier) 502 login_as(@profile.identifier)
493 ent = fast_create(Enterprise) 503 ent = fast_create(Enterprise)
@@ -1057,8 +1067,16 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1057,8 +1067,16 @@ class ProfileControllerTest &lt; ActionController::TestCase
1057 atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id) 1067 atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id)
1058 get :index, :profile => person.identifier 1068 get :index, :profile => person.identifier
1059 assert_no_tag :tag => 'div', :attributes => {:id => 'profile-network'} 1069 assert_no_tag :tag => 'div', :attributes => {:id => 'profile-network'}
  1070 + end
  1071 +
  1072 + should "show the network activity if the viewer follows the profile" do
  1073 + login_as(profile.identifier)
  1074 + person = fast_create(Person)
  1075 + at = fast_create(ActionTracker::Record, :user_id => person.id)
  1076 + atn = fast_create(ActionTrackerNotification, :profile_id => profile.id, :action_tracker_id => at.id)
1060 1077
1061 person.add_friend(profile) 1078 person.add_friend(profile)
  1079 + profile.add_friend(person)
1062 get :index, :profile => person.identifier 1080 get :index, :profile => person.identifier
1063 assert_tag :tag => 'div', :attributes => {:id => 'profile-network'} 1081 assert_tag :tag => 'div', :attributes => {:id => 'profile-network'}
1064 end 1082 end
@@ -1077,8 +1095,16 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1077,8 +1095,16 @@ class ProfileControllerTest &lt; ActionController::TestCase
1077 scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id) 1095 scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id)
1078 get :index, :profile => person.identifier 1096 get :index, :profile => person.identifier
1079 assert_no_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } 1097 assert_no_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} }
  1098 + end
  1099 +
  1100 + should "show the scrap area on wall if the user follows the user" do
  1101 + login_as(profile.identifier)
  1102 + person = fast_create(Person)
  1103 + scrap = fast_create(Scrap, :sender_id => person.id, :receiver_id => profile.id)
1080 1104
1081 person.add_friend(profile) 1105 person.add_friend(profile)
  1106 + profile.add_friend(person)
  1107 +
1082 get :index, :profile => person.identifier 1108 get :index, :profile => person.identifier
1083 assert_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} } 1109 assert_tag :tag => 'div', :attributes => {:id => 'leave_scrap'}, :descendant => { :tag => 'input', :attributes => {:value => 'Share'} }
1084 end 1110 end
@@ -1449,9 +1475,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1449,9 +1475,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1449 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } } 1475 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } }
1450 viewed.save! 1476 viewed.save!
1451 get :index, :profile => viewed.identifier 1477 get :index, :profile => viewed.identifier
1452 - assert_tag :tag => 'td', :content => 'Sex:' 1478 + assert_tag :tag => 'td', :content => 'Sex'
1453 assert_tag :tag => 'td', :content => 'Male' 1479 assert_tag :tag => 'td', :content => 'Male'
1454 - assert_tag :tag => 'td', :content => 'Date of birth:' 1480 + assert_tag :tag => 'td', :content => 'Date of birth'
1455 assert_tag :tag => 'td', :content => 'August 26, 1990' 1481 assert_tag :tag => 'td', :content => 'August 26, 1990'
1456 end 1482 end
1457 1483
@@ -1463,9 +1489,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1463,9 +1489,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1463 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } 1489 viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } }
1464 viewed.save! 1490 viewed.save!
1465 get :index, :profile => viewed.identifier 1491 get :index, :profile => viewed.identifier
1466 - assert_tag :tag => 'td', :content => 'Sex:' 1492 + assert_tag :tag => 'td', :content => 'Sex'
1467 assert_tag :tag => 'td', :content => 'Male' 1493 assert_tag :tag => 'td', :content => 'Male'
1468 - assert_no_tag :tag => 'td', :content => 'Date of birth:' 1494 + assert_no_tag :tag => 'td', :content => 'Date of birth'
1469 assert_no_tag :tag => 'td', :content => 'August 26, 1990' 1495 assert_no_tag :tag => 'td', :content => 'August 26, 1990'
1470 end 1496 end
1471 1497
@@ -1479,9 +1505,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1479,9 +1505,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1479 strange = create_user('person_2').person 1505 strange = create_user('person_2').person
1480 login_as(strange.identifier) 1506 login_as(strange.identifier)
1481 get :index, :profile => viewed.identifier 1507 get :index, :profile => viewed.identifier
1482 - assert_tag :tag => 'td', :content => 'Sex:' 1508 + assert_tag :tag => 'td', :content => 'Sex'
1483 assert_tag :tag => 'td', :content => 'Male' 1509 assert_tag :tag => 'td', :content => 'Male'
1484 - assert_no_tag :tag => 'td', :content => 'Date of birth:' 1510 + assert_no_tag :tag => 'td', :content => 'Date of birth'
1485 assert_no_tag :tag => 'td', :content => 'August 26, 1990' 1511 assert_no_tag :tag => 'td', :content => 'August 26, 1990'
1486 end 1512 end
1487 1513
@@ -1496,9 +1522,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1496,9 +1522,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1496 Person.any_instance.stubs(:is_a_friend?).returns(true) 1522 Person.any_instance.stubs(:is_a_friend?).returns(true)
1497 login_as(friend.identifier) 1523 login_as(friend.identifier)
1498 get :index, :profile => viewed.identifier 1524 get :index, :profile => viewed.identifier
1499 - assert_tag :tag => 'td', :content => 'Sex:' 1525 + assert_tag :tag => 'td', :content => 'Sex'
1500 assert_tag :tag => 'td', :content => 'Male' 1526 assert_tag :tag => 'td', :content => 'Male'
1501 - assert_tag :tag => 'td', :content => 'Date of birth:' 1527 + assert_tag :tag => 'td', :content => 'Date of birth'
1502 assert_tag :tag => 'td', :content => 'August 26, 1990' 1528 assert_tag :tag => 'td', :content => 'August 26, 1990'
1503 end 1529 end
1504 1530
@@ -1511,9 +1537,9 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1511,9 +1537,9 @@ class ProfileControllerTest &lt; ActionController::TestCase
1511 viewed.save! 1537 viewed.save!
1512 login_as(viewed.identifier) 1538 login_as(viewed.identifier)
1513 get :index, :profile => viewed.identifier 1539 get :index, :profile => viewed.identifier
1514 - assert_tag :tag => 'td', :content => 'Sex:' 1540 + assert_tag :tag => 'td', :content => 'Sex'
1515 assert_tag :tag => 'td', :content => 'Male' 1541 assert_tag :tag => 'td', :content => 'Male'
1516 - assert_tag :tag => 'td', :content => 'Date of birth:' 1542 + assert_tag :tag => 'td', :content => 'Date of birth'
1517 assert_tag :tag => 'td', :content => 'August 26, 1990' 1543 assert_tag :tag => 'td', :content => 'August 26, 1990'
1518 end 1544 end
1519 1545
@@ -1526,7 +1552,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1526,7 +1552,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1526 login_as(strange.identifier) 1552 login_as(strange.identifier)
1527 get :index, :profile => viewed.identifier 1553 get :index, :profile => viewed.identifier
1528 assert_tag :tag => 'th', :content => 'Contact' 1554 assert_tag :tag => 'th', :content => 'Contact'
1529 - assert_tag :tag => 'td', :content => 'e-Mail:' 1555 + assert_tag :tag => 'td', :content => 'e-Mail'
1530 end 1556 end
1531 1557
1532 should 'show contact to friend' do 1558 should 'show contact to friend' do
@@ -1539,7 +1565,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1539,7 +1565,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1539 login_as(friend.identifier) 1565 login_as(friend.identifier)
1540 get :index, :profile => viewed.identifier 1566 get :index, :profile => viewed.identifier
1541 assert_tag :tag => 'th', :content => 'Contact' 1567 assert_tag :tag => 'th', :content => 'Contact'
1542 - assert_tag :tag => 'td', :content => 'e-Mail:' 1568 + assert_tag :tag => 'td', :content => 'e-Mail'
1543 end 1569 end
1544 1570
1545 should 'show contact to self' do 1571 should 'show contact to self' do
@@ -1550,7 +1576,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1550,7 +1576,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1550 login_as(viewed.identifier) 1576 login_as(viewed.identifier)
1551 get :index, :profile => viewed.identifier 1577 get :index, :profile => viewed.identifier
1552 assert_tag :tag => 'th', :content => 'Contact' 1578 assert_tag :tag => 'th', :content => 'Contact'
1553 - assert_tag :tag => 'td', :content => 'e-Mail:' 1579 + assert_tag :tag => 'td', :content => 'e-Mail'
1554 end 1580 end
1555 1581
1556 should 'not show contact to non friend' do 1582 should 'not show contact to non friend' do
@@ -1562,7 +1588,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1562,7 +1588,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1562 login_as(strange.identifier) 1588 login_as(strange.identifier)
1563 get :index, :profile => viewed.identifier 1589 get :index, :profile => viewed.identifier
1564 assert_no_tag :tag => 'th', :content => 'Contact' 1590 assert_no_tag :tag => 'th', :content => 'Contact'
1565 - assert_no_tag :tag => 'td', :content => 'e-Mail:' 1591 + assert_no_tag :tag => 'td', :content => 'e-Mail'
1566 end 1592 end
1567 1593
1568 should 'show contact to friend even if private' do 1594 should 'show contact to friend even if private' do
@@ -1575,7 +1601,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1575,7 +1601,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1575 login_as(friend.identifier) 1601 login_as(friend.identifier)
1576 get :index, :profile => viewed.identifier 1602 get :index, :profile => viewed.identifier
1577 assert_tag :tag => 'th', :content => 'Contact' 1603 assert_tag :tag => 'th', :content => 'Contact'
1578 - assert_tag :tag => 'td', :content => 'e-Mail:' 1604 + assert_tag :tag => 'td', :content => 'e-Mail'
1579 end 1605 end
1580 1606
1581 should 'show contact to self even if private' do 1607 should 'show contact to self even if private' do
@@ -1586,7 +1612,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1586,7 +1612,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1586 login_as(viewed.identifier) 1612 login_as(viewed.identifier)
1587 get :index, :profile => viewed.identifier 1613 get :index, :profile => viewed.identifier
1588 assert_tag :tag => 'th', :content => 'Contact' 1614 assert_tag :tag => 'th', :content => 'Contact'
1589 - assert_tag :tag => 'td', :content => 'e-Mail:' 1615 + assert_tag :tag => 'td', :content => 'e-Mail'
1590 end 1616 end
1591 1617
1592 should 'not display list of communities to manage on menu by default' do 1618 should 'not display list of communities to manage on menu by default' do
@@ -1694,22 +1720,28 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1694,22 +1720,28 @@ class ProfileControllerTest &lt; ActionController::TestCase
1694 1720
1695 should 'show enterprises field if enterprises are enabled on environment' do 1721 should 'show enterprises field if enterprises are enabled on environment' do
1696 person = fast_create(Person) 1722 person = fast_create(Person)
  1723 + enterprise = fast_create(Enterprise)
  1724 + enterprise.add_admin person
1697 environment = person.environment 1725 environment = person.environment
1698 environment.disable('disable_asset_enterprises') 1726 environment.disable('disable_asset_enterprises')
1699 environment.save! 1727 environment.save!
1700 1728
1701 get :index, :profile => person.identifier 1729 get :index, :profile => person.identifier
1702 - assert_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } 1730 + assert_tag :tag => 'td', :content => 'Enterprises'
  1731 + assert_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }}
1703 end 1732 end
1704 1733
1705 should 'not show enterprises field if enterprises are disabled on environment' do 1734 should 'not show enterprises field if enterprises are disabled on environment' do
1706 person = fast_create(Person) 1735 person = fast_create(Person)
  1736 + enterprise = fast_create(Enterprise)
  1737 + enterprise.add_admin person
1707 environment = person.environment 1738 environment = person.environment
1708 environment.enable('disable_asset_enterprises') 1739 environment.enable('disable_asset_enterprises')
1709 environment.save! 1740 environment.save!
1710 1741
1711 get :index, :profile => person.identifier 1742 get :index, :profile => person.identifier
1712 - assert_no_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } 1743 + assert_no_tag :tag => 'td', :content => 'Enterprises'
  1744 + assert_no_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }}
1713 end 1745 end
1714 1746
1715 end 1747 end
test/unit/profile_helper_test.rb
@@ -17,45 +17,55 @@ class ProfileHelperTest &lt; ActiveSupport::TestCase @@ -17,45 +17,55 @@ class ProfileHelperTest &lt; ActiveSupport::TestCase
17 self.stubs(:user).returns(nil) 17 self.stubs(:user).returns(nil)
18 profile.expects(:may_display_field_to?).returns(true) 18 profile.expects(:may_display_field_to?).returns(true)
19 profile.expects(:field).returns('value') 19 profile.expects(:field).returns('value')
20 - assert_match /Title.*value/, display_field('Title', profile, 'field') 20 + expects(:title).with(:field, anything).returns('Title')
  21 + assert_match /Title.*value/, display_field(:field)
21 end 22 end
22 23
23 should 'not display field if may not display it and not forced' do 24 should 'not display field if may not display it and not forced' do
24 self.stubs(:user).returns(nil) 25 self.stubs(:user).returns(nil)
25 profile.expects(:may_display_field_to?).returns(false) 26 profile.expects(:may_display_field_to?).returns(false)
26 - assert_equal '', display_field('Title', profile, 'field') 27 + profile.expects(:field).never
  28 + assert_equal '', display_field(:field)
27 end 29 end
28 30
29 should 'display field if may not display it but is forced' do 31 should 'display field if may not display it but is forced' do
30 self.stubs(:user).returns(nil) 32 self.stubs(:user).returns(nil)
31 profile.stubs(:may_display_field_to?).returns(false) 33 profile.stubs(:may_display_field_to?).returns(false)
  34 + profile.stubs(:kind_of?).with(Person).returns(:person)
  35 + FORCE.merge!({:person => [:field]})
32 profile.expects(:field).returns('value') 36 profile.expects(:field).returns('value')
33 - assert_match /Title.*value/, display_field('Title', profile, 'field', true) 37 + expects(:title).with(:field, anything).returns('Title')
  38 + assert_match /Title.*value/, display_field(:field)
34 end 39 end
35 40
36 should 'display work info if at least one of the fields should be displayed' do 41 should 'display work info if at least one of the fields should be displayed' do
37 self.stubs(:user).returns(nil) 42 self.stubs(:user).returns(nil)
38 profile.stubs(:may_display_field_to?).with(:organization, nil).returns(true) 43 profile.stubs(:may_display_field_to?).with(:organization, nil).returns(true)
39 profile.stubs(:may_display_field_to?).with(:organization_website, nil).returns(false) 44 profile.stubs(:may_display_field_to?).with(:organization_website, nil).returns(false)
  45 + profile.stubs(:may_display_field_to?).with(:professional_activity, nil).returns(false)
  46 + profile.stubs(:kind_of?).with(Person).returns(:person)
40 profile.expects(:organization).returns('Organization Name') 47 profile.expects(:organization).returns('Organization Name')
41 profile.expects(:organization_website).never 48 profile.expects(:organization_website).never
42 - assert_match /Work.*Organization Name/, display_work_info(profile) 49 + profile.expects(:professional_activity).never
  50 + assert_match /Work.*Organization Name/, display_work
43 end 51 end
44 52
45 should 'not display work info if none of the fields should be displayed' do 53 should 'not display work info if none of the fields should be displayed' do
46 self.stubs(:user).returns(nil) 54 self.stubs(:user).returns(nil)
47 profile.stubs(:may_display_field_to?).returns(false) 55 profile.stubs(:may_display_field_to?).returns(false)
  56 + profile.stubs(:kind_of?).with(Person).returns(:person)
48 profile.expects(:organization).never 57 profile.expects(:organization).never
49 profile.expects(:organization_website).never 58 profile.expects(:organization_website).never
50 - assert_equal '', display_work_info(profile) 59 + assert_equal '', display_work
51 end 60 end
52 61
53 should 'display work info if both fields should be displayed' do 62 should 'display work info if both fields should be displayed' do
54 self.stubs(:user).returns(nil) 63 self.stubs(:user).returns(nil)
55 profile.stubs(:may_display_field_to?).returns(true) 64 profile.stubs(:may_display_field_to?).returns(true)
  65 + profile.stubs(:kind_of?).with(Person).returns(:person)
56 profile.expects(:organization).returns('Organization Name') 66 profile.expects(:organization).returns('Organization Name')
57 profile.expects(:organization_website).returns('') 67 profile.expects(:organization_website).returns('')
58 - assert_match /Work.*Organization Name/, display_work_info(profile) 68 + assert_match /Work.*Organization Name/, display_work
59 end 69 end
60 70
61 end 71 end