Commit ad4f98b3445f288b5fa7be8fa3315481f73b3461
Exists in
master
and in
22 other branches
Merge branch 'stable'
Conflicts: app/helpers/profile_helper.rb app/views/content_viewer/_article_toolbar.rhtml app/views/profile/_common.rhtml app/views/profile/_organization_profile.rhtml app/views/profile/_person_profile.rhtml db/schema.rb public/stylesheets/application.css
Showing
9 changed files
with
91 additions
and
58 deletions
Show diff stats
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 < ActiveRecord::Base | @@ -13,6 +13,7 @@ class ExternalFeed < 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 < ActiveRecord::Migration | @@ -2,7 +2,10 @@ class AddSpamCommentsCounterCacheToArticles < 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 < ActiveRecord::Migration | @@ -4,8 +4,10 @@ class CreateRealRelationBetweenArticleAndAuthor < 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" |
test/functional/profile_controller_test.rb
@@ -98,8 +98,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -98,8 +98,9 @@ class ProfileControllerTest < 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 < ActionController::TestCase | @@ -221,6 +222,7 @@ class ProfileControllerTest < 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 < ActionController::TestCase | @@ -488,6 +490,14 @@ class ProfileControllerTest < 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 < ActionController::TestCase | @@ -1057,8 +1067,16 @@ class ProfileControllerTest < 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 < ActionController::TestCase | @@ -1077,8 +1095,16 @@ class ProfileControllerTest < 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 |
@@ -1438,9 +1464,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1438,9 +1464,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
1438 | viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } } | 1464 | viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public', 'birth_date' => 'public' } } |
1439 | viewed.save! | 1465 | viewed.save! |
1440 | get :index, :profile => viewed.identifier | 1466 | get :index, :profile => viewed.identifier |
1441 | - assert_tag :tag => 'td', :content => 'Sex:' | 1467 | + assert_tag :tag => 'td', :content => 'Sex' |
1442 | assert_tag :tag => 'td', :content => 'Male' | 1468 | assert_tag :tag => 'td', :content => 'Male' |
1443 | - assert_tag :tag => 'td', :content => 'Date of birth:' | 1469 | + assert_tag :tag => 'td', :content => 'Date of birth' |
1444 | assert_tag :tag => 'td', :content => 'August 26, 1990' | 1470 | assert_tag :tag => 'td', :content => 'August 26, 1990' |
1445 | end | 1471 | end |
1446 | 1472 | ||
@@ -1452,9 +1478,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1452,9 +1478,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
1452 | viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } | 1478 | viewed.data = { :sex => 'male', :fields_privacy => { 'sex' => 'public' } } |
1453 | viewed.save! | 1479 | viewed.save! |
1454 | get :index, :profile => viewed.identifier | 1480 | get :index, :profile => viewed.identifier |
1455 | - assert_tag :tag => 'td', :content => 'Sex:' | 1481 | + assert_tag :tag => 'td', :content => 'Sex' |
1456 | assert_tag :tag => 'td', :content => 'Male' | 1482 | assert_tag :tag => 'td', :content => 'Male' |
1457 | - assert_no_tag :tag => 'td', :content => 'Date of birth:' | 1483 | + assert_no_tag :tag => 'td', :content => 'Date of birth' |
1458 | assert_no_tag :tag => 'td', :content => 'August 26, 1990' | 1484 | assert_no_tag :tag => 'td', :content => 'August 26, 1990' |
1459 | end | 1485 | end |
1460 | 1486 | ||
@@ -1468,9 +1494,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1468,9 +1494,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
1468 | strange = create_user('person_2').person | 1494 | strange = create_user('person_2').person |
1469 | login_as(strange.identifier) | 1495 | login_as(strange.identifier) |
1470 | get :index, :profile => viewed.identifier | 1496 | get :index, :profile => viewed.identifier |
1471 | - assert_tag :tag => 'td', :content => 'Sex:' | 1497 | + assert_tag :tag => 'td', :content => 'Sex' |
1472 | assert_tag :tag => 'td', :content => 'Male' | 1498 | assert_tag :tag => 'td', :content => 'Male' |
1473 | - assert_no_tag :tag => 'td', :content => 'Date of birth:' | 1499 | + assert_no_tag :tag => 'td', :content => 'Date of birth' |
1474 | assert_no_tag :tag => 'td', :content => 'August 26, 1990' | 1500 | assert_no_tag :tag => 'td', :content => 'August 26, 1990' |
1475 | end | 1501 | end |
1476 | 1502 | ||
@@ -1485,9 +1511,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1485,9 +1511,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
1485 | Person.any_instance.stubs(:is_a_friend?).returns(true) | 1511 | Person.any_instance.stubs(:is_a_friend?).returns(true) |
1486 | login_as(friend.identifier) | 1512 | login_as(friend.identifier) |
1487 | get :index, :profile => viewed.identifier | 1513 | get :index, :profile => viewed.identifier |
1488 | - assert_tag :tag => 'td', :content => 'Sex:' | 1514 | + assert_tag :tag => 'td', :content => 'Sex' |
1489 | assert_tag :tag => 'td', :content => 'Male' | 1515 | assert_tag :tag => 'td', :content => 'Male' |
1490 | - assert_tag :tag => 'td', :content => 'Date of birth:' | 1516 | + assert_tag :tag => 'td', :content => 'Date of birth' |
1491 | assert_tag :tag => 'td', :content => 'August 26, 1990' | 1517 | assert_tag :tag => 'td', :content => 'August 26, 1990' |
1492 | end | 1518 | end |
1493 | 1519 | ||
@@ -1500,9 +1526,9 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1500,9 +1526,9 @@ class ProfileControllerTest < ActionController::TestCase | ||
1500 | viewed.save! | 1526 | viewed.save! |
1501 | login_as(viewed.identifier) | 1527 | login_as(viewed.identifier) |
1502 | get :index, :profile => viewed.identifier | 1528 | get :index, :profile => viewed.identifier |
1503 | - assert_tag :tag => 'td', :content => 'Sex:' | 1529 | + assert_tag :tag => 'td', :content => 'Sex' |
1504 | assert_tag :tag => 'td', :content => 'Male' | 1530 | assert_tag :tag => 'td', :content => 'Male' |
1505 | - assert_tag :tag => 'td', :content => 'Date of birth:' | 1531 | + assert_tag :tag => 'td', :content => 'Date of birth' |
1506 | assert_tag :tag => 'td', :content => 'August 26, 1990' | 1532 | assert_tag :tag => 'td', :content => 'August 26, 1990' |
1507 | end | 1533 | end |
1508 | 1534 | ||
@@ -1515,7 +1541,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1515,7 +1541,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1515 | login_as(strange.identifier) | 1541 | login_as(strange.identifier) |
1516 | get :index, :profile => viewed.identifier | 1542 | get :index, :profile => viewed.identifier |
1517 | assert_tag :tag => 'th', :content => 'Contact' | 1543 | assert_tag :tag => 'th', :content => 'Contact' |
1518 | - assert_tag :tag => 'td', :content => 'e-Mail:' | 1544 | + assert_tag :tag => 'td', :content => 'e-Mail' |
1519 | end | 1545 | end |
1520 | 1546 | ||
1521 | should 'show contact to friend' do | 1547 | should 'show contact to friend' do |
@@ -1528,7 +1554,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1528,7 +1554,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1528 | login_as(friend.identifier) | 1554 | login_as(friend.identifier) |
1529 | get :index, :profile => viewed.identifier | 1555 | get :index, :profile => viewed.identifier |
1530 | assert_tag :tag => 'th', :content => 'Contact' | 1556 | assert_tag :tag => 'th', :content => 'Contact' |
1531 | - assert_tag :tag => 'td', :content => 'e-Mail:' | 1557 | + assert_tag :tag => 'td', :content => 'e-Mail' |
1532 | end | 1558 | end |
1533 | 1559 | ||
1534 | should 'show contact to self' do | 1560 | should 'show contact to self' do |
@@ -1539,7 +1565,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1539,7 +1565,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1539 | login_as(viewed.identifier) | 1565 | login_as(viewed.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 'not show contact to non friend' do | 1571 | should 'not show contact to non friend' do |
@@ -1551,7 +1577,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1551,7 +1577,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1551 | login_as(strange.identifier) | 1577 | login_as(strange.identifier) |
1552 | get :index, :profile => viewed.identifier | 1578 | get :index, :profile => viewed.identifier |
1553 | assert_no_tag :tag => 'th', :content => 'Contact' | 1579 | assert_no_tag :tag => 'th', :content => 'Contact' |
1554 | - assert_no_tag :tag => 'td', :content => 'e-Mail:' | 1580 | + assert_no_tag :tag => 'td', :content => 'e-Mail' |
1555 | end | 1581 | end |
1556 | 1582 | ||
1557 | should 'show contact to friend even if private' do | 1583 | should 'show contact to friend even if private' do |
@@ -1564,7 +1590,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1564,7 +1590,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1564 | login_as(friend.identifier) | 1590 | login_as(friend.identifier) |
1565 | get :index, :profile => viewed.identifier | 1591 | get :index, :profile => viewed.identifier |
1566 | assert_tag :tag => 'th', :content => 'Contact' | 1592 | assert_tag :tag => 'th', :content => 'Contact' |
1567 | - assert_tag :tag => 'td', :content => 'e-Mail:' | 1593 | + assert_tag :tag => 'td', :content => 'e-Mail' |
1568 | end | 1594 | end |
1569 | 1595 | ||
1570 | should 'show contact to self even if private' do | 1596 | should 'show contact to self even if private' do |
@@ -1575,7 +1601,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1575,7 +1601,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
1575 | login_as(viewed.identifier) | 1601 | login_as(viewed.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 'not display list of communities to manage on menu by default' do | 1607 | should 'not display list of communities to manage on menu by default' do |
@@ -1683,22 +1709,28 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1683,22 +1709,28 @@ class ProfileControllerTest < ActionController::TestCase | ||
1683 | 1709 | ||
1684 | should 'show enterprises field if enterprises are enabled on environment' do | 1710 | should 'show enterprises field if enterprises are enabled on environment' do |
1685 | person = fast_create(Person) | 1711 | person = fast_create(Person) |
1712 | + enterprise = fast_create(Enterprise) | ||
1713 | + enterprise.add_admin person | ||
1686 | environment = person.environment | 1714 | environment = person.environment |
1687 | environment.disable('disable_asset_enterprises') | 1715 | environment.disable('disable_asset_enterprises') |
1688 | environment.save! | 1716 | environment.save! |
1689 | 1717 | ||
1690 | get :index, :profile => person.identifier | 1718 | get :index, :profile => person.identifier |
1691 | - assert_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } | 1719 | + assert_tag :tag => 'td', :content => 'Enterprises' |
1720 | + assert_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }} | ||
1692 | end | 1721 | end |
1693 | 1722 | ||
1694 | should 'not show enterprises field if enterprises are disabled on environment' do | 1723 | should 'not show enterprises field if enterprises are disabled on environment' do |
1695 | person = fast_create(Person) | 1724 | person = fast_create(Person) |
1725 | + enterprise = fast_create(Enterprise) | ||
1726 | + enterprise.add_admin person | ||
1696 | environment = person.environment | 1727 | environment = person.environment |
1697 | environment.enable('disable_asset_enterprises') | 1728 | environment.enable('disable_asset_enterprises') |
1698 | environment.save! | 1729 | environment.save! |
1699 | 1730 | ||
1700 | get :index, :profile => person.identifier | 1731 | get :index, :profile => person.identifier |
1701 | - assert_no_tag :tag => 'tr', :attributes => { :id => "person-profile-network-enterprises" } | 1732 | + assert_no_tag :tag => 'td', :content => 'Enterprises' |
1733 | + assert_no_tag :tag => 'td', :descendant => { :tag => 'a', :content => /#{person.enterprises.count}/, :attributes => { :href => /profile\/#{person.identifier}\/enterprises$/ }} | ||
1702 | end | 1734 | end |
1703 | 1735 | ||
1704 | end | 1736 | end |
test/unit/profile_helper_test.rb
@@ -17,45 +17,55 @@ class ProfileHelperTest < ActiveSupport::TestCase | @@ -17,45 +17,55 @@ class ProfileHelperTest < 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 |