Commit 753770b353db3d018fdb554f9cee414f4f590c49

Authored by Weblate
2 parents 95cb82f9 e568ca79

Merge remote-tracking branch 'origin/master'

Showing 92 changed files with 910 additions and 794 deletions   Show diff stats
app/helpers/application_helper.rb
@@ -48,6 +48,8 @@ module ApplicationHelper @@ -48,6 +48,8 @@ module ApplicationHelper
48 48
49 include PluginsHelper 49 include PluginsHelper
50 50
  51 + include ButtonsHelper
  52 +
51 def locale 53 def locale
52 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale 54 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
53 end 55 end
@@ -209,52 +211,6 @@ module ApplicationHelper @@ -209,52 +211,6 @@ module ApplicationHelper
209 result 211 result
210 end 212 end
211 213
212 - def button(type, label, url, html_options = {})  
213 - html_options ||= {}  
214 - the_class = 'with-text'  
215 - if html_options.has_key?(:class)  
216 - the_class << ' ' << html_options[:class]  
217 - end  
218 - button_without_text type, label, url, html_options.merge(:class => the_class)  
219 - end  
220 -  
221 - def button_without_text(type, label, url, html_options = {})  
222 - the_class = "button icon-#{type}"  
223 - if html_options.has_key?(:class)  
224 - the_class << ' ' << html_options[:class]  
225 - end  
226 - the_title = html_options[:title] || label  
227 - if html_options[:disabled]  
228 - content_tag('a', '&nbsp;'+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title))  
229 - else  
230 - link_to('&nbsp;'+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title))  
231 - end  
232 - end  
233 -  
234 - def button_to_function(type, label, js_code, html_options = {}, &block)  
235 - html_options[:class] = "button with-text" unless html_options[:class]  
236 - html_options[:class] << " icon-#{type}"  
237 - link_to_function(label, js_code, html_options, &block)  
238 - end  
239 -  
240 - def button_to_function_without_text(type, label, js_code, html_options = {}, &block)  
241 - html_options[:class] = "" unless html_options[:class]  
242 - html_options[:class] << " button icon-#{type}"  
243 - link_to_function(content_tag('span', label), js_code, html_options, &block)  
244 - end  
245 -  
246 - def button_to_remote(type, label, options, html_options = {})  
247 - html_options[:class] = "button with-text" unless html_options[:class]  
248 - html_options[:class] << " icon-#{type}"  
249 - link_to_remote(label, options, html_options)  
250 - end  
251 -  
252 - def button_to_remote_without_text(type, label, options, html_options = {})  
253 - html_options[:class] = "" unless html_options[:class]  
254 - html_options[:class] << " button icon-#{type}"  
255 - link_to_remote(content_tag('span', label), options, html_options.merge(:title => label))  
256 - end  
257 -  
258 def icon(icon_name, html_options = {}) 214 def icon(icon_name, html_options = {})
259 the_class = "button #{icon_name}" 215 the_class = "button #{icon_name}"
260 if html_options.has_key?(:class) 216 if html_options.has_key?(:class)
@@ -934,13 +890,6 @@ module ApplicationHelper @@ -934,13 +890,6 @@ module ApplicationHelper
934 content_for(:head) { stylesheet_link_tag(*args) } 890 content_for(:head) { stylesheet_link_tag(*args) }
935 end 891 end
936 892
937 - def article_to_html(article, options = {})  
938 - options.merge!(:page => params[:npage])  
939 - content = article.to_html(options)  
940 - content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe  
941 - filter_html(content, article)  
942 - end  
943 -  
944 # Please, use link_to by default! 893 # Please, use link_to by default!
945 # This method was created to work around to inexplicable 894 # This method was created to work around to inexplicable
946 # chain of problems when display_short_format was called 895 # chain of problems when display_short_format was called
@@ -1365,16 +1314,6 @@ module ApplicationHelper @@ -1365,16 +1314,6 @@ module ApplicationHelper
1365 @no_design_blocks = true 1314 @no_design_blocks = true
1366 end 1315 end
1367 1316
1368 - def filter_html(html, source)  
1369 - if @plugins && source && source.has_macro?  
1370 - html = convert_macro(html, source) unless @plugins.enabled_macros.blank?  
1371 - #TODO This parse should be done through the macro infra, but since there  
1372 - # are old things that do not support it we are keeping this hot spot.  
1373 - html = @plugins.pipeline(:parse_content, html, source).first  
1374 - end  
1375 - html && html.html_safe  
1376 - end  
1377 -  
1378 def convert_macro(html, source) 1317 def convert_macro(html, source)
1379 doc = Nokogiri::HTML.fragment html 1318 doc = Nokogiri::HTML.fragment html
1380 #TODO This way is more efficient but do not support macro inside of 1319 #TODO This way is more efficient but do not support macro inside of
app/helpers/article_helper.rb
@@ -181,4 +181,21 @@ module ArticleHelper @@ -181,4 +181,21 @@ module ArticleHelper
181 end 181 end
182 end 182 end
183 183
  184 + def filter_html(html, source)
  185 + if @plugins && source && source.has_macro?
  186 + html = convert_macro(html, source) unless @plugins.enabled_macros.blank?
  187 + #TODO This parse should be done through the macro infra, but since there
  188 + # are old things that do not support it we are keeping this hot spot.
  189 + html = @plugins.pipeline(:parse_content, html, source).first
  190 + end
  191 + html && html.html_safe
  192 + end
  193 +
  194 + def article_to_html(article, options = {})
  195 + options.merge!(:page => params[:npage])
  196 + content = article.to_html(options)
  197 + content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe
  198 + filter_html(content, article)
  199 + end
  200 +
184 end 201 end
app/helpers/boxes_helper.rb
@@ -87,10 +87,30 @@ module BoxesHelper @@ -87,10 +87,30 @@ module BoxesHelper
87 box_decorator == DontMoveBlocks 87 box_decorator == DontMoveBlocks
88 end 88 end
89 89
90 - def display_block_content(block, person, main_content = nil)  
91 - content = block.main? ? wrap_main_content(main_content) : block.content({:person => person}) 90 + def render_block_content(block)
  91 + template_name = block.class.name.underscore.gsub('_block', '')
  92 + template_filename = "#{template_name}.html.erb"
  93 + if File.exists? Rails.root.join('app', 'views', 'blocks', template_filename)
  94 + render :file => "blocks/#{template_name}", :locals => { :block => block }
  95 + else
  96 + nil
  97 + end
  98 + end
  99 +
  100 + def render_block_footer(block)
  101 + template_name = block.class.name.underscore.gsub('_block', '')
  102 + template_filename = "#{template_name}.html.erb"
  103 + if File.exists? Rails.root.join('app', 'views', 'blocks', 'footers', template_filename)
  104 + render :file => "blocks/footers/#{template_name}", :locals => { :block => block }
  105 + else
  106 + nil
  107 + end
  108 + end
  109 +
  110 + def display_block_content(block, main_content = nil)
  111 + content = block.main? ? wrap_main_content(main_content) : render_block_content(block)
92 result = extract_block_content(content) 112 result = extract_block_content(content)
93 - footer_content = extract_block_content(block.footer) 113 + footer_content = extract_block_content(render_block_footer(block))
94 unless footer_content.blank? 114 unless footer_content.blank?
95 footer_content = content_tag('div', footer_content, :class => 'block-footer-content' ) 115 footer_content = content_tag('div', footer_content, :class => 'block-footer-content' )
96 end 116 end
app/helpers/buttons_helper.rb 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +module ButtonsHelper
  2 + def button(type, label, url, html_options = {})
  3 + html_options ||= {}
  4 + the_class = 'with-text'
  5 + if html_options.has_key?(:class)
  6 + the_class << ' ' << html_options[:class]
  7 + end
  8 + button_without_text type, label, url, html_options.merge(:class => the_class)
  9 + end
  10 +
  11 + def button_without_text(type, label, url, html_options = {})
  12 + the_class = "button icon-#{type}"
  13 + if html_options.has_key?(:class)
  14 + the_class << ' ' << html_options[:class]
  15 + end
  16 + the_title = html_options[:title] || label
  17 + if html_options[:disabled]
  18 + content_tag('a', '&nbsp;'+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title))
  19 + else
  20 + link_to('&nbsp;'+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title))
  21 + end
  22 + end
  23 +
  24 + def button_to_function(type, label, js_code, html_options = {}, &block)
  25 + html_options[:class] = "button with-text" unless html_options[:class]
  26 + html_options[:class] << " icon-#{type}"
  27 + link_to_function(label, js_code, html_options, &block)
  28 + end
  29 +
  30 + def button_to_function_without_text(type, label, js_code, html_options = {}, &block)
  31 + html_options[:class] = "" unless html_options[:class]
  32 + html_options[:class] << " button icon-#{type}"
  33 + link_to_function(content_tag('span', label), js_code, html_options, &block)
  34 + end
  35 +
  36 + def button_to_remote(type, label, options, html_options = {})
  37 + html_options[:class] = "button with-text" unless html_options[:class]
  38 + html_options[:class] << " icon-#{type}"
  39 + link_to_remote(label, options, html_options)
  40 + end
  41 +
  42 + def button_to_remote_without_text(type, label, options, html_options = {})
  43 + html_options[:class] = "" unless html_options[:class]
  44 + html_options[:class] << " button icon-#{type}"
  45 + link_to_remote(content_tag('span', label), options, html_options.merge(:title => label))
  46 + end
  47 +end
app/models/article_block.rb
@@ -18,18 +18,6 @@ class ArticleBlock &lt; Block @@ -18,18 +18,6 @@ class ArticleBlock &lt; Block
18 _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.') 18 _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.')
19 end 19 end
20 20
21 - def content(args={})  
22 - block = self  
23 - proc do  
24 - block_title(block.title) +  
25 - (block.article ? article_to_html(FilePresenter.for(block.article),  
26 - :gallery_view => false,  
27 - :inside_block => block, # For Blogs and folders  
28 - :format => block.visualization_format # For Articles and contents  
29 - ).html_safe : _('Article not selected yet.'))  
30 - end  
31 - end  
32 -  
33 def article_id 21 def article_id
34 self.settings[:article_id] 22 self.settings[:article_id]
35 end 23 end
app/models/blog.rb
@@ -93,4 +93,20 @@ class Blog &lt; Folder @@ -93,4 +93,20 @@ class Blog &lt; Folder
93 posts.where("type != 'RssFeed'").order(:updated_at).limit(limit) 93 posts.where("type != 'RssFeed'").order(:updated_at).limit(limit)
94 end 94 end
95 95
  96 + def total_number_of_posts(group_by, year = nil)
  97 + case group_by
  98 + when :by_year
  99 + posts.published.native_translations
  100 + .except(:order)
  101 + .count(:all, :group => 'EXTRACT(YEAR FROM published_at)')
  102 + .sort_by {|year, count| -year.to_i}
  103 + when :by_month
  104 + posts.published.native_translations
  105 + .except(:order)
  106 + .where('EXTRACT(YEAR FROM published_at)=?', year.to_i)
  107 + .group('EXTRACT(MONTH FROM published_at)')
  108 + .count
  109 + .sort_by {|month, count| -month.to_i}
  110 + end
  111 + end
96 end 112 end
app/models/blog_archives_block.rb
@@ -21,30 +21,6 @@ class BlogArchivesBlock &lt; Block @@ -21,30 +21,6 @@ class BlogArchivesBlock &lt; Block
21 blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog 21 blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog
22 end 22 end
23 23
24 - def visible_posts(person)  
25 - #FIXME Performance issues with display_to. Must convert it to a scope.  
26 - # Checkout this page for further information: http://noosfero.org/Development/ActionItem2705  
27 - blog.posts.published.native_translations #.select {|post| post.display_to?(person)}  
28 - end  
29 -  
30 - def content(args={})  
31 - owner_blog = self.blog  
32 - return nil unless owner_blog  
33 - results = ''  
34 - posts = visible_posts(args[:person])  
35 - posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count|  
36 - results << content_tag('li', content_tag('strong', "#{year.to_i} (#{count})"))  
37 - results << "<ul class='#{year.to_i}-archive'>"  
38 - posts.except(:order).where('EXTRACT(YEAR FROM published_at)=?', year.to_i).group('EXTRACT(MONTH FROM published_at)').count.sort_by {|month, count| -month.to_i}.each do |month, count|  
39 - results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(year: year.to_i, month: month.to_i)))  
40 - end  
41 - results << "</ul>"  
42 - end  
43 - block_title(title) +  
44 - content_tag('ul', results, :class => 'blog-archives') +  
45 - content_tag('div', link_to(_('Subscribe RSS Feed'), owner_blog.feed.url), :class => 'subscribe-feed')  
46 - end  
47 -  
48 def self.expire_on 24 def self.expire_on
49 { :profile => [:article], :environment => [:article] } 25 { :profile => [:article], :environment => [:article] }
50 end 26 end
app/models/categories_block.rb
@@ -30,13 +30,6 @@ class CategoriesBlock &lt; Block @@ -30,13 +30,6 @@ class CategoriesBlock &lt; Block
30 Category.top_level_for(self.owner).from_types(self.category_types) 30 Category.top_level_for(self.owner).from_types(self.category_types)
31 end 31 end
32 32
33 - def content(args={})  
34 - block = self  
35 - proc do  
36 - render :file => 'blocks/categories', :locals => { :block => block }  
37 - end  
38 - end  
39 -  
40 def self.expire_on 33 def self.expire_on
41 { :profile => [], :environment => [:category] } 34 { :profile => [], :environment => [:category] }
42 end 35 end
app/models/communities_block.rb
@@ -27,15 +27,6 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -27,15 +27,6 @@ class CommunitiesBlock &lt; ProfileListBlock
27 owner.profile_suggestions.of_community.enabled.limit(3).includes(:suggestion) 27 owner.profile_suggestions.of_community.enabled.limit(3).includes(:suggestion)
28 end 28 end
29 29
30 - def footer  
31 - owner = self.owner  
32 - suggestions = self.suggestions  
33 - return '' unless owner.kind_of?(Profile) || owner.kind_of?(Environment)  
34 - proc do  
35 - render :file => 'blocks/communities', :locals => { :owner => owner, :suggestions => suggestions }  
36 - end  
37 - end  
38 -  
39 def profiles 30 def profiles
40 owner.communities 31 owner.communities
41 end 32 end
app/models/disabled_enterprise_message_block.rb
@@ -12,13 +12,6 @@ class DisabledEnterpriseMessageBlock &lt; Block @@ -12,13 +12,6 @@ class DisabledEnterpriseMessageBlock &lt; Block
12 _('Message') 12 _('Message')
13 end 13 end
14 14
15 - def content(args={})  
16 - message = self.owner.environment.message_for_disabled_enterprise || ''  
17 - lambda do |_|  
18 - render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message}  
19 - end  
20 - end  
21 -  
22 def editable?(user=nil) 15 def editable?(user=nil)
23 false 16 false
24 end 17 end
app/models/enterprises_block.rb
@@ -12,22 +12,6 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -12,22 +12,6 @@ class EnterprisesBlock &lt; ProfileListBlock
12 _('Enterprises') 12 _('Enterprises')
13 end 13 end
14 14
15 - def footer  
16 - owner = self.owner  
17 - case owner  
18 - when Profile  
19 - proc do  
20 - link_to s_('enterprises|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'  
21 - end  
22 - when Environment  
23 - proc do  
24 - link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'  
25 - end  
26 - else  
27 - ''  
28 - end  
29 - end  
30 -  
31 def profiles 15 def profiles
32 owner.enterprises 16 owner.enterprises
33 end 17 end
app/models/fans_block.rb
@@ -12,14 +12,6 @@ class FansBlock &lt; ProfileListBlock @@ -12,14 +12,6 @@ class FansBlock &lt; ProfileListBlock
12 _('This block presents the fans of an enterprise.') 12 _('This block presents the fans of an enterprise.')
13 end 13 end
14 14
15 - def footer  
16 - profile = self.owner  
17 - proc do  
18 - link_to _('View all'), :profile => profile.identifier, :controller =>  
19 - 'profile', :action => 'fans'  
20 - end  
21 - end  
22 -  
23 def profiles 15 def profiles
24 owner.fans 16 owner.fans
25 end 17 end
app/models/favorite_enterprises_block.rb
@@ -12,14 +12,6 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock @@ -12,14 +12,6 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock
12 _('Favorite Enterprises') 12 _('Favorite Enterprises')
13 end 13 end
14 14
15 - def footer  
16 - owner = self.owner  
17 - return '' unless owner.kind_of?(Person)  
18 - proc do  
19 - link_to _('enterprises|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'}, :class => 'view-all'  
20 - end  
21 - end  
22 -  
23 def profiles 15 def profiles
24 owner.favorite_enterprises 16 owner.favorite_enterprises
25 end 17 end
app/models/featured_products_block.rb
@@ -32,11 +32,4 @@ class FeaturedProductsBlock &lt; Block @@ -32,11 +32,4 @@ class FeaturedProductsBlock &lt; Block
32 self.owner.highlighted_products_with_image 32 self.owner.highlighted_products_with_image
33 end 33 end
34 34
35 - def content(args={})  
36 - block = self  
37 - proc do  
38 - render :file => 'blocks/featured_products', :locals => { :block => block }  
39 - end  
40 - end  
41 -  
42 end 35 end
app/models/feed_reader_block.rb
@@ -52,24 +52,6 @@ class FeedReaderBlock &lt; Block @@ -52,24 +52,6 @@ class FeedReaderBlock &lt; Block
52 self.feed_title.nil? ? _('Feed Reader') : self.feed_title 52 self.feed_title.nil? ? _('Feed Reader') : self.feed_title
53 end 53 end
54 54
55 - def formatted_feed_content  
56 - if error_message.blank?  
57 - "<ul>\n".html_safe +  
58 - self.feed_items[0..(limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe +  
59 - "</ul>".html_safe  
60 - else  
61 - "<p>#{error_message}</p>".html_safe  
62 - end  
63 - end  
64 -  
65 - def footer  
66 - if self.fetched_at.nil? or self.feed_items.empty?  
67 - _('Feed content was not loaded yet')  
68 - else  
69 - _("Updated: %s") % show_date(self.fetched_at)  
70 - end  
71 - end  
72 -  
73 def add_item(title, link, date, content) 55 def add_item(title, link, date, content)
74 self.feed_items.unshift( {:title => title, :link => link}) 56 self.feed_items.unshift( {:title => title, :link => link})
75 end 57 end
@@ -85,8 +67,4 @@ class FeedReaderBlock &lt; Block @@ -85,8 +67,4 @@ class FeedReaderBlock &lt; Block
85 self.save! 67 self.save!
86 end 68 end
87 69
88 - def content(args={})  
89 - block_title(title) + formatted_feed_content  
90 - end  
91 -  
92 end 70 end
app/models/highlights_block.rb
@@ -43,13 +43,6 @@ class HighlightsBlock &lt; Block @@ -43,13 +43,6 @@ class HighlightsBlock &lt; Block
43 end 43 end
44 end 44 end
45 45
46 - def content(args={})  
47 - block = self  
48 - proc do  
49 - render :file => 'blocks/highlights', :locals => { :block => block }  
50 - end  
51 - end  
52 -  
53 def folder_choices 46 def folder_choices
54 owner.image_galleries 47 owner.image_galleries
55 end 48 end
app/models/link_list_block.rb
@@ -59,20 +59,6 @@ class LinkListBlock &lt; Block @@ -59,20 +59,6 @@ class LinkListBlock &lt; Block
59 _('Link list') 59 _('Link list')
60 end 60 end
61 61
62 - def content(args={})  
63 - block_title(title) +  
64 - content_tag('ul',  
65 - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))}.join  
66 - )  
67 - end  
68 -  
69 - def link_html(link)  
70 - klass = 'icon-' + link[:icon] if link[:icon]  
71 - sanitize_link(  
72 - link_to(link[:name], expand_address(link[:address]), :target => link[:target], :class => klass, :title => link[:title])  
73 - )  
74 - end  
75 -  
76 def expand_address(address) 62 def expand_address(address)
77 add = if owner.respond_to?(:identifier) 63 add = if owner.respond_to?(:identifier)
78 address.gsub('{profile}', owner.identifier) 64 address.gsub('{profile}', owner.identifier)
@@ -99,8 +85,6 @@ class LinkListBlock &lt; Block @@ -99,8 +85,6 @@ class LinkListBlock &lt; Block
99 end 85 end
100 end 86 end
101 87
102 - private  
103 -  
104 def sanitize_link(text) 88 def sanitize_link(text)
105 sanitizer = HTML::WhiteListSanitizer.new 89 sanitizer = HTML::WhiteListSanitizer.new
106 sanitizer.sanitize(text) 90 sanitizer.sanitize(text)
app/models/location_block.rb
@@ -13,12 +13,4 @@ class LocationBlock &lt; Block @@ -13,12 +13,4 @@ class LocationBlock &lt; Block
13 _('Shows where the profile is on the material world.') 13 _('Shows where the profile is on the material world.')
14 end 14 end
15 15
16 - def content(args={})  
17 - block = self  
18 - profile = self.owner  
19 - proc do  
20 - render :file => 'blocks/location', :locals => {:block => block, :profile => profile}  
21 - end  
22 - end  
23 -  
24 end 16 end
app/models/login_block.rb
@@ -8,12 +8,6 @@ class LoginBlock &lt; Block @@ -8,12 +8,6 @@ class LoginBlock &lt; Block
8 _('This block presents a login/logout block.') 8 _('This block presents a login/logout block.')
9 end 9 end
10 10
11 - def content(args={})  
12 - lambda do |context|  
13 - render :file => 'blocks/login_block'  
14 - end  
15 - end  
16 -  
17 def cacheable? 11 def cacheable?
18 false 12 false
19 end 13 end
app/models/main_block.rb
@@ -8,10 +8,6 @@ class MainBlock &lt; Block @@ -8,10 +8,6 @@ class MainBlock &lt; Block
8 _('This block presents the main content of your pages.') 8 _('This block presents the main content of your pages.')
9 end 9 end
10 10
11 - def content(args={})  
12 - nil  
13 - end  
14 -  
15 def main? 11 def main?
16 true 12 true
17 end 13 end
app/models/my_network_block.rb
@@ -14,16 +14,6 @@ class MyNetworkBlock &lt; Block @@ -14,16 +14,6 @@ class MyNetworkBlock &lt; Block
14 _('This block displays some info about your networking.') 14 _('This block displays some info about your networking.')
15 end 15 end
16 16
17 - def content(args={})  
18 - block = self  
19 - proc do  
20 - render :file => 'blocks/my_network', :locals => {  
21 - :title => block.title,  
22 - :owner => block.owner  
23 - }  
24 - end  
25 - end  
26 -  
27 def cacheable? 17 def cacheable?
28 false 18 false
29 end 19 end
app/models/product_categories_block.rb
@@ -13,26 +13,6 @@ class ProductCategoriesBlock &lt; Block @@ -13,26 +13,6 @@ class ProductCategoriesBlock &lt; Block
13 _('Helps to filter the products catalog.') 13 _('Helps to filter the products catalog.')
14 end 14 end
15 15
16 - def content(args={})  
17 - profile = owner  
18 - proc do  
19 - if @categories.nil? or @categories.length == 0  
20 - categories = ProductCategory.on_level(nil).order(:name)  
21 - if @categories and @categories.length == 0  
22 - notice = _('There are no sub-categories for %s') % @category.name  
23 - end  
24 - else  
25 - categories = @categories  
26 - end  
27 - render :file => 'blocks/product_categories',  
28 - :locals => {  
29 - :profile => profile,  
30 - :categories => categories,  
31 - :notice => notice  
32 - }  
33 - end  
34 - end  
35 -  
36 DISPLAY_OPTIONS = DISPLAY_OPTIONS.merge('catalog_only' => _('Only on the catalog')) 16 DISPLAY_OPTIONS = DISPLAY_OPTIONS.merge('catalog_only' => _('Only on the catalog'))
37 17
38 def display 18 def display
app/models/products_block.rb
@@ -19,26 +19,6 @@ class ProductsBlock &lt; Block @@ -19,26 +19,6 @@ class ProductsBlock &lt; Block
19 _('This block presents a list of your products.') 19 _('This block presents a list of your products.')
20 end 20 end
21 21
22 - def content(args={})  
23 - block_title(title) +  
24 - content_tag(  
25 - 'ul',  
26 - products.map {|product|  
27 - content_tag('li',  
28 - link_to( product.name,  
29 - product.url,  
30 - :style => 'background-image:url(%s)' % product.default_image('minor')  
31 - ),  
32 - :class => 'product'  
33 - )  
34 - }.join  
35 - )  
36 - end  
37 -  
38 - def footer  
39 - link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))  
40 - end  
41 -  
42 settings_items :product_ids, type: Array 22 settings_items :product_ids, type: Array
43 def product_ids=(array) 23 def product_ids=(array)
44 self.settings[:product_ids] = array 24 self.settings[:product_ids] = array
app/models/profile_image_block.rb
@@ -12,17 +12,6 @@ class ProfileImageBlock &lt; Block @@ -12,17 +12,6 @@ class ProfileImageBlock &lt; Block
12 _('This block presents the profile image') 12 _('This block presents the profile image')
13 end 13 end
14 14
15 - def content(args={})  
16 - block = self  
17 - s = show_name  
18 - lambda do |object|  
19 - render(  
20 - :file => 'blocks/profile_image',  
21 - :locals => { :block => block, :show_name => s }  
22 - )  
23 - end  
24 - end  
25 -  
26 def cacheable? 15 def cacheable?
27 false 16 false
28 end 17 end
app/models/profile_info_block.rb
@@ -16,13 +16,6 @@ class ProfileInfoBlock &lt; Block @@ -16,13 +16,6 @@ class ProfileInfoBlock &lt; Block
16 _('Basic information about <i>%{user}</i>: how long <i>%{user}</i> is part of <i>%{env}</i> and useful links.') % { :user => self.owner.name(), :env => self.owner.environment.name() } 16 _('Basic information about <i>%{user}</i>: how long <i>%{user}</i> is part of <i>%{env}</i> and useful links.') % { :user => self.owner.name(), :env => self.owner.environment.name() }
17 end 17 end
18 18
19 - def content(args={})  
20 - block = self  
21 - lambda do |_|  
22 - render :file => 'blocks/profile_info', :locals => { :block => block }  
23 - end  
24 - end  
25 -  
26 def cacheable? 19 def cacheable?
27 false 20 false
28 end 21 end
app/models/profile_list_block.rb
@@ -40,26 +40,6 @@ result = public_profiles.all(:limit =&gt; get_limit, :order =&gt; &#39;profiles.updated_at @@ -40,26 +40,6 @@ result = public_profiles.all(:limit =&gt; get_limit, :order =&gt; &#39;profiles.updated_at
40 _('Clicking on the people or groups will take you to their home page.') 40 _('Clicking on the people or groups will take you to their home page.')
41 end 41 end
42 42
43 - def content(args={})  
44 - profiles = self.profile_list  
45 - title = self.view_title  
46 - nl = "\n"  
47 - proc do |context|  
48 - count=0  
49 - list = profiles.map {|item|  
50 - count+=1  
51 - send(:profile_image_link, item, :minor )  
52 - }.join("\n ")  
53 - if list.empty?  
54 - list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none'  
55 - else  
56 - list = content_tag 'ul', nl +' '+ list + nl  
57 - end  
58 - block_title(title) + nl +  
59 - content_tag('div', nl + list + nl + tag('br', :style => 'clear:both'))  
60 - end  
61 - end  
62 -  
63 def view_title 43 def view_title
64 title.gsub('{#}', profile_count.to_s) 44 title.gsub('{#}', profile_count.to_s)
65 end 45 end
app/models/profile_search_block.rb
@@ -4,11 +4,4 @@ class ProfileSearchBlock &lt; Block @@ -4,11 +4,4 @@ class ProfileSearchBlock &lt; Block
4 _('Display a form to search the profile') 4 _('Display a form to search the profile')
5 end 5 end
6 6
7 - def content(args={})  
8 - title = self.title  
9 - lambda do |_|  
10 - render :file => 'blocks/profile_search', :locals => { :title => title }  
11 - end  
12 - end  
13 -  
14 end 7 end
app/models/raw_html_block.rb
@@ -12,10 +12,6 @@ class RawHTMLBlock &lt; Block @@ -12,10 +12,6 @@ class RawHTMLBlock &lt; Block
12 12
13 attr_accessible :html 13 attr_accessible :html
14 14
15 - def content(args={})  
16 - (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe  
17 - end  
18 -  
19 def has_macro? 15 def has_macro?
20 true 16 true
21 end 17 end
app/models/recent_documents_block.rb
@@ -22,24 +22,6 @@ class RecentDocumentsBlock &lt; Block @@ -22,24 +22,6 @@ class RecentDocumentsBlock &lt; Block
22 22
23 settings_items :limit, :type => :integer, :default => 5 23 settings_items :limit, :type => :integer, :default => 5
24 24
25 - def content(args={})  
26 - docs = self.docs  
27 - title = self.title  
28 - proc do  
29 - block_title(title) +  
30 - content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))  
31 - end  
32 - end  
33 -  
34 - def footer  
35 - return nil unless self.owner.is_a?(Profile)  
36 -  
37 - profile = self.owner  
38 - proc do  
39 - link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap'  
40 - end  
41 - end  
42 -  
43 def docs 25 def docs
44 self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false) 26 self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false)
45 end 27 end
app/models/sellers_search_block.rb
@@ -22,10 +22,4 @@ class SellersSearchBlock &lt; Block @@ -22,10 +22,4 @@ class SellersSearchBlock &lt; Block
22 _('This block presents a search engine for products.') 22 _('This block presents a search engine for products.')
23 end 23 end
24 24
25 - def content(args={})  
26 - title = self.title  
27 - lambda do |object|  
28 - render :file => 'search/_sellers_form', :locals => { :title => title }  
29 - end  
30 - end  
31 end 25 end
app/models/slideshow_block.rb
@@ -33,23 +33,6 @@ class SlideshowBlock &lt; Block @@ -33,23 +33,6 @@ class SlideshowBlock &lt; Block
33 gallery.images.reject {|item| item.folder?} 33 gallery.images.reject {|item| item.folder?}
34 end 34 end
35 35
36 - def content(args={})  
37 - block = self  
38 - if gallery  
39 - images = block_images  
40 - if shuffle  
41 - images = images.shuffle  
42 - end  
43 - proc do  
44 - render :file => 'blocks/slideshow', :locals => { :block => block, :images => images }  
45 - end  
46 - else  
47 - proc do  
48 - render :file => 'blocks/slideshow', :locals => { :block => block, :images => nil }  
49 - end  
50 - end  
51 - end  
52 -  
53 def folder_choices 36 def folder_choices
54 owner.image_galleries 37 owner.image_galleries
55 end 38 end
app/models/tags_block.rb
@@ -28,42 +28,6 @@ class TagsBlock &lt; Block @@ -28,42 +28,6 @@ class TagsBlock &lt; Block
28 Try to add some tags to some articles and you'l see your tag cloud growing.") 28 Try to add some tags to some articles and you'l see your tag cloud growing.")
29 end 29 end
30 30
31 - def content(args={})  
32 - is_env = owner.class == Environment  
33 - tags = is_env ? owner.tag_counts : owner.article_tags  
34 - return '' if tags.empty?  
35 -  
36 - if limit  
37 - tags_tmp = tags.sort_by{ |k,v| -v }[0..(limit-1)]  
38 - tags = {}  
39 - tags_tmp.map{ |k,v| tags[k] = v }  
40 - end  
41 -  
42 - url = is_env ? {:host=>owner.default_hostname, :controller=>'search', :action => 'tag'} :  
43 - owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged')  
44 - tagname_option = is_env ? :tag : :id  
45 -  
46 - block_title(title) +  
47 - "\n<div class='tag_cloud'>\n".html_safe+  
48 - tag_cloud( tags, tagname_option, url, :max_size => 16, :min_size => 9 ) +  
49 - "\n</div><!-- end class='tag_cloud' -->\n".html_safe  
50 - end  
51 -  
52 - def footer  
53 - if owner.class == Environment  
54 - proc do  
55 - link_to s_('tags|View all'),  
56 - :controller => 'search', :action => 'tags'  
57 - end  
58 - else  
59 - owner_id = owner.identifier  
60 - proc do  
61 - link_to s_('tags|View all'),  
62 - :profile => owner_id, :controller => 'profile', :action => 'tags'  
63 - end  
64 - end  
65 - end  
66 -  
67 def timeout 31 def timeout
68 15.minutes 32 15.minutes
69 end 33 end
app/views/blocks/article.html.erb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +<%= block_title(block.title) %>
  2 +<% if block.article %>
  3 + <%=
  4 + h(article_to_html(FilePresenter.for(block.article),
  5 + :gallery_view => false,
  6 + :inside_block => block, # For Blogs and folders
  7 + :format => block.visualization_format # For Articles and contents
  8 + ))
  9 + %>
  10 +<% else %>
  11 + <%= _('Article not selected yet.') %>
  12 +<% end %>
app/views/blocks/blog_archives.html.erb 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +<% if block.blog %>
  2 + <%= block_title(block.title) %>
  3 +
  4 + <ul class='blog-archives'>
  5 + <% block.blog.total_number_of_posts(:by_year).each do |year, count| %>
  6 + <%= content_tag('li', content_tag('strong', "#{year.to_i} (#{count})")) %>
  7 + <ul class='<%= year.to_i %>-archive'>
  8 + <% block.blog.total_number_of_posts(:by_month, year).each do |month, count| %>
  9 + <%= content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", block.blog.url.merge(year: year.to_i, month: month.to_i))) %>
  10 + <% end %>
  11 + </ul>
  12 + <% end %>
  13 + </ul>
  14 +
  15 + <%= content_tag('div', link_to(_('Subscribe RSS Feed'), block.blog.feed.url), :class => 'subscribe-feed') %>
  16 +<% end %>
app/views/blocks/communities.html.erb
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
1 -<% if owner.kind_of?(Profile) %>  
2 - <%= link_to s_('communities|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %>  
3 -<% elsif owner.kind_of?(Environment) %>  
4 - <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %>  
5 -<% end %>  
6 -  
7 -<% if user && user == profile && suggestions && !suggestions.empty? %>  
8 - <div class='suggestions-block common-profile-list-block'>  
9 - <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>  
10 - <div class='profiles-suggestions'>  
11 - <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :communities_suggestions, :per_page => 3 } %>  
12 - </div>  
13 - <div class='more-suggestions'>  
14 - <%= link_to _('See all suggestions'), profile.communities_suggestions_url %>  
15 - </div>  
16 - </div>  
17 -<% end %>  
app/views/blocks/communities.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +profile_list.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/blocks/disabled_enterprise_message.html.erb
  1 +<% message = block.owner.environment.message_for_disabled_enterprise || '' %>
  2 +
1 <div id='enterprise-disabled'> 3 <div id='enterprise-disabled'>
2 <%= message %> 4 <%= message %>
3 <% if profile.blocked? && user && user.is_admin?(profile.environment) %> 5 <% if profile.blocked? && user && user.is_admin?(profile.environment) %>
app/views/blocks/enterprises.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +profile_list.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/blocks/fans.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +profile_list.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/blocks/favorite_enterprises.html.erb 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +profile_list.html.erb
0 \ No newline at end of file 2 \ No newline at end of file
app/views/blocks/feed_reader.html.erb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<%=
  4 + if block.error_message.blank?
  5 + "<ul>\n".html_safe +
  6 + block.feed_items[0..(block.limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe +
  7 + "</ul>".html_safe
  8 + else
  9 + "<p>#{block.error_message}</p>".html_safe
  10 + end
  11 +%>
app/views/blocks/footers/communities.html.erb 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 +<% if block.owner.kind_of?(Profile) || block.owner.kind_of?(Environment) %>
  2 + <% if block.owner.kind_of?(Profile) %>
  3 + <%= link_to s_('communities|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %>
  4 + <% elsif block.owner.kind_of?(Environment) %>
  5 + <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %>
  6 + <% end %>
  7 +
  8 + <% if user && user == profile && block.suggestions && !block.suggestions.empty? %>
  9 + <div class='suggestions-block common-profile-list-block'>
  10 + <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>
  11 + <div class='profiles-suggestions'>
  12 + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => block.suggestions, :collection => :communities_suggestions, :per_page => 3 } %>
  13 + </div>
  14 + <div class='more-suggestions'>
  15 + <%= link_to _('See all suggestions'), profile.communities_suggestions_url %>
  16 + </div>
  17 + </div>
  18 + <% end %>
  19 +<% end %>
app/views/blocks/footers/enterprises.html.erb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<% if block.owner.is_a?(Profile) %>
  2 + <%= link_to s_('enterprises|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'enterprises' %>
  3 +<% elsif block.owner.is_a?(Environment) %>
  4 + <%= link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' %>
  5 +<% end %>
app/views/blocks/footers/fans.html.erb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= link_to _('View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'fans' %>
app/views/blocks/footers/favorite_enterprises.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<% if block.owner.is_a?(Person) %>
  2 + <%= link_to _('enterprises|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'}, :class => 'view-all' %>
  3 +<% end %>
app/views/blocks/footers/feed_reader.html.erb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<% if block.fetched_at.nil? or block.feed_items.empty? %>
  2 + <%= _('Feed content was not loaded yet') %>
  3 +<% else %>
  4 + <%= _("Updated: %s") % show_date(block.fetched_at) %>
  5 +<% end %>
app/views/blocks/footers/products.html.erb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= link_to(_('View all products'), block.owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) %>
app/views/blocks/footers/recent_documents.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<% if block.owner.is_a?(Profile) %>
  2 + <%= link_to _('All content'), :profile => block.owner.identifier, :controller => 'profile', :action => 'sitemap' %>
  3 +<% end %>
app/views/blocks/footers/tags.html.erb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<% if block.owner.is_a?(Environment) %>
  2 + <%= link_to s_('tags|View all'), :controller => 'search', :action => 'tags' %>
  3 +<% else %>
  4 + <%= link_to s_('tags|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'tags' %>
  5 +<% end %>
app/views/blocks/link_list.html.erb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.links.select{|i| !i[:name].blank? and !i[:address].blank?}.each do |link| %>
  5 + <li>
  6 + <%= block.sanitize_link(link_to(link[:name], block.expand_address(link[:address]),
  7 + :target => link[:target],
  8 + :class => (link[:icon] ? "icon-#{link[:icon]}" : ''),
  9 + :title => link[:title])) %>
  10 + </li>
  11 + <% end %>
  12 +</ul>
app/views/blocks/location.html.erb
1 -<% if profile.lat %> 1 +<% if block.owner.lat %>
2 <%= block_title block.title %> 2 <%= block_title block.title %>
3 <div class='the-localization-map'> 3 <div class='the-localization-map'>
4 - <img src="https://maps.google.com/maps/api/staticmap?center=<%=profile.lat%>,<%=profile.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=profile.lat%>,<%=profile.lng%>&sensor=false"/> 4 + <img src="https://maps.google.com/maps/api/staticmap?center=<%=block.owner.lat%>,<%=block.owner.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=block.owner.lat%>,<%=block.owner.lng%>&sensor=false"/>
5 </div> 5 </div>
6 <% else %> 6 <% else %>
7 <i><%= _('This profile has no geographical position registered.') %></i> 7 <i><%= _('This profile has no geographical position registered.') %></i>
app/views/blocks/login.html.erb 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +<% if user.present? %>
  2 + <div class="logged-user-info">
  3 + <h2><%= _('Logged in as %s') % user.identifier %></h2>
  4 + <ul>
  5 + <li><%= _('User since %s/%s') % [user.created_at.month, user.created_at.year] %></li>
  6 + <li><%= link_to _('Homepage'), user.public_profile_url %></li>
  7 + </ul>
  8 + <div class="user-actions">
  9 + <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %>
  10 + </div>
  11 + </div>
  12 +<% else %>
  13 + <div class='not-logged-user'>
  14 + <%= render :file => 'account/login_block' %>
  15 + </div>
  16 +<% end%>
app/views/blocks/login_block.html.erb
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -<% if user.present? %>  
2 - <div class="logged-user-info">  
3 - <h2><%= _('Logged in as %s') % user.identifier %></h2>  
4 - <ul>  
5 - <li><%= _('User since %s/%s') % [user.created_at.month, user.created_at.year] %></li>  
6 - <li><%= link_to _('Homepage'), user.public_profile_url %></li>  
7 - </ul>  
8 - <div class="user-actions">  
9 - <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %>  
10 - </div>  
11 - </div>  
12 -<% else %>  
13 - <div class='not-logged-user'>  
14 - <%= render :file => 'account/login_block' %>  
15 - </div>  
16 -<% end%>  
app/views/blocks/my_network.html.erb
1 -<%= block_title(title) %> 1 +<%= block_title(block.title) %>
2 2
3 <ul> 3 <ul>
4 - <li><%= link_to(_('Homepage'), owner.url, :class => 'url') %></li>  
5 - <li><%= link_to(_('View profile'), owner.public_profile_url) %></li>  
6 - <% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %> 4 + <li><%= link_to(_('Homepage'), block.owner.url, :class => 'url') %></li>
  5 + <li><%= link_to(_('View profile'), block.owner.public_profile_url) %></li>
  6 + <% if !user.nil? and block.owner.organization? and user.has_permission?('edit_profile', profile) %>
7 <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li> 7 <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li>
8 <% end %> 8 <% end %>
9 </ul> 9 </ul>
10 10
11 <div class="my-network-actions"> 11 <div class="my-network-actions">
12 - <%= render_profile_actions owner.class %> 12 + <%= render_profile_actions block.owner.class %>
13 </div> 13 </div>
app/views/blocks/product_categories.html.erb
1 -<%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %> 1 +<%
  2 + if @categories.nil? or @categories.length == 0
  3 + categories = ProductCategory.on_level(nil).order(:name)
  4 + else
  5 + categories = @categories
  6 + end
  7 +%>
  8 +
  9 +<%= link_to _('Catalog start'), block.owner.catalog_url, :class=>'catalog-home-link' %>
2 <ul class="catalog-categories-list"> 10 <ul class="catalog-categories-list">
3 <% categories.each do |category| %> 11 <% categories.each do |category| %>
4 <%= category_with_sub_list(category) %> 12 <%= category_with_sub_list(category) %>
5 <% end %> 13 <% end %>
6 </ul> 14 </ul>
7 -<% if notice %>  
8 - <div class="catalog-categories-notice"><%= notice %></div> 15 +<% if @categories and @categories.length == 0 %>
  16 + <div class="catalog-categories-notice">
  17 + <%= _('There are no sub-categories for %s') % @category.name %>
  18 + </div>
9 <% end %> 19 <% end %>
app/views/blocks/products.html.erb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.products.each do |product| %>
  5 + <li class='product'>
  6 + <%= link_to(product.name, product.url, :style => 'background-image:url(%s)' % product.default_image('minor')) %>
  7 + </li>
  8 + <% end %>
  9 +</ul>
app/views/blocks/profile_image.html.erb
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 </div> 12 </div>
13 </div> 13 </div>
14 14
15 -<% if show_name %> 15 +<% if block.show_name %>
16 <p><%= h block.owner.short_name %></p> 16 <p><%= h block.owner.short_name %></p>
17 <% end %> 17 <% end %>
18 18
app/views/blocks/profile_list.html.erb 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +<%= block_title(block.view_title) %>
  2 +
  3 +<%
  4 + list = block.profile_list.map do |item|
  5 + profile_image_link(item, :minor)
  6 + end.join("\n ")
  7 +%>
  8 +
  9 +<div>
  10 + <% if list.empty? %>
  11 + <div class='common-profile-list-block-none'><%= _('None') %></div>
  12 + <% else %>
  13 + <ul><%= list %></ul>
  14 + <% end %>
  15 +</div>
  16 +
  17 +<br style='clear:both'/>
app/views/blocks/profile_search.html.erb
1 -<%= block_title(title) %> 1 +<%= block_title(block.title) %>
2 2
3 <%= render :partial => 'shared/profile_search_form' %> 3 <%= render :partial => 'shared/profile_search_form' %>
app/views/blocks/raw_html.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<%=h block_title(block.title) %>
  2 +
  3 +<%=h block.html %>
app/views/blocks/recent_documents.html.erb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<ul>
  4 + <% block.docs.map do |item| %>
  5 + <%= content_tag('li', link_to(h(item.title), item.url)) %>
  6 + <% end %>
  7 +</ul>
app/views/blocks/sellers_search.html.erb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +<h3><%= block.title %></h3>
  2 +
  3 +<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %>
  4 +
  5 + <div class="search-in-opt"><%= _('Search in:') %>
  6 + <dir>
  7 + <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br />
  8 + <%= labelled_radio_button _('Products'), 'asset', 'products', false %>
  9 + </dir>
  10 + </div>
  11 +
  12 + <div class="formfield search-from-opt">
  13 + <%= select_city(true) %>
  14 + </div>
  15 +
  16 + <div class="formfield search-distance-opt">
  17 + <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %>
  18 + </div>
  19 +
  20 + <div class="button-bar">
  21 + <%= submit_button :search, _('Search') %>
  22 + </div>
  23 +
  24 +<% end %>
app/views/blocks/slideshow.html.erb
  1 +<%
  2 + if block.gallery
  3 + images = block.block_images
  4 + if block.shuffle
  5 + images = images.shuffle
  6 + end
  7 + end
  8 +%>
  9 +
1 <%= block_title(block.title) %> 10 <%= block_title(block.title) %>
  11 +
2 <% if images %> 12 <% if images %>
3 <% description = images.any? { |img| !img.abstract.blank? } %> 13 <% description = images.any? { |img| !img.abstract.blank? } %>
4 <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'> 14 <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'>
app/views/blocks/tags.html.erb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +<%= block_title(block.title) %>
  2 +
  3 +<%
  4 + is_env = block.owner.class == Environment
  5 + tags = is_env ? block.owner.tag_counts : block.owner.article_tags
  6 + if block.limit
  7 + tags_tmp = tags.sort_by{ |k,v| -v }[0..(block.limit-1)]
  8 + tags = {}
  9 + tags_tmp.map{ |k,v| tags[k] = v }
  10 + end
  11 +%>
  12 +
  13 +<% unless tags.empty? %>
  14 + <div class='tag_cloud'>
  15 + <% if is_env %>
  16 + <%= tag_cloud(tags, :tag,
  17 + {:host => block.owner.default_hostname, :controller=>'search', :action => 'tag'},
  18 + :max_size => 16, :min_size => 9) %>
  19 + <% else %>
  20 + <%= tag_cloud(tags, :id,
  21 + block.owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'),
  22 + :max_size => 16, :min_size => 9) %>
  23 + <% end %>
  24 + </div>
  25 +<% end %>
app/views/search/_sellers_form.html.erb
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -<h3><%= title %></h3>  
2 -  
3 -<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %>  
4 -  
5 - <div class="search-in-opt"><%= _('Search in:') %>  
6 - <dir>  
7 - <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br />  
8 - <%= labelled_radio_button _('Products'), 'asset', 'products', false %>  
9 - </dir>  
10 - </div>  
11 -  
12 - <div class="formfield search-from-opt">  
13 - <%= select_city(true) %>  
14 - </div>  
15 -  
16 - <div class="formfield search-distance-opt">  
17 - <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %>  
18 - </div>  
19 -  
20 - <div class="button-bar">  
21 - <%= submit_button :search, _('Search') %>  
22 - </div>  
23 -  
24 -<% end %>  
app/views/shared/block.html.erb
1 <% if block.cacheable? && use_cache %> 1 <% if block.cacheable? && use_cache %>
2 <% cache_timeout(block.cache_key(language, user), block.timeout) do %> 2 <% cache_timeout(block.cache_key(language, user), block.timeout) do %>
3 - <%= display_block_content(block, user, main_content) %> 3 + <%= display_block_content(block, main_content) %>
4 <% end %> 4 <% end %>
5 <% else %> 5 <% else %>
6 - <%= display_block_content(block, user, main_content) %> 6 + <%= display_block_content(block, main_content) %>
7 <% end %> 7 <% end %>
test/unit/application_helper_test.rb
@@ -80,12 +80,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -80,12 +80,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
80 assert_equal '', show_date(nil) 80 assert_equal '', show_date(nil)
81 end 81 end
82 82
83 -  
84 - should 'append with-text class and keep existing classes' do  
85 - expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'})  
86 - button('type', 'label', 'url', { :class => 'class1' })  
87 - end  
88 -  
89 should 'generate correct link to category' do 83 should 'generate correct link to category' do
90 cat = mock 84 cat = mock
91 cat.expects(:path).returns('my-category/my-subcatagory') 85 cat.expects(:path).returns('my-category/my-subcatagory')
test/unit/article_block_test.rb
@@ -7,15 +7,6 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -7,15 +7,6 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
7 assert_not_equal Block.description, ArticleBlock.description 7 assert_not_equal Block.description, ArticleBlock.description
8 end 8 end
9 9
10 - should "take article's content" do  
11 - block = ArticleBlock.new  
12 - article = mock  
13 - article.expects(:to_html).returns("Article content")  
14 - block.stubs(:article).returns(article)  
15 -  
16 - assert_match(/Article content/, instance_eval(&block.content))  
17 - end  
18 -  
19 should 'refer to an article' do 10 should 'refer to an article' do
20 profile = create_user('testuser').person 11 profile = create_user('testuser').person
21 article = profile.articles.build(:name => 'test article') 12 article = profile.articles.build(:name => 'test article')
@@ -85,6 +76,31 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -85,6 +76,31 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
85 assert_equal [a],block.available_articles 76 assert_equal [a],block.available_articles
86 end 77 end
87 78
  79 + protected
  80 + include NoosferoTestHelper
  81 +
  82 +end
  83 +
  84 +require 'boxes_helper'
  85 +require 'block_helper'
  86 +
  87 +class ArticleBlockViewTest < ActionView::TestCase
  88 + include BoxesHelper
  89 +
  90 + ActionView::Base.send :include, ArticleHelper
  91 + ActionView::Base.send :include, ButtonsHelper
  92 + ActionView::Base.send :include, BlockHelper
  93 +
  94 + should "take article's content" do
  95 + block = ArticleBlock.new
  96 + article = mock
  97 + article.expects(:to_html).returns("Article content")
  98 + block.stubs(:article).returns(article)
  99 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  100 +
  101 + assert_match(/Article content/, render_block_content(block))
  102 + end
  103 +
88 should "display empty title if title is blank" do 104 should "display empty title if title is blank" do
89 block = ArticleBlock.new 105 block = ArticleBlock.new
90 article = mock 106 article = mock
@@ -92,7 +108,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -92,7 +108,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
92 block.expects(:title).returns('') 108 block.expects(:title).returns('')
93 block.stubs(:article).returns(article) 109 block.stubs(:article).returns(article)
94 110
95 - assert_equal "<h3 class=\"block-title empty\"><span></span></h3>Article content", instance_eval(&block.content) 111 + assert_equal "<h3 class=\"block-title empty\"><span></span></h3>\n Article content\n", render_block_content(block)
96 end 112 end
97 113
98 should "display title if defined" do 114 should "display title if defined" do
@@ -102,7 +118,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -102,7 +118,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
102 block.expects(:title).returns('Article title') 118 block.expects(:title).returns('Article title')
103 block.stubs(:article).returns(article) 119 block.stubs(:article).returns(article)
104 120
105 - assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>Article content", instance_eval(&block.content) 121 + assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>\n Article content\n", render_block_content(block)
106 end 122 end
107 123
108 should 'display image if article is an image' do 124 should 'display image if article is an image' do
@@ -113,7 +129,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -113,7 +129,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
113 block.article = image 129 block.article = image
114 block.save! 130 block.save!
115 131
116 - assert_tag_in_string instance_eval(&block.content), 132 + assert_tag_in_string render_block_content(block),
117 :tag => 'img', 133 :tag => 'img',
118 :attributes => { 134 :attributes => {
119 :src => image.public_filename(:display), 135 :src => image.public_filename(:display),
@@ -129,7 +145,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -129,7 +145,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
129 block.article = image 145 block.article = image
130 block.save! 146 block.save!
131 147
132 - assert_no_match(/Previous/, instance_eval(&block.content)) 148 + assert_no_match(/Previous/, render_block_content(block))
133 end 149 end
134 150
135 should 'display link to archive if article is an archive' do 151 should 'display link to archive if article is an archive' do
@@ -141,11 +157,6 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase @@ -141,11 +157,6 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
141 block.save! 157 block.save!
142 158
143 UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file') 159 UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file')
144 -  
145 - assert_tag_in_string instance_eval(&block.content), :tag => 'a', :content => _('Download') 160 + assert_tag_in_string render_block_content(block), :tag => 'a', :content => _('Download')
146 end 161 end
147 -  
148 - protected  
149 - include NoosferoTestHelper  
150 -  
151 end 162 end
test/unit/blog_archives_block_test.rb
@@ -17,6 +17,69 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -17,6 +17,69 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
17 assert l.editable? 17 assert l.editable?
18 end 18 end
19 19
  20 + should 'has field to configure blog' do
  21 + b = BlogArchivesBlock.new
  22 + assert b.respond_to?(:blog_id)
  23 + assert b.respond_to?(:blog_id=)
  24 + end
  25 +
  26 + should 'not try to load a removed blog' do
  27 + block = fast_create(BlogArchivesBlock)
  28 + block.blog_id = profile.blog.id
  29 + block.save!
  30 + block.stubs(:owner).returns(profile)
  31 + profile.blog.destroy
  32 + assert_nothing_raised do
  33 + assert_nil block.blog
  34 + end
  35 + end
  36 +
  37 + should 'load next blog if configured blog was removed' do
  38 + other_blog = fast_create(Blog, :profile_id => profile.id)
  39 + block = fast_create(BlogArchivesBlock)
  40 + block.blog_id = profile.blog.id
  41 + block.save!
  42 + block.stubs(:owner).returns(profile)
  43 + profile.blog.destroy
  44 + assert_nothing_raised do
  45 + assert_equal other_blog, block.blog
  46 + end
  47 + end
  48 +
  49 +#FIXME Performance issues with display_to. Must convert it to a scope.
  50 +# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705
  51 +#
  52 +# should 'not count articles if the user can\'t see them' do
  53 +# person = create_user('testuser').person
  54 +# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path')
  55 +# block = fast_create(BlogArchivesBlock)
  56 +#
  57 +# feed = mock()
  58 +# feed.stubs(:url).returns(blog.url)
  59 +# blog.stubs(:feed).returns(feed)
  60 +# block.stubs(:blog).returns(blog)
  61 +# block.stubs(:owner).returns(profile)
  62 +#
  63 +# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan'))
  64 +# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan'))
  65 +#
  66 +# assert_match /January \(1\)/, block.content({:person => person})
  67 +# assert_match /January \(1\)/, block.content()
  68 +# assert_match /January \(2\)/, block.content({:person => profile})
  69 +# end
  70 +end
  71 +
  72 +require 'boxes_helper'
  73 +
  74 +class BlogArchivesBlockViewTest < ActionView::TestCase
  75 + include BoxesHelper
  76 +
  77 + def setup
  78 + @profile = create_user('flatline').person
  79 + @profile.articles << Blog.new(:name => 'Blog One', :profile => @profile)
  80 + end
  81 + attr_reader :profile
  82 +
20 should 'list amount posts by year' do 83 should 'list amount posts by year' do
21 date = DateTime.parse('2008-01-10') 84 date = DateTime.parse('2008-01-10')
22 blog = profile.blog 85 blog = profile.blog
@@ -26,7 +89,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -26,7 +89,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
26 end 89 end
27 block = BlogArchivesBlock.new 90 block = BlogArchivesBlock.new
28 block.stubs(:owner).returns(profile) 91 block.stubs(:owner).returns(profile)
29 - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (10)' 92 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  93 + ActionView::Base.any_instance.stubs(:month_name).returns("")
  94 + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (10)'
30 end 95 end
31 96
32 should 'list amount posts by month' do 97 should 'list amount posts by month' do
@@ -38,7 +103,18 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -38,7 +103,18 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
38 end 103 end
39 block = BlogArchivesBlock.new 104 block = BlogArchivesBlock.new
40 block.stubs(:owner).returns(profile) 105 block.stubs(:owner).returns(profile)
41 - assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } 106 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  107 + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January")
  108 + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February")
  109 + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March")
  110 + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April")
  111 + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May")
  112 + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June")
  113 + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July")
  114 + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August")
  115 + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September")
  116 + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber")
  117 + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ }
42 end 118 end
43 119
44 should 'order list of amount posts' do 120 should 'order list of amount posts' do
@@ -49,7 +125,18 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -49,7 +125,18 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
49 end 125 end
50 block = BlogArchivesBlock.new 126 block = BlogArchivesBlock.new
51 block.stubs(:owner).returns(profile) 127 block.stubs(:owner).returns(profile)
52 - assert_tag_in_string block.content, :tag => 'li', :content => 'January (1)', 128 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  129 + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January")
  130 + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February")
  131 + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March")
  132 + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April")
  133 + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May")
  134 + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June")
  135 + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July")
  136 + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August")
  137 + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September")
  138 + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber")
  139 + assert_tag_in_string render_block_content(block), :tag => 'li', :content => 'January (1)',
53 :sibling => {:tag => 'li', :content => 'February (1)', 140 :sibling => {:tag => 'li', :content => 'February (1)',
54 :sibling => {:tag => 'li', :content => 'March (1)', 141 :sibling => {:tag => 'li', :content => 'March (1)',
55 :sibling => {:tag => 'li', :content => 'April (1)', 142 :sibling => {:tag => 'li', :content => 'April (1)',
@@ -63,7 +150,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -63,7 +150,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
63 end 150 end
64 block = BlogArchivesBlock.new 151 block = BlogArchivesBlock.new
65 block.stubs(:owner).returns(profile) 152 block.stubs(:owner).returns(profile)
66 - assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content) 153 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  154 + ActionView::Base.any_instance.stubs(:month_name).returns("")
  155 + assert_match(/2009.*2008.*2007.*2006.*2005/m, render_block_content(block))
67 end 156 end
68 157
69 should 'order months from later to former' do 158 should 'order months from later to former' do
@@ -73,20 +162,20 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -73,20 +162,20 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
73 end 162 end
74 block = BlogArchivesBlock.new 163 block = BlogArchivesBlock.new
75 block.stubs(:owner).returns(profile) 164 block.stubs(:owner).returns(profile)
76 - assert_match(/.*March.*February.*January.*/m, block.content) 165 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  166 + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January")
  167 + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February")
  168 + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March")
  169 + assert_match(/.*March.*February.*January.*/m, render_block_content(block))
77 end 170 end
78 171
79 should 'not display any content if has no blog' do 172 should 'not display any content if has no blog' do
80 profile.blogs.destroy_all 173 profile.blogs.destroy_all
81 block = BlogArchivesBlock.new 174 block = BlogArchivesBlock.new
82 block.stubs(:owner).returns(profile) 175 block.stubs(:owner).returns(profile)
83 - assert_nil block.content  
84 - end  
85 -  
86 - should 'has field to configure blog' do  
87 - b = BlogArchivesBlock.new  
88 - assert b.respond_to?(:blog_id)  
89 - assert b.respond_to?(:blog_id=) 176 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  177 + ActionView::Base.any_instance.stubs(:month_name).returns("")
  178 + assert_empty render_block_content(block)
90 end 179 end
91 180
92 should 'show posts from first blog' do 181 should 'show posts from first blog' do
@@ -98,8 +187,10 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -98,8 +187,10 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
98 end 187 end
99 block = BlogArchivesBlock.new 188 block = BlogArchivesBlock.new
100 block.stubs(:owner).returns(profile) 189 block.stubs(:owner).returns(profile)
101 - assert_match(/blog-one/m, block.content)  
102 - assert_no_match(/blog-two/m, block.content) 190 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  191 + ActionView::Base.any_instance.stubs(:month_name).returns("")
  192 + assert_match(/blog-one/m, render_block_content(block))
  193 + assert_no_match(/blog-two/m, render_block_content(block))
103 end 194 end
104 195
105 should 'list amount native posts by year' do 196 should 'list amount native posts by year' do
@@ -115,7 +206,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -115,7 +206,9 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
115 end 206 end
116 block = BlogArchivesBlock.new 207 block = BlogArchivesBlock.new
117 block.stubs(:owner).returns(profile) 208 block.stubs(:owner).returns(profile)
118 - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (2)' 209 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  210 + ActionView::Base.any_instance.stubs(:month_name).returns("")
  211 + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (2)'
119 end 212 end
120 213
121 should 'list amount native posts by month' do 214 should 'list amount native posts by month' do
@@ -131,51 +224,8 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -131,51 +224,8 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
131 end 224 end
132 block = BlogArchivesBlock.new 225 block = BlogArchivesBlock.new
133 block.stubs(:owner).returns(profile) 226 block.stubs(:owner).returns(profile)
134 - assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ }  
135 - end  
136 -  
137 - should 'not try to load a removed blog' do  
138 - block = fast_create(BlogArchivesBlock)  
139 - block.blog_id = profile.blog.id  
140 - block.save!  
141 - block.stubs(:owner).returns(profile)  
142 - profile.blog.destroy  
143 - assert_nothing_raised do  
144 - assert_nil block.blog  
145 - end 227 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  228 + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January")
  229 + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ }
146 end 230 end
147 -  
148 - should 'load next blog if configured blog was removed' do  
149 - other_blog = fast_create(Blog, :profile_id => profile.id)  
150 - block = fast_create(BlogArchivesBlock)  
151 - block.blog_id = profile.blog.id  
152 - block.save!  
153 - block.stubs(:owner).returns(profile)  
154 - profile.blog.destroy  
155 - assert_nothing_raised do  
156 - assert_equal other_blog, block.blog  
157 - end  
158 - end  
159 -  
160 -#FIXME Performance issues with display_to. Must convert it to a scope.  
161 -# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705  
162 -#  
163 -# should 'not count articles if the user can\'t see them' do  
164 -# person = create_user('testuser').person  
165 -# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path')  
166 -# block = fast_create(BlogArchivesBlock)  
167 -#  
168 -# feed = mock()  
169 -# feed.stubs(:url).returns(blog.url)  
170 -# blog.stubs(:feed).returns(feed)  
171 -# block.stubs(:blog).returns(blog)  
172 -# block.stubs(:owner).returns(profile)  
173 -#  
174 -# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan'))  
175 -# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan'))  
176 -#  
177 -# assert_match /January \(1\)/, block.content({:person => person})  
178 -# assert_match /January \(1\)/, block.content()  
179 -# assert_match /January \(2\)/, block.content({:person => profile})  
180 -# end  
181 end 231 end
test/unit/blog_test.rb
@@ -266,4 +266,23 @@ class BlogTest &lt; ActiveSupport::TestCase @@ -266,4 +266,23 @@ class BlogTest &lt; ActiveSupport::TestCase
266 266
267 assert_equal blog.image(true).filename, 'noosfero-network.png' 267 assert_equal blog.image(true).filename, 'noosfero-network.png'
268 end 268 end
  269 +
  270 + should 'count total number of posts by year' do
  271 + p = create_user('testuser').person
  272 + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test')
  273 + create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => DateTime.parse('16-08-2010'))
  274 + create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p, :published_at => DateTime.parse('17-08-2010'))
  275 + create(TextileArticle, :name => 'Post 3', :parent => blog, :profile => p, :published_at => DateTime.parse('10-05-2012'))
  276 + assert_equal [[2012.0, 1], [2010.0, 2]], blog.total_number_of_posts(:by_year)
  277 + end
  278 +
  279 + should 'count total number of posts by month' do
  280 + p = create_user('testuser').person
  281 + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test')
  282 + create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => DateTime.parse('16-08-2010'))
  283 + create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p, :published_at => DateTime.parse('17-08-2010'))
  284 + create(TextileArticle, :name => 'Post 3', :parent => blog, :profile => p, :published_at => DateTime.parse('11-10-2010'))
  285 + assert_equal [[10.0, 1], [8.0, 2]], blog.total_number_of_posts(:by_month, 2010)
  286 + end
  287 +
269 end 288 end
test/unit/buttons_helper_test.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +# encoding: UTF-8
  2 +require_relative "../test_helper"
  3 +
  4 +class ButtonsHelperTest < ActionView::TestCase
  5 + include ButtonsHelper
  6 +
  7 + should 'append with-text class and keep existing classes' do
  8 + expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'})
  9 + button('type', 'label', 'url', { :class => 'class1' })
  10 + end
  11 +end
0 \ No newline at end of file 12 \ No newline at end of file
test/unit/categories_block_test.rb
@@ -17,11 +17,13 @@ class CategoriesBlockTest &lt; ActiveSupport::TestCase @@ -17,11 +17,13 @@ class CategoriesBlockTest &lt; ActiveSupport::TestCase
17 assert_not_nil category_block.help 17 assert_not_nil category_block.help
18 end 18 end
19 19
  20 + include BoxesHelper
  21 +
20 should 'display category block' do 22 should 'display category block' do
21 block = CategoriesBlock.new 23 block = CategoriesBlock.new
22 24
23 self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block}) 25 self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block})
24 - instance_eval(& block.content) 26 + render_block_content(block)
25 end 27 end
26 28
27 should 'be editable' do 29 should 'be editable' do
test/unit/communities_block_test.rb
@@ -27,14 +27,44 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -27,14 +27,44 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
27 assert_same list, block.profiles 27 assert_same list, block.profiles
28 end 28 end
29 29
  30 + should 'list non-public communities' do
  31 + user = create_user('testuser').person
  32 +
  33 + public_community = fast_create(Community, :environment_id => Environment.default.id)
  34 + public_community.add_member(user)
  35 +
  36 + private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)
  37 + private_community.add_member(user)
  38 +
  39 + block = CommunitiesBlock.new
  40 + block.expects(:owner).at_least_once.returns(user)
  41 +
  42 + assert_equivalent [public_community, private_community], block.profiles
  43 + end
  44 +
  45 +end
  46 +
  47 +require 'boxes_helper'
  48 +
  49 +class CommunitiesBlockViewTest < ActionView::TestCase
  50 + include BoxesHelper
  51 +
30 should 'support profile as block owner' do 52 should 'support profile as block owner' do
31 profile = Profile.new 53 profile = Profile.new
  54 + profile.identifier = 42
  55 +
  56 + ActionView::Base.any_instance.stubs(:user).with(anything).returns(profile)
  57 + ActionView::Base.any_instance.stubs(:profile).with(anything).returns(profile)
32 58
33 block = CommunitiesBlock.new 59 block = CommunitiesBlock.new
34 block.expects(:owner).returns(profile).at_least_once 60 block.expects(:owner).returns(profile).at_least_once
35 61
36 - self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => profile, :suggestions => block.suggestions })  
37 - instance_eval(&block.footer) 62 + footer = render_block_footer(block)
  63 +
  64 + assert_tag_in_string footer, tag: 'a', attributes: {href: '/profile/42/communities'}
  65 +
  66 + ActionView::Base.any_instance.unstub(:user)
  67 + ActionView::Base.any_instance.unstub(:profile)
38 end 68 end
39 69
40 should 'support environment as block owner' do 70 should 'support environment as block owner' do
@@ -42,31 +72,24 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -42,31 +72,24 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
42 block = CommunitiesBlock.new 72 block = CommunitiesBlock.new
43 block.expects(:owner).returns(env).at_least_once 73 block.expects(:owner).returns(env).at_least_once
44 74
45 - self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => env, :suggestions => block.suggestions })  
46 - instance_eval(&block.footer)  
47 - end  
48 -  
49 - should 'give empty footer on unsupported owner type' do  
50 - block = CommunitiesBlock.new  
51 - block.expects(:owner).returns(1).at_least_once 75 + profile = Profile.new
  76 + profile.identifier = 42
52 77
53 - self.expects(:render).with(anything).never  
54 - assert_equal '', block.footer  
55 - end 78 + ActionView::Base.any_instance.stubs(:user).with(anything).returns(profile)
  79 + ActionView::Base.any_instance.stubs(:profile).with(anything).returns(profile)
56 80
57 - should 'list non-public communities' do  
58 - user = create_user('testuser').person 81 + footer = render_block_footer(block)
59 82
60 - public_community = fast_create(Community, :environment_id => Environment.default.id)  
61 - public_community.add_member(user) 83 + assert_tag_in_string footer, tag: 'a', attributes: {href: '/search/communities'}
62 84
63 - private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false)  
64 - private_community.add_member(user) 85 + ActionView::Base.any_instance.unstub(:user)
  86 + ActionView::Base.any_instance.unstub(:profile)
  87 + end
65 88
  89 + should 'give empty footer on unsupported owner type' do
66 block = CommunitiesBlock.new 90 block = CommunitiesBlock.new
67 - block.expects(:owner).at_least_once.returns(user) 91 + block.expects(:owner).returns(1).at_least_once
68 92
69 - assert_equivalent [public_community, private_community], block.profiles 93 + assert_equal '', render_block_footer(block)
70 end 94 end
71 -  
72 end 95 end
test/unit/disabled_enterprise_message_block_test.rb
@@ -6,16 +6,25 @@ class DisabledEnterpriseMessageBlockTest &lt; ActiveSupport::TestCase @@ -6,16 +6,25 @@ class DisabledEnterpriseMessageBlockTest &lt; ActiveSupport::TestCase
6 assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description 6 assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description
7 end 7 end
8 8
  9 + include BoxesHelper
  10 +
9 should 'display message for disabled enterprise' do 11 should 'display message for disabled enterprise' do
10 - e = Environment.default  
11 - e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises')  
12 - block = DisabledEnterpriseMessageBlock.new  
13 - p = Profile.new  
14 - block.expects(:owner).returns(p)  
15 - p.expects(:environment).returns(e)  
16 -  
17 - expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => 'This message is for disabled enterprises'})  
18 - instance_eval(&block.content) 12 + environment = Environment.default
  13 + environment.message_for_disabled_enterprise = 'This message is for disabled enterprises'
  14 + environment.save
  15 +
  16 + enterprise = fast_create(Enterprise, :identifier => 'disabled-enterprise', :environment_id => environment.id)
  17 + enterprise.boxes << Box.new
  18 + enterprise.boxes.first.blocks << DisabledEnterpriseMessageBlock.new
  19 + block = enterprise.boxes.first.blocks.first
  20 +
  21 + ApplicationHelper.class_eval do
  22 + def profile
  23 + return Enterprise['disabled-enterprise']
  24 + end
  25 + end
  26 +
  27 + assert_match 'This message is for disabled enterprises', render_block_content(block)
19 end 28 end
20 29
21 should 'not be editable' do 30 should 'not be editable' do
test/unit/enterprises_block_test.rb
@@ -27,32 +27,6 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase @@ -27,32 +27,6 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase
27 assert_same list, block.profiles 27 assert_same list, block.profiles
28 end 28 end
29 29
30 - should 'link to all enterprises for profile' do  
31 - profile = Profile.new  
32 - profile.expects(:identifier).returns('theprofile')  
33 - block = EnterprisesBlock.new  
34 - block.expects(:owner).returns(profile)  
35 -  
36 - expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')  
37 -  
38 - instance_eval(&block.footer)  
39 - end  
40 -  
41 - should 'link to all enterprises for environment' do  
42 - env = Environment.default  
43 - block = EnterprisesBlock.new  
44 - block.expects(:owner).returns(env)  
45 -  
46 - expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises')  
47 - instance_eval(&block.footer)  
48 - end  
49 -  
50 - should 'give empty footer for unsupported owner type' do  
51 - block = EnterprisesBlock.new  
52 - block.expects(:owner).returns(1)  
53 - assert_equal '', block.footer  
54 - end  
55 -  
56 should 'count number of owner enterprises' do 30 should 'count number of owner enterprises' do
57 user = create_user('testuser').person 31 user = create_user('testuser').person
58 32
@@ -71,3 +45,35 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase @@ -71,3 +45,35 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase
71 end 45 end
72 46
73 end 47 end
  48 +
  49 +require 'boxes_helper'
  50 +
  51 +class EnterprisesBlockViewTest < ActionView::TestCase
  52 + include BoxesHelper
  53 +
  54 + should 'link to all enterprises for profile' do
  55 + profile = Profile.new
  56 + profile.identifier = 'theprofile'
  57 + block = EnterprisesBlock.new
  58 + block.expects(:owner).twice.returns(profile)
  59 +
  60 + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')
  61 +
  62 + render_block_footer(block)
  63 + end
  64 +
  65 + should 'link to all enterprises for environment' do
  66 + env = Environment.default
  67 + block = EnterprisesBlock.new
  68 + block.expects(:owner).twice.returns(env)
  69 +
  70 + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises')
  71 + render_block_footer(block)
  72 + end
  73 +
  74 + should 'give empty footer for unsupported owner type' do
  75 + block = EnterprisesBlock.new
  76 + block.expects(:owner).twice.returns(1)
  77 + assert_equal '', render_block_footer(block)
  78 + end
  79 +end
test/unit/featured_products_block_test.rb
1 require_relative "../test_helper" 1 require_relative "../test_helper"
  2 +require 'boxes_helper'
2 3
3 class FeaturedProductsBlockTest < ActiveSupport::TestCase 4 class FeaturedProductsBlockTest < ActiveSupport::TestCase
  5 + include BoxesHelper
4 6
5 def setup 7 def setup
6 @profile = fast_create(Profile) 8 @profile = fast_create(Profile)
@@ -108,7 +110,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -108,7 +110,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
108 block = FeaturedProductsBlock.new 110 block = FeaturedProductsBlock.new
109 111
110 self.expects(:render).with(:file => 'blocks/featured_products', :locals => { :block => block}) 112 self.expects(:render).with(:file => 'blocks/featured_products', :locals => { :block => block})
111 - instance_eval(& block.content) 113 + render_block_content(block)
112 end 114 end
113 115
114 should "return just highlighted products with image for selection" do 116 should "return just highlighted products with image for selection" do
test/unit/feed_reader_block_test.rb
@@ -26,19 +26,6 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase @@ -26,19 +26,6 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase
26 assert feed.editable? 26 assert feed.editable?
27 end 27 end
28 28
29 - should 'display feed posts from content' do  
30 - feed.feed_items = []  
31 - %w[ last-post second-post first-post ].each do |i|  
32 - feed.feed_items << {:title => i, :link => "http://localhost/#{i}"}  
33 - end  
34 - feed.feed_title = 'Feed for unit tests'  
35 - feed_content = feed.content  
36 - assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests'  
37 - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post'  
38 - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post'  
39 - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post'  
40 - end  
41 -  
42 should 'display channel title as title by default' do 29 should 'display channel title as title by default' do
43 feed.feed_title = 'Feed for unit tests' 30 feed.feed_title = 'Feed for unit tests'
44 assert_equal 'Feed for unit tests', feed.title 31 assert_equal 'Feed for unit tests', feed.title
@@ -48,17 +35,6 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase @@ -48,17 +35,6 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase
48 assert_equal 'Feed Reader', feed.title 35 assert_equal 'Feed Reader', feed.title
49 end 36 end
50 37
51 - should 'notice when content not fetched yet' do  
52 - assert_equal'Feed content was not loaded yet', feed.footer  
53 - end  
54 -  
55 - should 'display last fetched date' do  
56 - now = Time.new(2014,1,1)  
57 - feed.feed_items = ['one', 'two']  
58 - feed.fetched_at = now  
59 - assert_equal "Updated: #{show_date(now)}", feed.footer  
60 - end  
61 -  
62 should 'clear feed title and items' do 38 should 'clear feed title and items' do
63 feed.feed_items = %w[ last-post second-post first-post ] 39 feed.feed_items = %w[ last-post second-post first-post ]
64 feed.feed_title = 'Feed Test' 40 feed.feed_title = 'Feed Test'
@@ -90,26 +66,10 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase @@ -90,26 +66,10 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase
90 assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} 66 assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]}
91 end 67 end
92 68
93 - should 'display only limit posts' do  
94 - feed.limit = 1; feed.save!  
95 - %w[ first-post second-post ].each do |i|  
96 - feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}")  
97 - end  
98 -  
99 - assert_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post'  
100 - assert_no_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post'  
101 - end  
102 -  
103 should 'have empty error message by default' do 69 should 'have empty error message by default' do
104 assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message' 70 assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message'
105 end 71 end
106 72
107 - should "display error message as content when it's the case" do  
108 - msg = "there was a problem"  
109 - feed.error_message = msg  
110 - assert_match(msg, feed.content)  
111 - end  
112 -  
113 should 'expire after a period' do 73 should 'expire after a period' do
114 # save current time 74 # save current time
115 now = Time.now 75 now = Time.now
@@ -195,3 +155,67 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase @@ -195,3 +155,67 @@ class FeedReaderBlockTest &lt; ActiveSupport::TestCase
195 end 155 end
196 156
197 end 157 end
  158 +
  159 +require 'boxes_helper'
  160 +require 'block_helper'
  161 +require 'dates_helper'
  162 +
  163 +class FeedReaderBlockViewTest < ActionView::TestCase
  164 + include BoxesHelper
  165 + include DatesHelper
  166 +
  167 + ActionView::Base.send :include, BlockHelper
  168 + ActionView::Base.send :include, DatesHelper
  169 +
  170 + def setup
  171 + @feed = create(:feed_reader_block)
  172 + end
  173 + attr_reader :feed
  174 +
  175 + should "display error message as content when it's the case" do
  176 + msg = "there was a problem"
  177 + feed.error_message = msg
  178 +
  179 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  180 +
  181 + assert_match(msg, render_block_content(feed))
  182 + end
  183 +
  184 + should 'display feed posts from content' do
  185 + feed.feed_items = []
  186 + %w[ last-post second-post first-post ].each do |i|
  187 + feed.feed_items << {:title => i, :link => "http://localhost/#{i}"}
  188 + end
  189 + feed.feed_title = 'Feed for unit tests'
  190 +
  191 + feed_content = render_block_content(feed)
  192 +
  193 + assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests'
  194 + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post'
  195 + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post'
  196 + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post'
  197 + end
  198 +
  199 + should 'display only limit posts' do
  200 + feed.limit = 1; feed.save!
  201 + %w[ first-post second-post ].each do |i|
  202 + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}")
  203 + end
  204 +
  205 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  206 +
  207 + assert_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post'
  208 + assert_no_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post'
  209 + end
  210 +
  211 + should 'notice when content not fetched yet' do
  212 + assert_equal " Feed content was not loaded yet\n", render_block_footer(feed)
  213 + end
  214 +
  215 + should 'display last fetched date' do
  216 + now = Time.new(2014,1,1)
  217 + feed.feed_items = ['one', 'two']
  218 + feed.fetched_at = now
  219 + assert_equal " Updated: #{show_date(now)}\n", render_block_footer(feed)
  220 + end
  221 +end
test/unit/highlights_block_test.rb
@@ -80,11 +80,13 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase @@ -80,11 +80,13 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase
80 assert_equal 'always', block.display 80 assert_equal 'always', block.display
81 end 81 end
82 82
  83 + include BoxesHelper
  84 +
83 should 'display highlights block' do 85 should 'display highlights block' do
84 block = HighlightsBlock.new 86 block = HighlightsBlock.new
85 self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block}) 87 self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block})
86 88
87 - instance_eval(& block.content) 89 + render_block_content(block)
88 end 90 end
89 91
90 should 'not list non existent image' do 92 should 'not list non existent image' do
@@ -167,7 +169,7 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase @@ -167,7 +169,7 @@ class HighlightsBlockTest &lt; ActiveSupport::TestCase
167 block.images = [i1] 169 block.images = [i1]
168 block.save! 170 block.save!
169 171
170 - assert_tag_in_string instance_eval(& block.content), :tag => 'img', :attributes => { :src => "/social/img_address" } 172 + assert_tag_in_string render_block_content(block), :tag => 'img', :attributes => { :src => "/social/img_address" }
171 end 173 end
172 174
173 [Environment, Profile].each do |klass| 175 [Environment, Profile].each do |klass|
test/unit/link_list_block_test.rb
@@ -2,6 +2,8 @@ require_relative &quot;../test_helper&quot; @@ -2,6 +2,8 @@ require_relative &quot;../test_helper&quot;
2 2
3 class LinkListBlockTest < ActiveSupport::TestCase 3 class LinkListBlockTest < ActiveSupport::TestCase
4 4
  5 + include BoxesHelper
  6 +
5 should 'default describe' do 7 should 'default describe' do
6 assert_not_equal Block.description, LinkListBlock.description 8 assert_not_equal Block.description, LinkListBlock.description
7 end 9 end
@@ -23,7 +25,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -23,7 +25,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
23 25
24 should 'list links' do 26 should 'list links' do
25 l = LinkListBlock.new(:links => [{:name => 'products', :address => '/cat/products'}]) 27 l = LinkListBlock.new(:links => [{:name => 'products', :address => '/cat/products'}])
26 - assert_match /products/, l.content 28 + assert_match /products/, render_block_content(l)
27 end 29 end
28 30
29 should 'remove links with blank fields' do 31 should 'remove links with blank fields' do
@@ -36,7 +38,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -36,7 +38,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
36 profile = Profile.new(:identifier => 'test_profile') 38 profile = Profile.new(:identifier => 'test_profile')
37 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{profile}/address'}]) 39 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{profile}/address'}])
38 l.stubs(:owner).returns(profile) 40 l.stubs(:owner).returns(profile)
39 - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'} 41 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/test_profile/address'}
40 end 42 end
41 43
42 should 'replace {portal} with environment portal identifier' do 44 should 'replace {portal} with environment portal identifier' do
@@ -49,7 +51,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -49,7 +51,7 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
49 stubs(:environment).returns(env) 51 stubs(:environment).returns(env)
50 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{portal}/address'}]) 52 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{portal}/address'}])
51 l.stubs(:owner).returns(env) 53 l.stubs(:owner).returns(env)
52 - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/portal-community/address'} 54 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/portal-community/address'}
53 end 55 end
54 56
55 should 'not change address if no {portal} there' do 57 should 'not change address if no {portal} there' do
@@ -62,19 +64,19 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -62,19 +64,19 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
62 stubs(:environment).returns(env) 64 stubs(:environment).returns(env)
63 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/address'}]) 65 l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/address'}])
64 l.stubs(:owner).returns(env) 66 l.stubs(:owner).returns(env)
65 - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/address'} 67 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/address'}
66 end 68 end
67 69
68 should 'handle /prefix if not already added' do 70 should 'handle /prefix if not already added' do
69 Noosfero.stubs(:root).returns('/prefix') 71 Noosfero.stubs(:root).returns('/prefix')
70 l = LinkListBlock.new(:links => [{:name => "foo", :address => '/bar'}] ) 72 l = LinkListBlock.new(:links => [{:name => "foo", :address => '/bar'}] )
71 - assert_tag_in_string l.content, :tag => 'a', :attributes => { :href => '/prefix/bar' } 73 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => { :href => '/prefix/bar' }
72 end 74 end
73 75
74 should 'not add /prefix if already there' do 76 should 'not add /prefix if already there' do
75 Noosfero.stubs(:root).returns('/prefix') 77 Noosfero.stubs(:root).returns('/prefix')
76 l = LinkListBlock.new(:links => [{:name => "foo", :address => '/prefix/bar'}] ) 78 l = LinkListBlock.new(:links => [{:name => "foo", :address => '/prefix/bar'}] )
77 - assert_tag_in_string l.content, :tag => 'a', :attributes => { :href => '/prefix/bar' } 79 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => { :href => '/prefix/bar' }
78 end 80 end
79 81
80 should 'display options for icons' do 82 should 'display options for icons' do
@@ -85,29 +87,29 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -85,29 +87,29 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
85 end 87 end
86 88
87 should 'link with icon' do 89 should 'link with icon' do
88 - l = LinkListBlock.new  
89 - assert_match /class="icon-save"/, l.link_html({:icon => 'save', :name => 'test', :address => 'test.com'}) 90 + l = LinkListBlock.new(:links => [{:icon => 'save', :name => 'test', :address => 'test.com'}])
  91 + assert_match /a class="icon-[^"]+"/, render_block_content(l)
90 end 92 end
91 93
92 should 'no class without icon' do 94 should 'no class without icon' do
93 - l = LinkListBlock.new  
94 - assert_no_match /class="/, l.link_html({:icon => nil, :name => 'test', :address => 'test.com'}) 95 + l = LinkListBlock.new(:links => [{:icon => nil, :name => 'test', :address => 'test.com'}])
  96 + assert_no_match /a class="icon-[^"]+"/, render_block_content(l)
95 end 97 end
96 98
97 should 'not add link to javascript' do 99 should 'not add link to javascript' do
98 l = LinkListBlock.new(:links => [{:name => 'link', :address => "javascript:alert('Message test')"}]) 100 l = LinkListBlock.new(:links => [{:name => 'link', :address => "javascript:alert('Message test')"}])
99 - assert_no_match /href="javascript/, l.link_html(l.links.first) 101 + assert_no_match /href="javascript/, render_block_content(l)
100 end 102 end
101 103
102 should 'not add link to onclick' do 104 should 'not add link to onclick' do
103 l = LinkListBlock.new(:links => [{:name => 'link', :address => "#\" onclick=\"alert(123456)"}]) 105 l = LinkListBlock.new(:links => [{:name => 'link', :address => "#\" onclick=\"alert(123456)"}])
104 - assert_no_tag_in_string l.link_html(l.links.first), :attributes => { :onclick => /.*/ } 106 + assert_no_tag_in_string render_block_content(l), :attributes => { :onclick => /.*/ }
105 end 107 end
106 108
107 should 'add protocol in front of incomplete external links' do 109 should 'add protocol in front of incomplete external links' do
108 {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => '//example.org'}.each do |input, output| 110 {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => '//example.org'}.each do |input, output|
109 l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}]) 111 l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}])
110 - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => output} 112 + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => output}
111 end 113 end
112 end 114 end
113 115
@@ -128,7 +130,8 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -128,7 +130,8 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
128 130
129 should 'link with title' do 131 should 'link with title' do
130 l = LinkListBlock.new 132 l = LinkListBlock.new
131 - assert_match /title="mytitle"/, l.link_html({:name => 'mylink', :address => '/myaddress', :title => 'mytitle'}) 133 + l = LinkListBlock.new(:links => [{:name => 'mylink', :address => '/myaddress', :title => 'mytitle'}])
  134 + assert_match /title="mytitle"/, render_block_content(l)
132 end 135 end
133 136
134 end 137 end
test/unit/location_block_test.rb
@@ -18,7 +18,7 @@ class LocationBlockTest &lt; ActiveSupport::TestCase @@ -18,7 +18,7 @@ class LocationBlockTest &lt; ActiveSupport::TestCase
18 end 18 end
19 19
20 should 'display no localization map without lat' do 20 should 'display no localization map without lat' do
21 - assert_tag_in_string extract_block_content(block.content), :tag => 'i' 21 + assert_tag_in_string extract_block_content(render_block_content(block)), :tag => 'i'
22 end 22 end
23 23
24 should 'be editable' do 24 should 'be editable' do
@@ -31,7 +31,7 @@ class LocationBlockTest &lt; ActiveSupport::TestCase @@ -31,7 +31,7 @@ class LocationBlockTest &lt; ActiveSupport::TestCase
31 31
32 should 'use google maps api v3 with ssl' do 32 should 'use google maps api v3 with ssl' do
33 @block.owner.lat = '-12.34'; @block.owner.save! 33 @block.owner.lat = '-12.34'; @block.owner.save!
34 - content = extract_block_content(@block.content) 34 + content = extract_block_content(render_block_content(@block))
35 35
36 assert_match 'https://maps.google.com/maps/api/staticmap', content 36 assert_match 'https://maps.google.com/maps/api/staticmap', content
37 assert_no_match /key=/, content 37 assert_no_match /key=/, content
test/unit/manage_products_helper_test.rb
@@ -5,6 +5,7 @@ class ManageProductsHelperTest &lt; ActionView::TestCase @@ -5,6 +5,7 @@ class ManageProductsHelperTest &lt; ActionView::TestCase
5 5
6 include ManageProductsHelper 6 include ManageProductsHelper
7 include ContentViewerHelper 7 include ContentViewerHelper
  8 + include ArticleHelper
8 include ActionView::Helpers::AssetTagHelper 9 include ActionView::Helpers::AssetTagHelper
9 include ApplicationHelper 10 include ApplicationHelper
10 11
test/unit/my_network_block_test.rb
@@ -19,14 +19,6 @@ class MyNetworkBlockTest &lt; ActiveSupport::TestCase @@ -19,14 +19,6 @@ class MyNetworkBlockTest &lt; ActiveSupport::TestCase
19 assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title 19 assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title
20 end 20 end
21 21
22 - should 'display my-profile' do  
23 - self.expects(:render).with(:file => 'blocks/my_network', :locals => {  
24 - :title => 'My network',  
25 - :owner => owner  
26 - })  
27 - instance_eval(&block.content)  
28 - end  
29 -  
30 should 'be able to update display setting' do 22 should 'be able to update display setting' do
31 user = create_user('testinguser').person 23 user = create_user('testinguser').person
32 box = fast_create(Box, :owner_id => user.id) 24 box = fast_create(Box, :owner_id => user.id)
@@ -37,3 +29,22 @@ class MyNetworkBlockTest &lt; ActiveSupport::TestCase @@ -37,3 +29,22 @@ class MyNetworkBlockTest &lt; ActiveSupport::TestCase
37 end 29 end
38 30
39 end 31 end
  32 +
  33 +class MyNetworkBlockViewTest < ActionView::TestCase
  34 + include BoxesHelper
  35 +
  36 + def setup
  37 + @block = MyNetworkBlock.new
  38 + @owner = Person.new(:identifier => 'testuser')
  39 + @block.stubs(:owner).returns(@owner)
  40 + owner.stubs(:environment).returns(Environment.default)
  41 + end
  42 + attr_reader :owner, :block
  43 +
  44 + should 'display my-profile' do
  45 + ActionView::Base.any_instance.stubs(:block_title).with(anything).returns(true)
  46 + ActionView::Base.any_instance.stubs(:user).with(anything).returns(owner)
  47 + ActionView::Base.any_instance.stubs(:render_profile_actions)
  48 + assert_match "#{Environment.default.top_url}/profile/testuser", render_block_content(block)
  49 + end
  50 +end
test/unit/products_block_test.rb
@@ -20,33 +20,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -20,33 +20,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
20 assert_not_equal Block.description, ProductsBlock.description 20 assert_not_equal Block.description, ProductsBlock.description
21 end 21 end
22 22
23 - should "list owner products" do  
24 - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')  
25 - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)  
26 - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)  
27 -  
28 - block.expects(:products).returns(enterprise.products)  
29 -  
30 - content = block.content  
31 -  
32 - assert_tag_in_string content, :content => 'Products'  
33 -  
34 - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ }  
35 - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ }  
36 - end  
37 -  
38 - should 'point to all products in footer' do  
39 - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')  
40 - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)  
41 - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)  
42 -  
43 - block.stubs(:owner).returns(enterprise)  
44 -  
45 - footer = block.footer  
46 -  
47 - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'  
48 - end  
49 -  
50 should 'list 4 random products by default' do 23 should 'list 4 random products by default' do
51 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') 24 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
52 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) 25 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
@@ -120,18 +93,35 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -120,18 +93,35 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
120 assert_equivalent [p1, p2, p3, p4], block.products 93 assert_equivalent [p1, p2, p3, p4], block.products
121 end 94 end
122 end 95 end
  96 +end
123 97
124 - should 'generate footer when enterprise has own hostname' do 98 +require 'boxes_helper'
  99 +require 'block_helper'
  100 +
  101 +class ProductsBlockViewTest < ActionView::TestCase
  102 + include BoxesHelper
  103 +
  104 + ActionView::Base.send :include, BlockHelper
  105 +
  106 + def setup
  107 + @block = ProductsBlock.new
  108 + @product_category = fast_create(ProductCategory, :name => 'Products')
  109 + end
  110 + attr_reader :block
  111 +
  112 + should "list owner products" do
125 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') 113 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
126 - enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!  
127 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) 114 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
128 create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) 115 create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)
129 116
130 - block.stubs(:owner).returns(enterprise) 117 + block.expects(:products).returns(enterprise.products)
131 118
132 - footer = block.footer 119 + content = render_block_content(block)
133 120
134 - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' 121 + assert_tag_in_string content, :content => 'Products'
  122 +
  123 + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ }
  124 + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ }
135 end 125 end
136 126
137 should 'display the default minor image if thumbnails were not processed' do 127 should 'display the default minor image if thumbnails were not processed' do
@@ -139,8 +129,9 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -139,8 +129,9 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
139 create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) 129 create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
140 130
141 block.expects(:products).returns(enterprise.products) 131 block.expects(:products).returns(enterprise.products)
  132 + ActionView::Base.any_instance.stubs(:block_title).returns("")
142 133
143 - content = block.content 134 + content = render_block_content(block)
144 135
145 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /image-loading-minor.png/ } 136 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /image-loading-minor.png/ }
146 end 137 end
@@ -151,9 +142,34 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -151,9 +142,34 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
151 142
152 process_delayed_job_queue 143 process_delayed_job_queue
153 block.expects(:products).returns(enterprise.products.reload) 144 block.expects(:products).returns(enterprise.products.reload)
  145 + ActionView::Base.any_instance.stubs(:block_title).returns("")
154 146
155 - content = block.content 147 + content = render_block_content(block)
156 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } 148 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ }
157 end 149 end
158 150
  151 + should 'point to all products in footer' do
  152 + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
  153 + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
  154 + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)
  155 +
  156 + block.stubs(:owner).returns(enterprise)
  157 +
  158 + footer = render_block_footer(block)
  159 +
  160 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  161 + end
  162 +
  163 + should 'generate footer when enterprise has own hostname' do
  164 + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
  165 + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!
  166 + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
  167 + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)
  168 +
  169 + block.stubs(:owner).returns(enterprise)
  170 +
  171 + footer = render_block_footer(block)
  172 +
  173 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  174 + end
159 end 175 end
test/unit/profile_image_block_test.rb
1 require_relative "../test_helper" 1 require_relative "../test_helper"
  2 +require 'boxes_helper'
2 3
3 class ProfileImageBlockTest < ActiveSupport::TestCase 4 class ProfileImageBlockTest < ActiveSupport::TestCase
  5 + include BoxesHelper
4 6
5 should 'provide description' do 7 should 'provide description' do
6 assert_not_equal Block.description, ProfileImageBlock.description 8 assert_not_equal Block.description, ProfileImageBlock.description
@@ -9,8 +11,8 @@ class ProfileImageBlockTest &lt; ActiveSupport::TestCase @@ -9,8 +11,8 @@ class ProfileImageBlockTest &lt; ActiveSupport::TestCase
9 should 'display profile image' do 11 should 'display profile image' do
10 block = ProfileImageBlock.new 12 block = ProfileImageBlock.new
11 13
12 - self.expects(:render).with(:file => 'blocks/profile_image', :locals => { :block => block, :show_name => false})  
13 - instance_eval(& block.content) 14 + self.expects(:render).with(:file => 'blocks/profile_image', :locals => { :block => block })
  15 + render_block_content(block)
14 end 16 end
15 17
16 should 'be editable' do 18 should 'be editable' do
test/unit/profile_info_block_test.rb
@@ -16,9 +16,11 @@ class ProfileInfoBlockTest &lt; ActiveSupport::TestCase @@ -16,9 +16,11 @@ class ProfileInfoBlockTest &lt; ActiveSupport::TestCase
16 assert_not_equal Block.description, ProfileInfoBlock.description 16 assert_not_equal Block.description, ProfileInfoBlock.description
17 end 17 end
18 18
  19 + include BoxesHelper
  20 +
19 should 'display profile information' do 21 should 'display profile information' do
20 - self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block})  
21 - instance_eval(& block.content) 22 + self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block })
  23 + render_block_content(block)
22 end 24 end
23 25
24 end 26 end
test/unit/profile_list_block_test.rb
@@ -20,6 +20,8 @@ class ProfileListBlockTest &lt; ActiveSupport::TestCase @@ -20,6 +20,8 @@ class ProfileListBlockTest &lt; ActiveSupport::TestCase
20 assert_equal 20, block.limit 20 assert_equal 20, block.limit
21 end 21 end
22 22
  23 + include BoxesHelper
  24 +
23 should 'list people' do 25 should 'list people' do
24 env = fast_create(Environment) 26 env = fast_create(Environment)
25 27
@@ -30,15 +32,16 @@ class ProfileListBlockTest &lt; ActiveSupport::TestCase @@ -30,15 +32,16 @@ class ProfileListBlockTest &lt; ActiveSupport::TestCase
30 block = ProfileListBlock.new 32 block = ProfileListBlock.new
31 block.stubs(:owner).returns(env) 33 block.stubs(:owner).returns(env)
32 34
33 - self.expects(:profile_image_link).with(person1, :minor).once  
34 - self.expects(:profile_image_link).with(person2, :minor).once  
35 - self.expects(:profile_image_link).with(person3, :minor).once  
36 -  
37 - self.stubs(:tag).returns('<div></div>')  
38 - self.expects(:content_tag).returns('<div></div>').at_least_once  
39 - self.expects(:block_title).returns('block title').at_least_once 35 + ApplicationHelper.class_eval do
  36 + def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
  37 + "<#{profile.name}>"
  38 + end
  39 + end
40 40
41 - assert_kind_of String, instance_eval(&block.content) 41 + content = render_block_content(block)
  42 + assert_match '<testperson1>', content
  43 + assert_match '<testperson2>', content
  44 + assert_match '<testperson3>', content
42 end 45 end
43 46
44 should 'list private profiles' do 47 should 'list private profiles' do
test/unit/profile_search_block_test.rb
@@ -10,14 +10,16 @@ class ProfileSearchBlockTest &lt; ActiveSupport::TestCase @@ -10,14 +10,16 @@ class ProfileSearchBlockTest &lt; ActiveSupport::TestCase
10 assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title 10 assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title
11 end 11 end
12 12
  13 + include BoxesHelper
  14 +
13 should 'render profile search' do 15 should 'render profile search' do
14 person = fast_create(Person) 16 person = fast_create(Person)
15 17
16 block = ProfileSearchBlock.new 18 block = ProfileSearchBlock.new
17 block.stubs(:owner).returns(person) 19 block.stubs(:owner).returns(person)
18 20
19 - self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :title => block.title})  
20 - instance_eval(& block.content) 21 + self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :block => block })
  22 + render_block_content(block)
21 end 23 end
22 24
23 should 'provide view_title' do 25 should 'provide view_title' do
test/unit/raw_html_block_test.rb
@@ -17,9 +17,11 @@ class RawHTMLBlockTest &lt; ActiveSupport::TestCase @@ -17,9 +17,11 @@ class RawHTMLBlockTest &lt; ActiveSupport::TestCase
17 assert_equal html, block.html 17 assert_equal html, block.html
18 end 18 end
19 19
  20 + include BoxesHelper
  21 +
20 should 'return html as content' do 22 should 'return html as content' do
21 block = RawHTMLBlock.new(:html => "HTML") 23 block = RawHTMLBlock.new(:html => "HTML")
22 - assert_match(/HTML$/, block.content) 24 + assert_match /HTML$/, render_block_content(block)
23 end 25 end
24 26
25 should 'not be editable for users without permission' do 27 should 'not be editable for users without permission' do
test/unit/recent_documents_block_test.rb
@@ -35,17 +35,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase @@ -35,17 +35,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase
35 assert_equivalent block.docs, articles 35 assert_equivalent block.docs, articles
36 end 36 end
37 37
38 - should 'link to documents' do  
39 - articles.each do |a|  
40 - expects(:link_to).with(a.title, a.url)  
41 - end  
42 - stubs(:block_title).returns("")  
43 - stubs(:content_tag).returns("")  
44 - stubs(:li).returns("")  
45 -  
46 - instance_eval(&block.content)  
47 - end  
48 -  
49 should 'respect the maximum number of items as configured' do 38 should 'respect the maximum number of items as configured' do
50 block.limit = 3 39 block.limit = 3
51 40
@@ -68,21 +57,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase @@ -68,21 +57,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase
68 assert block.limit > 0 57 assert block.limit > 0
69 end 58 end
70 59
71 - should 'display a link to sitemap with title "All content"' do  
72 - expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)  
73 - expects(:_).with('All content').returns('All content')  
74 -  
75 - instance_eval(&(block.footer))  
76 - end  
77 -  
78 - should 'not display link to sitemap when owner is environment' do  
79 - block = RecentDocumentsBlock.new  
80 - box = mock  
81 - block.expects(:box).returns(box).at_least_once  
82 - box.expects(:owner).returns(Environment.new).at_least_once  
83 - assert_equal nil, block.footer  
84 - end  
85 -  
86 should 'be able to update display setting' do 60 should 'be able to update display setting' do
87 assert @block.update!(:display => 'always') 61 assert @block.update!(:display => 'always')
88 @block.reload 62 @block.reload
@@ -100,3 +74,56 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase @@ -100,3 +74,56 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase
100 assert_equal 0, block.get_limit 74 assert_equal 0, block.get_limit
101 end 75 end
102 end 76 end
  77 +
  78 +require 'boxes_helper'
  79 +
  80 +class RecentDocumentsBlockViewTest < ActionView::TestCase
  81 + include BoxesHelper
  82 +
  83 + def setup
  84 + @articles = []
  85 + @profile = create_user('testinguser').person
  86 + @profile.articles.destroy_all
  87 + ['first', 'second', 'third', 'fourth', 'fifth'].each do |name|
  88 + article = @profile.articles.create!(:name => name)
  89 + @articles << article
  90 + end
  91 +
  92 + box = Box.new
  93 + box.owner = profile
  94 + box.save!
  95 +
  96 +
  97 + @block = RecentDocumentsBlock.new
  98 + @block.box_id = box.id
  99 + @block.save!
  100 +
  101 + end
  102 + attr_reader :block, :profile, :articles
  103 +
  104 + should 'link to documents' do
  105 + articles.each do |a|
  106 + ActionView::Base.any_instance.expects(:link_to).with(a.title, a.url)
  107 + end
  108 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  109 + ActionView::Base.any_instance.stubs(:content_tag).returns("")
  110 + ActionView::Base.any_instance.stubs(:li).returns("")
  111 +
  112 + render_block_content(block)
  113 + end
  114 +
  115 + should 'display a link to sitemap with title "All content"' do
  116 + ActionView::Base.any_instance.expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)
  117 + ActionView::Base.any_instance.expects(:_).with('All content').returns('All content')
  118 +
  119 + render_block_footer(block)
  120 + end
  121 +
  122 + should 'not display link to sitemap when owner is environment' do
  123 + block = RecentDocumentsBlock.new
  124 + box = mock
  125 + block.expects(:box).returns(box).at_least_once
  126 + box.expects(:owner).returns(Environment.new).at_least_once
  127 + assert_equal '', render_block_footer(block)
  128 + end
  129 +end
test/unit/sellers_search_block_test.rb
@@ -10,10 +10,4 @@ class SellersSearchBlockTest &lt; ActiveSupport::TestCase @@ -10,10 +10,4 @@ class SellersSearchBlockTest &lt; ActiveSupport::TestCase
10 assert_not_equal Block.new.default_title, SellersSearchBlock.new.default_title 10 assert_not_equal Block.new.default_title, SellersSearchBlock.new.default_title
11 end 11 end
12 12
13 - should 'not use a fixed title' do  
14 - block = SellersSearchBlock.new(:title => 'my custom title')  
15 - expects(:render).with(:file => 'search/_sellers_form', :locals => { :title => 'my custom title'})  
16 - instance_eval(&block.content)  
17 - end  
18 -  
19 end 13 end
test/unit/slideshow_block_test.rb
1 require_relative "../test_helper" 1 require_relative "../test_helper"
  2 +require 'boxes_helper'
2 3
3 class SlideshowBlockTest < ActiveSupport::TestCase 4 class SlideshowBlockTest < ActiveSupport::TestCase
  5 + include BoxesHelper
4 6
5 def setup 7 def setup
6 @profile = fast_create(Profile) 8 @profile = fast_create(Profile)
@@ -30,7 +32,7 @@ class SlideshowBlockTest &lt; ActiveSupport::TestCase @@ -30,7 +32,7 @@ class SlideshowBlockTest &lt; ActiveSupport::TestCase
30 32
31 block = SlideshowBlock.new 33 block = SlideshowBlock.new
32 block.stubs(:gallery).returns(gallery) 34 block.stubs(:gallery).returns(gallery)
33 - block.content 35 + render_block_content(block)
34 end 36 end
35 37
36 should 'list in random order' do 38 should 'list in random order' do
@@ -42,7 +44,7 @@ class SlideshowBlockTest &lt; ActiveSupport::TestCase @@ -42,7 +44,7 @@ class SlideshowBlockTest &lt; ActiveSupport::TestCase
42 block.stubs(:block_images).returns(images) 44 block.stubs(:block_images).returns(images)
43 images.expects(:shuffle).once.returns(shuffled) 45 images.expects(:shuffle).once.returns(shuffled)
44 46
45 - block.content 47 + render_block_content(block)
46 end 48 end
47 49
48 should 'not shuffle by default' do 50 should 'not shuffle by default' do
test/unit/tags_block_test.rb
@@ -25,47 +25,80 @@ class TagsBlockTest &lt; ActiveSupport::TestCase @@ -25,47 +25,80 @@ class TagsBlockTest &lt; ActiveSupport::TestCase
25 assert_not_equal Block.new.default_title, TagsBlock.new.default_title 25 assert_not_equal Block.new.default_title, TagsBlock.new.default_title
26 end 26 end
27 27
28 - should 'generate links to tags' do  
29 - assert_match /profile\/testinguser\/tags\/first-tag/, block.content  
30 - assert_match /profile\/testinguser\/tags\/second-tag/, block.content  
31 - assert_match /profile\/testinguser\/tags\/third-tag/, block.content 28 + include BoxesHelper
  29 +
  30 + should 'return the max value in the range between zero and limit' do
  31 + block = TagsBlock.new
  32 + assert_equal 12, block.get_limit
32 end 33 end
33 34
34 - should 'generate links to tags on a environment page' do  
35 - @otheruser = create_user('othertestinguser').person  
36 - @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save!  
37 - @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save!  
38 - box = create(Box, :owner => Environment.default)  
39 - @block = create(TagsBlock, :box => box) 35 + should '' do
  36 + block = TagsBlock.new
  37 + block.limit = -5
  38 + assert_equal 0, block.get_limit
  39 + end
  40 +end
  41 +
  42 +require 'tags_helper'
  43 +
  44 +class TagsBlockViewTest < ActionView::TestCase
  45 + include BoxesHelper
  46 +
  47 + ActionView::Base.send :include, TagsHelper
  48 +
  49 + def setup
  50 + @user = create_user('testinguser').person
  51 + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!
  52 + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!
  53 + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save!
40 54
41 - assert_match /3 items[^>]+\/tag\/first-tag/, block.content  
42 - assert_match /3 items[^>]+\/tag\/second-tag/, block.content  
43 - assert_match /one item[^>]+\/tag\/third-tag/, block.content  
44 - assert_match /2 item[^>]+\/tag\/other-tag"/, block.content 55 + box = Box.new
  56 + box.owner = @user
  57 + box.save!
  58 + @block = TagsBlock.new
  59 + @block.box = box
  60 + @block.save
45 end 61 end
  62 + attr_reader :block
46 63
47 should 'return (none) when no tags to display' do 64 should 'return (none) when no tags to display' do
  65 + ActionView::Base.any_instance.stubs(:block_title).returns("")
48 block.owner.expects(:article_tags).returns([]) 66 block.owner.expects(:article_tags).returns([])
49 - assert_equal '', block.content 67 + assert_equal "\n\n\n", render_block_content(block)
50 end 68 end
51 69
52 - should 'generate links when profile has own hostname' do  
53 - @user.domains << Domain.new(:name => 'testuser.net'); @user.save!  
54 - assert_match /profile\/testinguser\/tags\/first-tag/, block.content 70 + should 'order tags alphabetically' do
  71 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  72 + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block)
55 end 73 end
56 74
57 - should 'order tags alphabetically' do  
58 - assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content 75 + should 'generate links to tags' do
  76 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  77 + content = render_block_content(block)
  78 + assert_match /profile\/testinguser\/tags\/first-tag/, content
  79 + assert_match /profile\/testinguser\/tags\/second-tag/, content
  80 + assert_match /profile\/testinguser\/tags\/third-tag/, content
59 end 81 end
60 82
61 - should 'return the max value in the range between zero and limit' do  
62 - block = TagsBlock.new  
63 - assert_equal 12, block.get_limit 83 + should 'generate links to tags on a environment page' do
  84 + @otheruser = create_user('othertestinguser').person
  85 + @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save!
  86 + @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save!
  87 + box = create(Box, :owner => Environment.default)
  88 + @block = create(TagsBlock, :box => box)
  89 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  90 +
  91 + content = render_block_content(block)
  92 + assert_match /3 items[^>]+\/tag\/first-tag/, content
  93 + assert_match /3 items[^>]+\/tag\/second-tag/, content
  94 + assert_match /one item[^>]+\/tag\/third-tag/, content
  95 + assert_match /2 item[^>]+\/tag\/other-tag"/, content
64 end 96 end
65 97
66 - should '' do  
67 - block = TagsBlock.new  
68 - block.limit = -5  
69 - assert_equal 0, block.get_limit 98 +
  99 + should 'generate links when profile has own hostname' do
  100 + @user.domains << Domain.new(:name => 'testuser.net'); @user.save!
  101 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  102 + assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block)
70 end 103 end
71 end 104 end