Commit ab3a8f33c55384e5ae8b9e856a7c0c8310a301f5

Authored by Antonio Terceiro
2 parents ee3ac2ce 9abf114d

Merge branch 'stable'

@@ -59,7 +59,7 @@ Rake::PackageTask.new(Noosfero::PROJECT, Noosfero::VERSION) do |p| @@ -59,7 +59,7 @@ Rake::PackageTask.new(Noosfero::PROJECT, Noosfero::VERSION) do |p|
59 p.package_files.include('util/**/*') 59 p.package_files.include('util/**/*')
60 60
61 # external resources 61 # external resources
62 - p.package_files.include('vendor/**/*') 62 + p.package_files.include('vendor/plugins/**/*')
63 63
64 # exclusions 64 # exclusions
65 p.package_files.exclude('coverage/**/*') 65 p.package_files.exclude('coverage/**/*')
app/controllers/my_profile/cms_controller.rb
@@ -21,9 +21,9 @@ class CmsController < MyProfileController @@ -21,9 +21,9 @@ class CmsController < MyProfileController
21 def available_article_types 21 def available_article_types
22 articles = [ 22 articles = [
23 TinyMceArticle, 23 TinyMceArticle,
24 - TextileArticle,  
25 - Event 24 + TextileArticle
26 ] 25 ]
  26 + articles << Event unless profile.environment.enabled?(:disable_asset_events)
27 parent_id = params ? params[:parent_id] : nil 27 parent_id = params ? params[:parent_id] : nil
28 if !parent_id or !Article.find(parent_id).blog? 28 if !parent_id or !Article.find(parent_id).blog?
29 articles += [ 29 articles += [
app/controllers/my_profile/friends_controller.rb
@@ -74,10 +74,10 @@ class FriendsController &lt; MyProfileController @@ -74,10 +74,10 @@ class FriendsController &lt; MyProfileController
74 end 74 end
75 75
76 friend = User.find_by_email(friend_email) 76 friend = User.find_by_email(friend_email)
77 - if !friend.nil? && friend.person.person?  
78 - InviteFriend.create(:person => profile, :friend => friend.person)  
79 - else 77 + if friend.nil?
80 InviteFriend.create(:person => profile, :friend_name => friend_name, :friend_email => friend_email, :message => params[:message]) 78 InviteFriend.create(:person => profile, :friend_name => friend_name, :friend_email => friend_email, :message => params[:message])
  79 + elsif !friend.person.is_a_friend?(profile)
  80 + InviteFriend.create(:person => profile, :friend => friend.person)
81 end 81 end
82 end 82 end
83 83
app/helpers/display_helper.rb
@@ -2,7 +2,7 @@ module DisplayHelper @@ -2,7 +2,7 @@ module DisplayHelper
2 2
3 def link_to_product(product, opts={}) 3 def link_to_product(product, opts={})
4 return _('No product') unless product 4 return _('No product') unless product
5 - target = product.enterprise.enabled? ? product.enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url 5 + target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url
6 link_to content_tag( 'span', product.name ), 6 link_to content_tag( 'span', product.name ),
7 target, 7 target,
8 opts 8 opts
app/models/blog_archives_block.rb
@@ -22,7 +22,7 @@ class BlogArchivesBlock &lt; Block @@ -22,7 +22,7 @@ class BlogArchivesBlock &lt; Block
22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) 22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
23 results << "<ul class='#{year}-archive'>" 23 results << "<ul class='#{year}-archive'>"
24 results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month| 24 results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month|
25 - results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.generate_url(:controller => 'content_viewer', :action => 'view_page', :page => [owner.blog.path], :year => year, :month => month[0]))) 25 + results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.blog.url.merge(:year => year, :month => month[0])))
26 end 26 end
27 results << "</ul>" 27 results << "</ul>"
28 end 28 end
app/models/communities_block.rb
@@ -33,7 +33,7 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -33,7 +33,7 @@ class CommunitiesBlock &lt; ProfileListBlock
33 end 33 end
34 34
35 def profile_count 35 def profile_count
36 - owner.communities.count 36 + owner.communities(:public_profile => true).count
37 end 37 end
38 38
39 def profile_finder 39 def profile_finder
app/models/enterprises_block.rb
@@ -29,7 +29,7 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -29,7 +29,7 @@ class EnterprisesBlock &lt; ProfileListBlock
29 end 29 end
30 30
31 def profile_count 31 def profile_count
32 - owner.enterprises.count 32 + owner.enterprises(:public_profile => true).count
33 end 33 end
34 34
35 def profile_finder 35 def profile_finder
app/models/link_list_block.rb
@@ -49,15 +49,22 @@ class LinkListBlock &lt; Block @@ -49,15 +49,22 @@ class LinkListBlock &lt; Block
49 49
50 def link_html(link) 50 def link_html(link)
51 klass = 'icon-' + link[:icon] if link[:icon] 51 klass = 'icon-' + link[:icon] if link[:icon]
52 - link_to(link[:name], expand_address(link[:address]), :class => klass) 52 + sanitize_link(
  53 + link_to(link[:name], expand_address(link[:address]), :class => klass)
  54 + )
53 end 55 end
54 56
55 def expand_address(address) 57 def expand_address(address)
56 - if owner.respond_to?(:identifier) 58 + add = if owner.respond_to?(:identifier)
57 address.gsub('{profile}', owner.identifier) 59 address.gsub('{profile}', owner.identifier)
58 else 60 else
59 address 61 address
60 end 62 end
  63 + if add !~ /^[a-z]+:\/\// && add !~ /^\//
  64 + 'http://' + add
  65 + else
  66 + add
  67 + end
61 end 68 end
62 69
63 def editable? 70 def editable?
@@ -71,4 +78,10 @@ class LinkListBlock &lt; Block @@ -71,4 +78,10 @@ class LinkListBlock &lt; Block
71 end 78 end
72 end 79 end
73 80
  81 + private
  82 +
  83 + def sanitize_link(text)
  84 + sanitizer = HTML::WhiteListSanitizer.new
  85 + sanitizer.sanitize(text)
  86 + end
74 end 87 end
app/models/person.rb
@@ -128,14 +128,14 @@ class Person &lt; Profile @@ -128,14 +128,14 @@ class Person &lt; Profile
128 :select => 'profiles.*').uniq 128 :select => 'profiles.*').uniq
129 end 129 end
130 130
131 - def enterprise_memberships  
132 - memberships(:type => Enterprise.name) 131 + def enterprise_memberships(conditions = {})
  132 + memberships({:type => Enterprise.name}.merge(conditions))
133 end 133 end
134 134
135 alias :enterprises :enterprise_memberships 135 alias :enterprises :enterprise_memberships
136 136
137 - def community_memberships  
138 - memberships(:type => Community.name) 137 + def community_memberships(conditions = {})
  138 + memberships({:type => Community.name}.merge(conditions))
139 end 139 end
140 140
141 alias :communities :community_memberships 141 alias :communities :community_memberships
app/models/product.rb
@@ -60,7 +60,7 @@ class Product &lt; ActiveRecord::Base @@ -60,7 +60,7 @@ class Product &lt; ActiveRecord::Base
60 end 60 end
61 61
62 def url 62 def url
63 - enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => id) 63 + enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => id)
64 end 64 end
65 65
66 def public? 66 def public?
app/models/products_block.rb
@@ -25,7 +25,7 @@ class ProductsBlock &lt; Block @@ -25,7 +25,7 @@ class ProductsBlock &lt; Block
25 end 25 end
26 26
27 def footer 27 def footer
28 - link_to(_('View all products'), owner.generate_url(:controller => 'catalog', :action => 'index')) 28 + link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))
29 end 29 end
30 30
31 settings_items :product_ids, Array 31 settings_items :product_ids, Array
app/models/profile.rb
@@ -362,6 +362,8 @@ class Profile &lt; ActiveRecord::Base @@ -362,6 +362,8 @@ class Profile &lt; ActiveRecord::Base
362 Noosfero.url_options.merge(options) 362 Noosfero.url_options.merge(options)
363 end 363 end
364 364
  365 +private :generate_url, :url_options
  366 +
365 def default_hostname 367 def default_hostname
366 @default_hostname ||= (hostname || environment.default_hostname) 368 @default_hostname ||= (hostname || environment.default_hostname)
367 end 369 end
@@ -543,11 +545,12 @@ class Profile &lt; ActiveRecord::Base @@ -543,11 +545,12 @@ class Profile &lt; ActiveRecord::Base
543 def custom_header_expanded 545 def custom_header_expanded
544 header = custom_header 546 header = custom_header
545 if header 547 if header
546 - if self.respond_to?(:name) && header.include?('{name}')  
547 - header.gsub('{name}', self.name)  
548 - else  
549 - header 548 + %w[name short_name].each do |att|
  549 + if self.respond_to?(att) && header.include?("{#{att}}")
  550 + header.gsub!("{#{att}}", self.send(att))
  551 + end
550 end 552 end
  553 + header
551 end 554 end
552 end 555 end
553 556
app/models/tags_block.rb
@@ -24,7 +24,7 @@ class TagsBlock &lt; Block @@ -24,7 +24,7 @@ class TagsBlock &lt; Block
24 block_title(title) + 24 block_title(title) +
25 "\n<div class='tag_cloud'>\n"+ 25 "\n<div class='tag_cloud'>\n"+
26 tag_cloud( tags, :id, 26 tag_cloud( tags, :id,
27 - owner.generate_url(:controller => 'profile', :action => 'tag'), 27 + owner.public_profile_url.merge(:controller => 'profile', :action => 'tag'),
28 :max_size => 16, :min_size => 9 ) + 28 :max_size => 16, :min_size => 9 ) +
29 "\n</div><!-- end class='tag_cloud' -->\n"; 29 "\n</div><!-- end class='tag_cloud' -->\n";
30 end 30 end
app/models/uploaded_file.rb
@@ -50,7 +50,14 @@ class UploadedFile &lt; Article @@ -50,7 +50,14 @@ class UploadedFile &lt; Article
50 include ActionView::Helpers::TagHelper 50 include ActionView::Helpers::TagHelper
51 51
52 def to_html(options = {}) 52 def to_html(options = {})
53 - tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%') if image? 53 + if image?
  54 + tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%')
  55 + else
  56 + article = self
  57 + lambda do
  58 + content_tag('ul', content_tag('li', link_to(article.name, article.url, :class => article.css_class_name)))
  59 + end
  60 + end
54 end 61 end
55 62
56 def allow_children? 63 def allow_children?
app/views/profile_editor/index.rhtml
1 <div id="profile-editor-index"> 1 <div id="profile-editor-index">
2 2
3 <h1 class="block-title"> 3 <h1 class="block-title">
4 - <span class='control-panel-title'><%= profile.name %></span> 4 + <span class='control-panel-title'><%= profile.short_name %></span>
5 <span class='control-panel-sep'>&#150;</span> 5 <span class='control-panel-sep'>&#150;</span>
6 <span class='control-panel-subtitle'><%= _('Control Panel') %></span> 6 <span class='control-panel-subtitle'><%= _('Control Panel') %></span>
7 </h1> 7 </h1>
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 69) do 12 +ActiveRecord::Schema.define(:version => 71) do
13 13
14 create_table "article_versions", :force => true do |t| 14 create_table "article_versions", :force => true do |t|
15 t.integer "article_id" 15 t.integer "article_id"
@@ -59,7 +59,6 @@ ActiveRecord::Schema.define(:version =&gt; 69) do @@ -59,7 +59,6 @@ ActiveRecord::Schema.define(:version =&gt; 69) do
59 t.datetime "created_at" 59 t.datetime "created_at"
60 t.integer "last_changed_by_id" 60 t.integer "last_changed_by_id"
61 t.integer "version" 61 t.integer "version"
62 - t.integer "lock_version"  
63 t.string "type" 62 t.string "type"
64 t.integer "size" 63 t.integer "size"
65 t.string "content_type" 64 t.string "content_type"
@@ -253,6 +252,7 @@ ActiveRecord::Schema.define(:version =&gt; 69) do @@ -253,6 +252,7 @@ ActiveRecord::Schema.define(:version =&gt; 69) do
253 t.boolean "public_profile", :default => true 252 t.boolean "public_profile", :default => true
254 t.date "birth_date" 253 t.date "birth_date"
255 t.integer "preferred_domain_id" 254 t.integer "preferred_domain_id"
  255 + t.datetime "updated_at"
256 end 256 end
257 257
258 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" 258 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
lib/noosfero.rb
1 module Noosfero 1 module Noosfero
2 PROJECT = 'noosfero' 2 PROJECT = 'noosfero'
3 - VERSION = '0.19.3' 3 + VERSION = '0.19.4'
4 SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' 4 SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero'
5 5
6 def self.pattern_for_controllers_in_directory(dir) 6 def self.pattern_for_controllers_in_directory(dir)
public/images/icons-app/user_icon_size-big.png 0 → 100644

9.65 KB

public/images/icons-app/users_size-big.png 0 → 100644

15.2 KB

test/functional/cms_controller_test.rb
@@ -560,12 +560,12 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -560,12 +560,12 @@ class CmsControllerTest &lt; Test::Unit::TestCase
560 end 560 end
561 561
562 should 'not make enterprise homepage available to person' do 562 should 'not make enterprise homepage available to person' do
563 - @controller.stubs(:profile).returns(Person.new) 563 + @controller.stubs(:profile).returns(create_user('test_user').person)
564 assert_not_includes @controller.available_article_types, EnterpriseHomepage 564 assert_not_includes @controller.available_article_types, EnterpriseHomepage
565 end 565 end
566 566
567 should 'make enterprise homepage available to enterprises' do 567 should 'make enterprise homepage available to enterprises' do
568 - @controller.stubs(:profile).returns(Enterprise.new) 568 + @controller.stubs(:profile).returns(Enterprise.create(:name => 'test_ent', :identifier => 'test_ent'))
569 assert_includes @controller.available_article_types, EnterpriseHomepage 569 assert_includes @controller.available_article_types, EnterpriseHomepage
570 end 570 end
571 571
@@ -767,7 +767,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -767,7 +767,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
767 end 767 end
768 768
769 should 'not offer folder to blog articles' do 769 should 'not offer folder to blog articles' do
770 - @controller.stubs(:profile).returns(Enterprise.new) 770 + @controller.stubs(:profile).returns(Enterprise.create(:name => 'test_ent', :identifier => 'test_ent'))
771 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 771 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
772 @controller.stubs(:params).returns({ :parent_id => blog.id }) 772 @controller.stubs(:params).returns({ :parent_id => blog.id })
773 773
@@ -775,7 +775,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -775,7 +775,7 @@ class CmsControllerTest &lt; Test::Unit::TestCase
775 end 775 end
776 776
777 should 'not offer rssfeed to blog articles' do 777 should 'not offer rssfeed to blog articles' do
778 - @controller.stubs(:profile).returns(Enterprise.new) 778 + @controller.stubs(:profile).returns(Enterprise.create(:name => 'test_ent', :identifier => 'test_ent'))
779 blog = Blog.create!(:name => 'Blog for test', :profile => profile) 779 blog = Blog.create!(:name => 'Blog for test', :profile => profile)
780 @controller.stubs(:params).returns({ :parent_id => blog.id }) 780 @controller.stubs(:params).returns({ :parent_id => blog.id })
781 781
@@ -1137,4 +1137,15 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -1137,4 +1137,15 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1137 assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/upload_files?parent_id=#{profile.blog.id}"} 1137 assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/upload_files?parent_id=#{profile.blog.id}"}
1138 end 1138 end
1139 1139
  1140 + should 'not offer to create events if events is disabled' do
  1141 + e = profile.environment
  1142 + e.enable(:disable_asset_events)
  1143 + e.save!
  1144 +
  1145 + get :new, :profile => profile.identifier
  1146 +
  1147 +
  1148 + assert_not_includes assigns(:article_types).map{|at|at[:name]}, 'Event'
  1149 + end
  1150 +
1140 end 1151 end
test/functional/friends_controller_test.rb
@@ -157,4 +157,11 @@ class FriendsControllerTest &lt; Test::Unit::TestCase @@ -157,4 +157,11 @@ class FriendsControllerTest &lt; Test::Unit::TestCase
157 end 157 end
158 end 158 end
159 159
  160 + should 'not create InviteFriend if is a friend' do
  161 + friend = create_user('testfriend', :email => 'friend@noosfero.org')
  162 + friend.person.add_friend(profile)
  163 + assert_no_difference InviteFriend, :count do
  164 + post :invite, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :message => "click: <url>", :confirmation => 1, :wizard => true
  165 + end
  166 + end
160 end 167 end
test/functional/profile_editor_controller_test.rb
@@ -816,4 +816,20 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -816,4 +816,20 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
816 end 816 end
817 end 817 end
818 818
  819 + should 'show profile nickname on title' do
  820 + person = create_user('testuser', {}, :nickname => 'my nick').person
  821 + get :index, :profile => 'testuser'
  822 + assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => {
  823 + :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'my nick'
  824 + }
  825 + end
  826 +
  827 + should 'show profile name on title when no nickname' do
  828 + person = create_user('testuser').person
  829 + get :index, :profile => 'testuser'
  830 + assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => {
  831 + :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'testuser'
  832 + }
  833 + end
  834 +
819 end 835 end
test/functional/search_controller_test.rb
@@ -992,6 +992,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -992,6 +992,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase
992 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} 992 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'}
993 end 993 end
994 994
  995 + should 'find products when enterprises has own hostname' do
  996 + ent = Enterprise.create!(:name => 'teste', :identifier => 'teste')
  997 + ent.domains << Domain.new(:name => 'testent.com'); ent.save!
  998 + prod = ent.products.create!(:name => 'a beautiful product')
  999 + get 'index', :query => 'beautiful', :find_in => ['products']
  1000 + assert_includes assigns(:results)[:products], prod
  1001 + end
  1002 +
  1003 +
995 ################################################################## 1004 ##################################################################
996 ################################################################## 1005 ##################################################################
997 1006
test/unit/communities_block_test.rb
@@ -90,10 +90,10 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -90,10 +90,10 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
90 should 'count number of owner communities' do 90 should 'count number of owner communities' do
91 user = create_user('testuser').person 91 user = create_user('testuser').person
92 92
93 - community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default) 93 + community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
94 community1.add_member(user) 94 community1.add_member(user)
95 95
96 - community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default) 96 + community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => true)
97 community2.add_member(user) 97 community2.add_member(user)
98 98
99 block = CommunitiesBlock.new 99 block = CommunitiesBlock.new
@@ -102,4 +102,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -102,4 +102,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
102 assert_equal 2, block.profile_count 102 assert_equal 2, block.profile_count
103 end 103 end
104 104
  105 + should 'not count non-public communities' do
  106 + user = create_user('testuser').person
  107 +
  108 + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
  109 + community_public.add_member(user)
  110 +
  111 + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
  112 + community_private.add_member(user)
  113 +
  114 + block = CommunitiesBlock.new
  115 + block.expects(:owner).at_least_once.returns(user)
  116 +
  117 + assert_equal 1, block.profile_count
  118 + end
  119 +
105 end 120 end
test/unit/enterprises_block_test.rb
@@ -114,4 +114,21 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -114,4 +114,21 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
114 assert_equal 2, block.profile_count 114 assert_equal 2, block.profile_count
115 end 115 end
116 116
  117 + should 'not count non-public enterprises' do
  118 + user = create_user('testuser').person
  119 +
  120 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true)
  121 + ent1.expects(:closed?).returns(false)
  122 + ent1.add_member(user)
  123 +
  124 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default, :public_profile => false)
  125 + ent2.expects(:closed?).returns(false)
  126 + ent2.add_member(user)
  127 +
  128 + block = EnterprisesBlock.new
  129 + block.expects(:owner).at_least_once.returns(user)
  130 +
  131 + assert_equal 1, block.profile_count
  132 + end
  133 +
117 end 134 end
test/unit/link_list_block_test.rb
@@ -57,4 +57,21 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -57,4 +57,21 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
57 assert_no_match /class="/, l.link_html({:icon => nil, :name => 'test', :address => 'test.com'}) 57 assert_no_match /class="/, l.link_html({:icon => nil, :name => 'test', :address => 'test.com'})
58 end 58 end
59 59
  60 + should 'not add link to javascript' do
  61 + l = LinkListBlock.new(:links => [{:name => 'link', :address => "javascript:alert('Message test')"}])
  62 + assert_no_match /href="javascript/, l.link_html(l.links.first)
  63 + end
  64 +
  65 + should 'not add link to onclick' do
  66 + l = LinkListBlock.new(:links => [{:name => 'link', :address => "#\" onclick=\"alert(123456)"}])
  67 + assert_no_match /onclick/, l.link_html(l.links.first)
  68 + end
  69 +
  70 + should 'add http in front of incomplete external links' do
  71 + {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => 'http://example.org'}.each do |input, output|
  72 + l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}])
  73 + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => output}
  74 + end
  75 + end
  76 +
60 end 77 end
test/unit/product_test.rb
@@ -112,15 +112,12 @@ class ProductTest &lt; Test::Unit::TestCase @@ -112,15 +112,12 @@ class ProductTest &lt; Test::Unit::TestCase
112 should 'provide url' do 112 should 'provide url' do
113 product = Product.new 113 product = Product.new
114 114
115 - result = mock  
116 -  
117 enterprise = Enterprise.new 115 enterprise = Enterprise.new
118 - enterprise.expects(:generate_url).with(:controller => 'catalog', :action => 'show', :id => 999).returns(result) 116 + enterprise.expects(:public_profile_url).returns({})
119 117
120 product.expects(:id).returns(999) 118 product.expects(:id).returns(999)
121 product.expects(:enterprise).returns(enterprise) 119 product.expects(:enterprise).returns(enterprise)
122 -  
123 - assert_same result, product.url 120 + assert_equal({:controller => 'catalog', :action => 'show', :id => 999}, product.url)
124 end 121 end
125 122
126 should 'categorize also with product categorization' do 123 should 'categorize also with product categorization' do
test/unit/products_block_test.rb
@@ -123,4 +123,16 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -123,4 +123,16 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
123 end 123 end
124 end 124 end
125 125
  126 + should 'generate footer when enterprise has own hostname' do
  127 + enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise')
  128 + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!
  129 + enterprise.products.create!(:name => 'product one')
  130 + enterprise.products.create!(:name => 'product two')
  131 +
  132 + block.stubs(:owner).returns(enterprise)
  133 +
  134 + footer = block.footer
  135 +
  136 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  137 + end
126 end 138 end
test/unit/profile_test.rb
@@ -262,30 +262,18 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -262,30 +262,18 @@ class ProfileTest &lt; Test::Unit::TestCase
262 assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) 262 assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url)
263 end 263 end
264 264
265 - should 'generate URL' do  
266 - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)  
267 -  
268 - assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'friends' }, profile.generate_url(:controller => 'profile', :action => 'friends'))  
269 - end  
270 -  
271 - should 'provide URL options' do  
272 - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)  
273 -  
274 - assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options)  
275 - end  
276 -  
277 should "use own domain name instead of environment's for home page url" do 265 should "use own domain name instead of environment's for home page url" do
278 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) 266 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
279 profile.domains << Domain.new(:name => 'micojones.net') 267 profile.domains << Domain.new(:name => 'micojones.net')
280 assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) 268 assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url)
281 end 269 end
282 270
283 - should 'help developers by adding a suitable port to url options' do 271 + should 'help developers by adding a suitable port to url' do
284 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) 272 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
285 273
286 Noosfero.expects(:url_options).returns({ :port => 9999 }) 274 Noosfero.expects(:url_options).returns({ :port => 9999 })
287 275
288 - ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } 276 + ok('Profile#url_options must include port option when running in development mode') { profile.url[:port] == 9999 }
289 end 277 end
290 278
291 should 'help developers by adding a suitable port to url options for own domain urls' do 279 should 'help developers by adding a suitable port to url options for own domain urls' do
@@ -809,6 +797,18 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -809,6 +797,18 @@ class ProfileTest &lt; Test::Unit::TestCase
809 assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header_expanded 797 assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header_expanded
810 end 798 end
811 799
  800 + should 'provide custom header with nickname when use short_name variable' do
  801 + profile = Profile.new(:custom_header => 'Custom header of {short_name}', :name => 'Test', :nickname => 'Nickname test')
  802 + assert_equal 'Custom header of {short_name}', profile.custom_header
  803 + assert_equal 'Custom header of Nickname test', profile.custom_header_expanded
  804 + end
  805 +
  806 + should 'provide custom header with name when use short_name variable and no nickname' do
  807 + profile = Profile.new(:custom_header => 'Custom header of {short_name}', :name => 'Test')
  808 + assert_equal 'Custom header of {short_name}', profile.custom_header
  809 + assert_equal 'Custom header of Test', profile.custom_header_expanded
  810 + end
  811 +
812 should 'provide custom footer' do 812 should 'provide custom footer' do
813 assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer 813 assert_equal 'my custom footer', Profile.new(:custom_footer => 'my custom footer').custom_footer
814 end 814 end
test/unit/tags_block_test.rb
@@ -3,12 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,12 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class TagsBlockTest < Test::Unit::TestCase 3 class TagsBlockTest < Test::Unit::TestCase
4 4
5 def setup 5 def setup
6 - user = create_user('testinguser').person  
7 - user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!  
8 - user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!  
9 - user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! 6 + @user = create_user('testinguser').person
  7 + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!
  8 + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!
  9 + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save!
10 10
11 - box = Box.create!(:owner => user) 11 + box = Box.create!(:owner => @user)
12 @block = TagsBlock.create!(:box => box) 12 @block = TagsBlock.create!(:box => box)
13 end 13 end
14 attr_reader :block 14 attr_reader :block
@@ -32,4 +32,9 @@ class TagsBlockTest &lt; Test::Unit::TestCase @@ -32,4 +32,9 @@ class TagsBlockTest &lt; Test::Unit::TestCase
32 assert_equal '', block.content 32 assert_equal '', block.content
33 end 33 end
34 34
  35 + should 'generate links when profile has own hostname' do
  36 + @user.domains << Domain.new(:name => 'testuser.net'); @user.save!
  37 + assert_match /profile\/testinguser\/tag\/first-tag/, block.content
  38 + end
  39 +
35 end 40 end
test/unit/uploaded_file_test.rb
@@ -109,4 +109,14 @@ class UploadedFileTest &lt; Test::Unit::TestCase @@ -109,4 +109,14 @@ class UploadedFileTest &lt; Test::Unit::TestCase
109 assert_match /#{UploadedFile.max_size.to_humanreadable}/, up.errors[:size] 109 assert_match /#{UploadedFile.max_size.to_humanreadable}/, up.errors[:size]
110 end 110 end
111 111
  112 + should 'display link to download of non-image files' do
  113 + p = create_user('test_user').person
  114 + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => p)
  115 +
  116 + stubs(:content_tag)
  117 + expects(:link_to).with(file.name, file.url, :class => file.css_class_name)
  118 +
  119 + instance_eval(&file.to_html)
  120 + end
  121 +
112 end 122 end