Commit dbb2c156568f7ad6f0326dc9565d77bb4314c84a

Authored by Rodrigo Souto
2 parents fe66361c d53e71f1

Merge branch 'decouple_people_block_plugin_html' into 'master'

Decouple people block plugin Model html generation

As a follow up for !803. This applies the same refactor to PeopleBlockPlugin removing HTML generation from models.

Here is a build: https://travis-ci.org/rafamanzo/noosfero/builds/117720302

As it involved many changes, I figured it would be worth of its own MR. I'll work on other block plugins refactor following. Please let me know if you do not want one MR for each.

See merge request !817
app/helpers/application_helper.rb
... ... @@ -50,6 +50,10 @@ module ApplicationHelper
50 50  
51 51 include ButtonsHelper
52 52  
  53 + include ProfileImageHelper
  54 +
  55 + include ThemeLoaderHelper
  56 +
53 57 def locale
54 58 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
55 59 end
... ... @@ -281,48 +285,6 @@ module ApplicationHelper
281 285 end
282 286 end
283 287  
284   - def theme_path
285   - if session[:theme]
286   - '/user_themes/' + current_theme
287   - else
288   - '/designs/themes/' + current_theme
289   - end
290   - end
291   -
292   - def current_theme
293   - @current_theme ||=
294   - begin
295   - if session[:theme]
296   - session[:theme]
297   - else
298   - # utility for developers: set the theme to 'random' in development mode and
299   - # you will get a different theme every request. This is interesting for
300   - # testing
301   - if Rails.env.development? && environment.theme == 'random'
302   - @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
303   - @random_theme
304   - elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
305   - params[:theme]
306   - else
307   - if profile && !profile.theme.nil?
308   - profile.theme
309   - elsif environment
310   - environment.theme
311   - else
312   - if logger
313   - logger.warn("No environment found. This is weird.")
314   - logger.warn("Request environment: %s" % request.env.inspect)
315   - logger.warn("Request parameters: %s" % params.inspect)
316   - end
317   -
318   - # could not determine the theme, so return the default one
319   - 'default'
320   - end
321   - end
322   - end
323   - end
324   - end
325   -
326 288 def theme_view_file(template, theme=nil)
327 289 # Since we cannot control what people are doing in external themes, we
328 290 # will keep looking for the deprecated .rhtml extension here.
... ... @@ -395,141 +357,6 @@ module ApplicationHelper
395 357 Theme.find(current_theme).owner.identifier
396 358 end
397 359  
398   - # generates a image tag for the profile.
399   - #
400   - # If the profile has no image set yet, then a default image is used.
401   - def profile_image(profile, size=:portrait, opt={})
402   - return '' if profile.nil?
403   - opt[:alt] ||= profile.name()
404   - opt[:title] ||= ''
405   - opt[:class] ||= ''
406   - opt[:class] += ( profile.class == Person ? ' photo' : ' logo' )
407   - image_tag(profile_icon(profile, size), opt )
408   - end
409   -
410   - def profile_icon( profile, size=:portrait, return_mimetype=false )
411   - filename, mimetype = '', 'image/png'
412   - if profile.image
413   - filename = profile.image.public_filename( size )
414   - mimetype = profile.image.content_type
415   - else
416   - icon =
417   - if profile.organization?
418   - if profile.kind_of?(Community)
419   - '/images/icons-app/community-'+ size.to_s() +'.png'
420   - else
421   - '/images/icons-app/enterprise-'+ size.to_s() +'.png'
422   - end
423   - else
424   - pixels = Image.attachment_options[:thumbnails][size].split('x').first
425   - gravatar_profile_image_url(
426   - profile.email,
427   - :size => pixels,
428   - :d => gravatar_default
429   - )
430   - end
431   - filename = default_or_themed_icon(icon)
432   - end
433   - return_mimetype ? [filename, mimetype] : filename
434   - end
435   -
436   - def default_or_themed_icon(icon)
437   - if File.exists?(Rails.root.join('public', theme_path, icon))
438   - theme_path + icon
439   - else
440   - icon
441   - end
442   - end
443   -
444   - def profile_sex_icon( profile )
445   - return '' unless profile.is_a?(Person)
446   - return '' unless !environment.enabled?('disable_gender_icon')
447   - sex = ( profile.sex ? profile.sex.to_s() : 'undef' )
448   - title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) )
449   - sex = content_tag 'span',
450   - content_tag( 'span', sex ),
451   - :class => 'sex-'+sex,
452   - :title => title
453   - sex
454   - end
455   -
456   - def links_for_balloon(profile)
457   - if environment.enabled?(:show_balloon_with_profile_links_when_clicked)
458   - if profile.kind_of?(Person)
459   - [
460   - {_('Wall') => {:href => url_for(profile.public_profile_url)}},
461   - {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}},
462   - {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}},
463   - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
464   - {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}}
465   - ]
466   - elsif profile.kind_of?(Community)
467   - [
468   - {_('Wall') => {:href => url_for(profile.public_profile_url)}},
469   - {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
470   - {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
471   - {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}},
472   - {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}},
473   - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}
474   - ]
475   - elsif profile.kind_of?(Enterprise)
476   - [
477   - {_('Products') => {:href => catalog_path(profile.identifier)}},
478   - {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
479   - {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
480   - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
481   - ]
482   - else
483   - []
484   - end
485   - end
486   - end
487   -
488   - # displays a link to the profile homepage with its image (as generated by
489   - # #profile_image) and its name below it.
490   - def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
491   - if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info)
492   - return instance_exec(&content)
493   - end
494   - name = profile.short_name
495   - if profile.person?
496   - url = url_for(profile.check_friendship_url)
497   - trigger_class = 'person-trigger'
498   - else
499   - city = ''
500   - url = url_for(profile.check_membership_url)
501   - if profile.community?
502   - trigger_class = 'community-trigger'
503   - elsif profile.enterprise?
504   - trigger_class = 'enterprise-trigger'
505   - end
506   - end
507   -
508   - extra_info_tag = ''
509   - img_class = 'profile-image'
510   -
511   - if extra_info.is_a? Hash
512   - extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
513   - img_class +=' '+extra_info[:class]
514   - else
515   - extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
516   - end
517   -
518   - links = links_for_balloon(profile)
519   - content_tag('div', content_tag(tag,
520   - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ?
521   - popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
522   - link_to(
523   - content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
524   - content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
525   - extra_info_tag + profile_sex_icon( profile ),
526   - profile.url,
527   - :class => 'profile_link url',
528   - :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
529   - :title => profile.name ),
530   - :class => 'vcard'), :class => 'common-profile-list-block')
531   - end
532   -
533 360 def popover_menu(title,menu_title,links,html_options={})
534 361 html_options[:class] = "" unless html_options[:class]
535 362 html_options[:class] << " menu-submenu-trigger"
... ... @@ -538,10 +365,6 @@ module ApplicationHelper
538 365 link_to(content_tag(:span, title), '#', html_options)
539 366 end
540 367  
541   - def gravatar_default
542   - (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm'
543   - end
544   -
545 368 attr_reader :environment
546 369  
547 370 def select_categories(object_name, title=nil, title_size=4)
... ...
app/helpers/profile_image_helper.rb 0 → 100644
... ... @@ -0,0 +1,140 @@
  1 +module ProfileImageHelper
  2 + def default_or_themed_icon(icon)
  3 + if File.exists?(Rails.root.join('public', theme_path, icon))
  4 + theme_path + icon
  5 + else
  6 + icon
  7 + end
  8 + end
  9 +
  10 + def gravatar_default
  11 + (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm'
  12 + end
  13 +
  14 + def profile_sex_icon( profile )
  15 + return '' unless profile.is_a?(Person)
  16 + return '' unless !environment.enabled?('disable_gender_icon')
  17 + sex = ( profile.sex ? profile.sex.to_s() : 'undef' )
  18 + title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) )
  19 + sex = content_tag 'span',
  20 + content_tag( 'span', sex ),
  21 + :class => 'sex-'+sex,
  22 + :title => title
  23 + sex
  24 + end
  25 +
  26 + def profile_icon( profile, size=:portrait, return_mimetype=false )
  27 + filename, mimetype = '', 'image/png'
  28 + if profile.image
  29 + filename = profile.image.public_filename( size )
  30 + mimetype = profile.image.content_type
  31 + else
  32 + icon =
  33 + if profile.organization?
  34 + if profile.kind_of?(Community)
  35 + '/images/icons-app/community-'+ size.to_s() +'.png'
  36 + else
  37 + '/images/icons-app/enterprise-'+ size.to_s() +'.png'
  38 + end
  39 + else
  40 + pixels = Image.attachment_options[:thumbnails][size].split('x').first
  41 + gravatar_profile_image_url(
  42 + profile.email,
  43 + :size => pixels,
  44 + :d => gravatar_default
  45 + )
  46 + end
  47 + filename = default_or_themed_icon(icon)
  48 + end
  49 + return_mimetype ? [filename, mimetype] : filename
  50 + end
  51 +
  52 + # generates a image tag for the profile.
  53 + #
  54 + # If the profile has no image set yet, then a default image is used.
  55 + def profile_image(profile, size=:portrait, opt={})
  56 + return '' if profile.nil?
  57 + opt[:alt] ||= profile.name()
  58 + opt[:title] ||= ''
  59 + opt[:class] ||= ''
  60 + opt[:class] += ( profile.class == Person ? ' photo' : ' logo' )
  61 + image_tag(profile_icon(profile, size), opt )
  62 + end
  63 +
  64 + def links_for_balloon(profile)
  65 + if environment.enabled?(:show_balloon_with_profile_links_when_clicked)
  66 + if profile.kind_of?(Person)
  67 + [
  68 + {_('Wall') => {:href => url_for(profile.public_profile_url)}},
  69 + {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}},
  70 + {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}},
  71 + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
  72 + {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}}
  73 + ]
  74 + elsif profile.kind_of?(Community)
  75 + [
  76 + {_('Wall') => {:href => url_for(profile.public_profile_url)}},
  77 + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
  78 + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
  79 + {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}},
  80 + {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}},
  81 + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}
  82 + ]
  83 + elsif profile.kind_of?(Enterprise)
  84 + [
  85 + {_('Products') => {:href => catalog_path(profile.identifier)}},
  86 + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}},
  87 + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}},
  88 + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}},
  89 + ]
  90 + else
  91 + []
  92 + end
  93 + end
  94 + end
  95 +
  96 + # displays a link to the profile homepage with its image (as generated by
  97 + # #profile_image) and its name below it.
  98 + def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil )
  99 + if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info)
  100 + return instance_exec(&content)
  101 + end
  102 + name = profile.short_name
  103 + if profile.person?
  104 + url = url_for(profile.check_friendship_url)
  105 + trigger_class = 'person-trigger'
  106 + else
  107 + city = ''
  108 + url = url_for(profile.check_membership_url)
  109 + if profile.community?
  110 + trigger_class = 'community-trigger'
  111 + elsif profile.enterprise?
  112 + trigger_class = 'enterprise-trigger'
  113 + end
  114 + end
  115 +
  116 + extra_info_tag = ''
  117 + img_class = 'profile-image'
  118 +
  119 + if extra_info.is_a? Hash
  120 + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
  121 + img_class +=' '+extra_info[:class]
  122 + else
  123 + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' )
  124 + end
  125 +
  126 + links = links_for_balloon(profile)
  127 + content_tag('div', content_tag(tag,
  128 + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ?
  129 + popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") +
  130 + link_to(
  131 + content_tag( 'span', profile_image( profile, size ), :class => img_class ) +
  132 + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
  133 + extra_info_tag + profile_sex_icon( profile ),
  134 + profile.url,
  135 + :class => 'profile_link url',
  136 + :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
  137 + :title => profile.name ),
  138 + :class => 'vcard'), :class => 'common-profile-list-block')
  139 + end
  140 +end
0 141 \ No newline at end of file
... ...
app/helpers/theme_loader_helper.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +module ThemeLoaderHelper
  2 + def current_theme
  3 + @current_theme ||=
  4 + begin
  5 + if session[:theme]
  6 + session[:theme]
  7 + else
  8 + # utility for developers: set the theme to 'random' in development mode and
  9 + # you will get a different theme every request. This is interesting for
  10 + # testing
  11 + if Rails.env.development? && environment.theme == 'random'
  12 + @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand
  13 + @random_theme
  14 + elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme]))
  15 + params[:theme]
  16 + else
  17 + if profile && !profile.theme.nil?
  18 + profile.theme
  19 + elsif environment
  20 + environment.theme
  21 + else
  22 + if logger
  23 + logger.warn("No environment found. This is weird.")
  24 + logger.warn("Request environment: %s" % request.env.inspect)
  25 + logger.warn("Request parameters: %s" % params.inspect)
  26 + end
  27 +
  28 + # could not determine the theme, so return the default one
  29 + 'default'
  30 + end
  31 + end
  32 + end
  33 + end
  34 + end
  35 +
  36 + def theme_path
  37 + if session[:theme]
  38 + '/user_themes/' + current_theme
  39 + else
  40 + '/designs/themes/' + current_theme
  41 + end
  42 + end
  43 +end
... ...
plugins/people_block/lib/friends_block.rb
... ... @@ -20,14 +20,6 @@ class FriendsBlock &lt; PeopleBlockBase
20 20 owner.suggested_profiles.of_person.enabled.limit(3).includes(:suggestion)
21 21 end
22 22  
23   - def footer
24   - profile = self.owner
25   - suggestions = self.suggestions
26   - proc do
27   - render :file => 'blocks/friends', :locals => { :profile => profile, :suggestions => suggestions }
28   - end
29   - end
30   -
31 23 def self.expire_on
32 24 { :profile => [:profile] }
33 25 end
... ...
plugins/people_block/lib/members_block.rb
... ... @@ -20,15 +20,6 @@ class MembersBlock &lt; PeopleBlockBase
20 20 role ? owner.members.with_role(role.id) : owner.members
21 21 end
22 22  
23   - def footer
24   - profile = self.owner
25   - role_key = visible_role
26   - s = show_join_leave_button
27   - proc do
28   - render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key}
29   - end
30   - end
31   -
32 23 def role
33 24 visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil
34 25 end
... ...
plugins/people_block/lib/people_block.rb
... ... @@ -15,11 +15,4 @@ class PeopleBlock &lt; PeopleBlockBase
15 15 def profiles
16 16 owner.people
17 17 end
18   -
19   - def footer
20   - proc do
21   - render :file => 'blocks/people'
22   - end
23   - end
24   -
25 18 end
... ...
plugins/people_block/lib/people_block_base.rb
... ... @@ -42,57 +42,6 @@ class PeopleBlockBase &lt; Block
42 42 profiles.visible.count
43 43 end
44 44  
45   - def content(args={})
46   - profiles = self.profile_list
47   - title = self.view_title
48   -
49   - if !self.name.blank? && !self.address.blank?
50   - name = self.name
51   - expanded_address = expand_address(self.address)
52   - end
53   -
54   - proc do
55   - count = 0
56   - list = profiles.map {|item|
57   - count += 1
58   - send(:profile_image_link, item, :minor )
59   - }.join("\n")
60   - if list.empty?
61   - list = content_tag 'div', c_('None'), :class => 'common-profile-list-block-none'
62   - else
63   - if !name.blank? && !expanded_address.blank?
64   - list << content_tag(
65   - 'div',
66   - content_tag(
67   - 'li',
68   - content_tag(
69   - 'div',
70   - link_to(
71   - content_tag('span', name, :class => 'banner-span' ),
72   - expanded_address,
73   - :title => name
74   - ),
75   - :class => 'banner-div'
76   - ),
77   - :class => 'vcard'
78   - ),
79   - :class => 'common-profile-list-block'
80   - )
81   - end
82   - list = content_tag 'ul', list
83   - end
84   - block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both'))
85   - end
86   - end
87   -
88   - def expand_address(address)
89   - if address !~ /^[a-z]+:\/\// && address !~ /^\//
90   - 'http://' + address
91   - else
92   - address
93   - end
94   - end
95   -
96 45 def extra_option
97 46 { }
98 47 end
... ...
plugins/people_block/lib/people_block_helper.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +module PeopleBlockHelper
  2 + def profiles_images_list(profiles)
  3 + profiles.map { |profile| profile_image_link(profile, :minor) }.join("\n")
  4 + end
  5 +
  6 + def set_address_protocol(address)
  7 + !URI.parse(address).scheme ? 'http://'+address : address
  8 + end
  9 +end
... ...
plugins/people_block/test/unit/friends_block_test.rb
... ... @@ -60,39 +60,6 @@ class FriendsBlockTest &lt; ActionView::TestCase
60 60 assert_equal 20, block.limit
61 61 end
62 62  
63   - should 'list friends from person' do
64   - owner = fast_create(Person)
65   - friend1 = fast_create(Person)
66   - friend2 = fast_create(Person)
67   - owner.add_friend(friend1)
68   - owner.add_friend(friend2)
69   -
70   - block = FriendsBlock.new
71   -
72   - block.expects(:owner).returns(owner).at_least_once
73   - expects(:profile_image_link).with(friend1, :minor).returns(friend1.name)
74   - expects(:profile_image_link).with(friend2, :minor).returns(friend2.name)
75   - expects(:block_title).with(anything).returns('')
76   -
77   - content = instance_eval(&block.content)
78   -
79   - assert_match(/#{friend1.name}/, content)
80   - assert_match(/#{friend2.name}/, content)
81   - end
82   -
83   - should 'link to "all friends"' do
84   - person1 = create_user('mytestperson').person
85   -
86   - block = FriendsBlock.new
87   - block.stubs(:suggestions).returns([])
88   - block.expects(:owner).returns(person1).at_least_once
89   -
90   - instance_eval(&block.footer)
91   - assert_select 'a.view-all' do |elements|
92   - assert_select '[href=/profile/mytestperson/friends]'
93   - end
94   - end
95   -
96 63 should 'count number of owner friends' do
97 64 owner = fast_create(Person)
98 65 friend1 = fast_create(Person)
... ... @@ -151,3 +118,39 @@ class FriendsBlockTest &lt; ActionView::TestCase
151 118 include NoosferoTestHelper
152 119  
153 120 end
  121 +
  122 +require 'boxes_helper'
  123 +
  124 +class FriendsBlockViewTest < ActionView::TestCase
  125 + include BoxesHelper
  126 +
  127 + should 'list friends from person' do
  128 + owner = fast_create(Person)
  129 + friend1 = fast_create(Person)
  130 + friend2 = fast_create(Person)
  131 + owner.add_friend(friend1)
  132 + owner.add_friend(friend2)
  133 +
  134 + block = FriendsBlock.new
  135 +
  136 + block.expects(:owner).returns(owner).at_least_once
  137 + ActionView::Base.any_instance.expects(:profile_image_link).with(friend1, :minor).returns(friend1.name)
  138 + ActionView::Base.any_instance.expects(:profile_image_link).with(friend2, :minor).returns(friend2.name)
  139 + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('')
  140 +
  141 + content = render_block_content(block)
  142 +
  143 + assert_match(/#{friend1.name}/, content)
  144 + assert_match(/#{friend2.name}/, content)
  145 + end
  146 +
  147 + should 'link to "all friends"' do
  148 + person1 = create_user('mytestperson').person
  149 +
  150 + block = FriendsBlock.new
  151 + block.stubs(:suggestions).returns([])
  152 + block.expects(:owner).returns(person1).at_least_once
  153 +
  154 + assert_tag_in_string render_block_footer(block), tag: 'a', attributes: {class: 'view-all', href: '/profile/mytestperson/friends' }
  155 + end
  156 +end
... ...
plugins/people_block/test/unit/members_block_test.rb
... ... @@ -90,26 +90,6 @@ class MembersBlockTest &lt; ActionView::TestCase
90 90 end
91 91  
92 92  
93   - should 'list members from community' do
94   - owner = fast_create(Community)
95   - person1 = fast_create(Person)
96   - person2 = fast_create(Person)
97   - owner.add_member(person1)
98   - owner.add_member(person2)
99   -
100   - block = MembersBlock.new
101   -
102   - block.expects(:owner).returns(owner).at_least_once
103   - expects(:profile_image_link).with(person1, :minor).returns(person1.name)
104   - expects(:profile_image_link).with(person2, :minor).returns(person2.name)
105   - expects(:block_title).with(anything).returns('')
106   -
107   - content = instance_eval(&block.content)
108   -
109   - assert_match(/#{person1.name}/, content)
110   - assert_match(/#{person2.name}/, content)
111   - end
112   -
113 93 should 'count number of public and private members' do
114 94 owner = fast_create(Community)
115 95 private_p = fast_create(Person, {:public_profile => false})
... ... @@ -139,57 +119,6 @@ class MembersBlockTest &lt; ActionView::TestCase
139 119 assert_equal 1, block.profile_count
140 120 end
141 121  
142   - should 'provide link to members page without a visible_role selected' do
143   - profile = create_user('mytestuser').person
144   - block = MembersBlock.new
145   - block.box = profile.boxes.first
146   - block.save!
147   -
148   - instance_eval(&block.footer)
149   - assert_select 'a.view-all' do |elements|
150   - assert_select "[href=/profile/mytestuser/members#members-tab]"
151   - end
152   - end
153   -
154   - should 'provide link to members page when visible_role is profile_member' do
155   - profile = create_user('mytestuser').person
156   - block = MembersBlock.new
157   - block.box = profile.boxes.first
158   - block.visible_role = 'profile_member'
159   - block.save!
160   -
161   - instance_eval(&block.footer)
162   - assert_select 'a.view-all' do |elements|
163   - assert_select '[href=/profile/mytestuser/members#members-tab]'
164   - end
165   - end
166   -
167   - should 'provide link to members page when visible_role is profile_moderator' do
168   - profile = create_user('mytestuser').person
169   - block = MembersBlock.new
170   - block.box = profile.boxes.first
171   - block.visible_role = 'profile_moderator'
172   - block.save!
173   -
174   - instance_eval(&block.footer)
175   - assert_select 'a.view-all' do |elements|
176   - assert_select '[href=/profile/mytestuser/members#members-tab]'
177   - end
178   - end
179   -
180   - should 'provide link to admins page when visible_role is profile_admin' do
181   - profile = create_user('mytestuser').person
182   - block = MembersBlock.new
183   - block.box = profile.boxes.first
184   - block.visible_role = 'profile_admin'
185   - block.save!
186   -
187   - instance_eval(&block.footer)
188   - assert_select 'a.view-all' do |elements|
189   - assert_select '[href=/profile/mytestuser/members#admins-tab]'
190   - end
191   - end
192   -
193 122 should 'provide a role to be displayed (and default to nil)' do
194 123 env = fast_create(Environment)
195 124 env.boxes << Box.new
... ... @@ -299,3 +228,82 @@ class MembersBlockTest &lt; ActionView::TestCase
299 228 include NoosferoTestHelper
300 229  
301 230 end
  231 +
  232 +require 'boxes_helper'
  233 +
  234 +class MembersBlockViewTest < ActionView::TestCase
  235 + include BoxesHelper
  236 +
  237 + should 'list members from community' do
  238 + owner = fast_create(Community)
  239 + person1 = fast_create(Person)
  240 + person2 = fast_create(Person)
  241 + owner.add_member(person1)
  242 + owner.add_member(person2)
  243 + profile = Profile.new
  244 + profile.identifier = 42
  245 +
  246 + block = MembersBlock.new
  247 +
  248 + block.expects(:owner).returns(owner).at_least_once
  249 + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  250 + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  251 + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('')
  252 +
  253 + content = render_block_content(block)
  254 +
  255 + assert_match(/#{person1.name}/, content)
  256 + assert_match(/#{person2.name}/, content)
  257 + end
  258 +
  259 + should 'provide link to members page without a visible_role selected' do
  260 + profile = create_user('mytestuser').person
  261 + block = MembersBlock.new
  262 + block.box = profile.boxes.first
  263 + block.save!
  264 +
  265 + render_block_footer(block)
  266 + assert_select 'a.view-all' do |elements|
  267 + assert_select "[href=/profile/mytestuser/members#members-tab]"
  268 + end
  269 + end
  270 +
  271 + should 'provide link to members page when visible_role is profile_member' do
  272 + profile = create_user('mytestuser').person
  273 + block = MembersBlock.new
  274 + block.box = profile.boxes.first
  275 + block.visible_role = 'profile_member'
  276 + block.save!
  277 +
  278 + render_block_footer(block)
  279 + assert_select 'a.view-all' do |elements|
  280 + assert_select '[href=/profile/mytestuser/members#members-tab]'
  281 + end
  282 + end
  283 +
  284 + should 'provide link to members page when visible_role is profile_moderator' do
  285 + profile = create_user('mytestuser').person
  286 + block = MembersBlock.new
  287 + block.box = profile.boxes.first
  288 + block.visible_role = 'profile_moderator'
  289 + block.save!
  290 +
  291 + render_block_footer(block)
  292 + assert_select 'a.view-all' do |elements|
  293 + assert_select '[href=/profile/mytestuser/members#members-tab]'
  294 + end
  295 + end
  296 +
  297 + should 'provide link to admins page when visible_role is profile_admin' do
  298 + profile = create_user('mytestuser').person
  299 + block = MembersBlock.new
  300 + block.box = profile.boxes.first
  301 + block.visible_role = 'profile_admin'
  302 + block.save!
  303 +
  304 + render_block_footer(block)
  305 + assert_select 'a.view-all' do |elements|
  306 + assert_select '[href=/profile/mytestuser/members#admins-tab]'
  307 + end
  308 + end
  309 +end
... ...
plugins/people_block/test/unit/people_block_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +require 'test_helper'
  2 +
  3 +class PeopleBlockHelperTest < ActionView::TestCase
  4 + include PeopleBlockHelper
  5 +
  6 + should 'list profiles as images links' do
  7 + owner = fast_create(Environment)
  8 + profiles = [
  9 + fast_create(Person, :environment_id => owner.id),
  10 + fast_create(Person, :environment_id => owner.id),
  11 + fast_create(Person, :environment_id => owner.id)
  12 + ]
  13 + link_html = "<a href=#><img src='' /></a>"
  14 +
  15 + profiles.each do |profile|
  16 + expects(:profile_image_link).with(profile, :minor).returns(link_html)
  17 + end
  18 +
  19 + list = profiles_images_list(profiles)
  20 +
  21 + assert_equal list, ([link_html]*profiles.count).join("\n")
  22 + end
  23 +
  24 + should 'prepend the protocol to urls missing it' do
  25 + address = 'noosfero.org'
  26 +
  27 + assert_equal set_address_protocol(address), 'http://'+address
  28 + end
  29 +
  30 + should 'leave urls already with protocol unchanged' do
  31 + address = 'http://noosfero.org'
  32 + ssl_address = 'https://noosfero.org'
  33 +
  34 + assert_equal set_address_protocol(address), address
  35 + assert_equal set_address_protocol(ssl_address), ssl_address
  36 + end
  37 +end
0 38 \ No newline at end of file
... ...
plugins/people_block/test/unit/people_block_test.rb
... ... @@ -85,36 +85,6 @@ class PeopleBlockTest &lt; ActionView::TestCase
85 85 end
86 86  
87 87  
88   - should 'list people from environment' do
89   - owner = fast_create(Environment)
90   - person1 = fast_create(Person, :environment_id => owner.id)
91   - person2 = fast_create(Person, :environment_id => owner.id)
92   -
93   - block = PeopleBlock.new
94   -
95   - block.expects(:owner).returns(owner).at_least_once
96   - expects(:profile_image_link).with(person1, :minor).returns(person1.name)
97   - expects(:profile_image_link).with(person2, :minor).returns(person2.name)
98   - expects(:block_title).with(anything).returns('')
99   -
100   - content = instance_exec(&block.content)
101   -
102   - assert_match(/#{person1.name}/, content)
103   - assert_match(/#{person2.name}/, content)
104   - end
105   -
106   -
107   - should 'link to "all people"' do
108   - env = fast_create(Environment)
109   - block = PeopleBlock.new
110   -
111   - instance_eval(&block.footer)
112   - assert_select 'a.view-all' do |elements|
113   - assert_select '[href=/search/people]'
114   - end
115   - end
116   -
117   -
118 88 should 'count number of public and private people' do
119 89 owner = fast_create(Environment)
120 90 private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id)
... ... @@ -142,3 +112,37 @@ class PeopleBlockTest &lt; ActionView::TestCase
142 112 include NoosferoTestHelper
143 113  
144 114 end
  115 +
  116 +require 'boxes_helper'
  117 +
  118 +class PeopleBlockViewTest < ActionView::TestCase
  119 + include BoxesHelper
  120 +
  121 + should 'list people from environment' do
  122 + owner = fast_create(Environment)
  123 + person1 = fast_create(Person, :environment_id => owner.id)
  124 + person2 = fast_create(Person, :environment_id => owner.id)
  125 +
  126 + block = PeopleBlock.new
  127 +
  128 + block.expects(:owner).returns(owner).at_least_once
  129 + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name)
  130 + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name)
  131 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  132 +
  133 + content = render_block_content(block)
  134 +
  135 + assert_match(/#{person1.name}/, content)
  136 + assert_match(/#{person2.name}/, content)
  137 + end
  138 +
  139 + should 'link to "all people"' do
  140 + env = fast_create(Environment)
  141 + block = PeopleBlock.new
  142 +
  143 + render_block_footer(block)
  144 + assert_select 'a.view-all' do |elements|
  145 + assert_select '[href=/search/people]'
  146 + end
  147 + end
  148 +end
... ...
plugins/people_block/views/blocks/footers/friends.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<%= link_to s_('friends|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %>
  2 +
  3 +<% if !block.suggestions.empty? && user == block.owner %>
  4 + <div class='suggestions-block common-profile-list-block'>
  5 + <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>
  6 + <div class='profiles-suggestions'>
  7 + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => block.suggestions, :collection => :friends_suggestions } %>
  8 + </div>
  9 + <div class='more-suggestions'>
  10 + <%= link_to _('See all suggestions'), block.owner.people_suggestions_url %>
  11 + </div>
  12 + </div>
  13 +<% end %>
... ...
plugins/people_block/views/blocks/footers/members.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<% anchor = block.visible_role == "profile_admin" ? "admins-tab" : "members-tab" %>
  2 +<%= link_to c_('View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %>
  3 +
  4 +<% if block.show_join_leave_button %>
  5 + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %>
  6 +<% end %>
... ...
plugins/people_block/views/blocks/footers/people.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %>
... ...
plugins/people_block/views/blocks/friends.html.erb
... ... @@ -1,13 +0,0 @@
1   -<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %>
2   -
3   -<% if !suggestions.empty? && user == profile %>
4   - <div class='suggestions-block common-profile-list-block'>
5   - <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>
6   - <div class='profiles-suggestions'>
7   - <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :friends_suggestions } %>
8   - </div>
9   - <div class='more-suggestions'>
10   - <%= link_to _('See all suggestions'), profile.people_suggestions_url %>
11   - </div>
12   - </div>
13   -<% end %>
plugins/people_block/views/blocks/members.html.erb
... ... @@ -1,6 +0,0 @@
1   -<% anchor = role_key == "profile_admin" ? "admins-tab" : "members-tab" %>
2   -<%= link_to c_('View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %>
3   -
4   -<% if show_join_leave_button %>
5   - <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %>
6   -<% end %>
plugins/people_block/views/blocks/people.html.erb
... ... @@ -1 +0,0 @@
1   -<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %>
plugins/people_block/views/blocks/people_base.html.erb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +<% extend PeopleBlockHelper %>
  2 +
  3 +<%= block_title(block.view_title) %>
  4 +
  5 +<div>
  6 + <% unless block.profiles.count == 0 %>
  7 + <ul>
  8 + <%= profiles_images_list(block.profiles) %>
  9 +
  10 + <% unless block.name.blank? || block.address.blank? %>
  11 + <div class="common-profile-list-block">
  12 + <li class="vcard">
  13 + <div class="banner-div">
  14 + <%= link_to(
  15 + content_tag('span', block.name, :class => 'banner-span' ),
  16 + set_address_protocol(block.address),
  17 + title: block.name
  18 + ) %>
  19 + </div>
  20 + </li>
  21 + </div>
  22 + <% end %>
  23 + </ul>
  24 + <% else %>
  25 + <div class="common-profile-list-block-none"><%= c_('None') %></div>
  26 + <% end %>
  27 + <br style="clear:both" />
  28 +</div>
... ...
test/unit/application_helper_test.rb
... ... @@ -145,35 +145,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
145 145 assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator'
146 146 end
147 147  
148   - should 'get theme from environment by default' do
149   - @environment = mock
150   - @environment.stubs(:theme).returns('my-environment-theme')
151   - stubs(:profile).returns(nil)
152   - assert_equal 'my-environment-theme', current_theme
153   - end
154   -
155   - should 'get theme from profile when profile is present' do
156   - profile = mock
157   - profile.stubs(:theme).returns('my-profile-theme')
158   - stubs(:profile).returns(profile)
159   - assert_equal 'my-profile-theme', current_theme
160   - end
161   -
162   - should 'override theme with testing theme from session' do
163   - stubs(:session).returns(:theme => 'theme-under-test')
164   - assert_equal 'theme-under-test', current_theme
165   - end
166   -
167   - should 'point to system theme path by default' do
168   - expects(:current_theme).returns('my-system-theme')
169   - assert_equal '/designs/themes/my-system-theme', theme_path
170   - end
171   -
172   - should 'point to user theme path when testing theme' do
173   - stubs(:session).returns({:theme => 'theme-under-test'})
174   - assert_equal '/user_themes/theme-under-test', theme_path
175   - end
176   -
177 148 should 'render theme footer' do
178 149 stubs(:theme_path).returns('/user_themes/mytheme')
179 150 footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb')
... ... @@ -295,38 +266,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
295 266 assert_nil select_categories(mock)
296 267 end
297 268  
298   - should 'provide sex icon for males' do
299   - stubs(:environment).returns(Environment.default)
300   - expects(:content_tag).with(anything, 'male').returns('MALE!!')
301   - expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL")
302   - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male'))
303   - end
304   -
305   - should 'provide sex icon for females' do
306   - stubs(:environment).returns(Environment.default)
307   - expects(:content_tag).with(anything, 'female').returns('FEMALE!!')
308   - expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL")
309   - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female'))
310   - end
311   -
312   - should 'provide undef sex icon' do
313   - stubs(:environment).returns(Environment.default)
314   - expects(:content_tag).with(anything, 'undef').returns('UNDEF!!')
315   - expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL")
316   - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil))
317   - end
318   -
319   - should 'not draw sex icon for non-person profiles' do
320   - assert_equal '', profile_sex_icon(Community.new)
321   - end
322   -
323   - should 'not draw sex icon when disabled in the environment' do
324   - env = fast_create(Environment, :name => 'env test')
325   - env.expects(:enabled?).with('disable_gender_icon').returns(true)
326   - stubs(:environment).returns(env)
327   - assert_equal '', profile_sex_icon(build(Person, :sex => 'male'))
328   - end
329   -
330 269 should 'display field on person signup' do
331 270 env = create(Environment, :name => 'env test')
332 271 stubs(:environment).returns(env)
... ... @@ -524,19 +463,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
524 463 assert_equal Environment.default.name, page_title
525 464 end
526 465  
527   - should 'gravatar default parameter' do
528   - profile = mock
529   - profile.stubs(:theme).returns('some-theme')
530   - stubs(:profile).returns(profile)
531   -
532   - NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
533   - assert_equal gravatar_default, 'crazyvatar'
534   -
535   - stubs(:theme_option).returns('gravatar' => 'nicevatar')
536   - NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
537   - assert_equal gravatar_default, 'nicevatar'
538   - end
539   -
540 466 should 'use theme passed via param when in development mode' do
541 467 stubs(:environment).returns(build(Environment, :theme => 'environment-theme'))
542 468 Rails.env.stubs(:development?).returns(true)
... ... @@ -558,48 +484,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
558 484 assert_equal environment.theme, current_theme
559 485 end
560 486  
561   - should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do
562   - env = Environment.default
563   - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false)
564   - stubs(:environment).returns(env)
565   - profile = Profile.new
566   - assert_nil links_for_balloon(profile)
567   - end
568   -
569   - should 'return ordered list of links to balloon to Person' do
570   - env = Environment.default
571   - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
572   - stubs(:environment).returns(env)
573   - person = Person.new identifier: 'person'
574   - person.stubs(:url).returns('url for person')
575   - person.stubs(:public_profile_url).returns('url for person')
576   - links = links_for_balloon(person)
577   - assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first}
578   - end
579   -
580   - should 'return ordered list of links to balloon to Community' do
581   - env = Environment.default
582   - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
583   - stubs(:environment).returns(env)
584   - community = Community.new identifier: 'comm'
585   - community.stubs(:url).returns('url for community')
586   - community.stubs(:public_profile_url).returns('url for community')
587   - links = links_for_balloon(community)
588   - assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first}
589   - end
590   -
591   - should 'return ordered list of links to balloon to Enterprise' do
592   - env = Environment.default
593   - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
594   - stubs(:environment).returns(env)
595   - enterprise = Enterprise.new identifier: 'coop'
596   - enterprise.stubs(:url).returns('url for enterprise')
597   - enterprise.stubs(:public_profile_url).returns('url for enterprise')
598   - stubs(:catalog_path)
599   - links = links_for_balloon(enterprise)
600   - assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first}
601   - end
602   -
603 487 should 'use favicon from environment theme if does not have profile' do
604 488 stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme'))
605 489 stubs(:profile).returns(nil)
... ... @@ -651,24 +535,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
651 535 assert admin_link.present?
652 536 end
653 537  
654   - should 'not return mime type of profile icon if not requested' do
655   - stubs(:profile).returns(Person.new)
656   - stubs(:current_theme).returns('default')
657   -
658   - filename, mime = profile_icon(Person.new, :thumb)
659   - assert_not_nil filename
660   - assert_nil mime
661   - end
662   -
663   - should 'return mime type of profile icon' do
664   - stubs(:profile).returns(Person.new)
665   - stubs(:current_theme).returns('default')
666   -
667   - filename, mime = profile_icon(Person.new, :thumb, true)
668   - assert_not_nil filename
669   - assert_not_nil mime
670   - end
671   -
672 538 should 'pluralize without count' do
673 539 assert_equal "tests", pluralize_without_count(2, "test")
674 540 assert_equal "test", pluralize_without_count(1, "test")
... ... @@ -1037,31 +903,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
1037 903 assert_equal c.top_url, top_url
1038 904 end
1039 905  
1040   - should "Extra info with hash" do
1041   - @plugins = mock
1042   - @plugins.stubs(:dispatch_first).returns(false)
1043   - env = Environment.default
1044   - stubs(:environment).returns(env)
1045   - stubs(:profile).returns(profile)
1046   - profile = fast_create(Person, :environment_id => env.id)
1047   - info = {:value =>_('New'), :class => 'new-profile'}
1048   - html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
1049   - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' }
1050   - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New'
1051   - end
1052   -
1053   - should "Extra info without hash" do
1054   - @plugins = mock
1055   - @plugins.stubs(:dispatch_first).returns(false)
1056   - env = Environment.default
1057   - stubs(:environment).returns(env)
1058   - stubs(:profile).returns(profile)
1059   - profile = fast_create(Person, :environment_id => env.id)
1060   - info = 'new'
1061   - html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
1062   - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new'
1063   - end
1064   -
1065 906 protected
1066 907 include NoosferoTestHelper
1067 908  
... ...
test/unit/profile_image_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,138 @@
  1 +# encoding: UTF-8
  2 +require_relative "../test_helper"
  3 +
  4 +class ProfileImageHelperTest < ActionView::TestCase
  5 + include Noosfero::Gravatar
  6 + include ThemeLoaderHelper
  7 + include ProfileImageHelper
  8 +
  9 + should "Extra info with hash" do
  10 + @plugins = mock
  11 + @plugins.stubs(:dispatch_first).returns(false)
  12 + env = Environment.default
  13 + stubs(:environment).returns(env)
  14 + stubs(:profile).returns(profile)
  15 + profile = fast_create(Person, :environment_id => env.id)
  16 + info = {:value =>_('New'), :class => 'new-profile'}
  17 + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
  18 + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' }
  19 + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New'
  20 + end
  21 +
  22 + should "Extra info without hash" do
  23 + @plugins = mock
  24 + @plugins.stubs(:dispatch_first).returns(false)
  25 + env = Environment.default
  26 + stubs(:environment).returns(env)
  27 + stubs(:profile).returns(profile)
  28 + profile = fast_create(Person, :environment_id => env.id)
  29 + info = 'new'
  30 + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info)
  31 + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new'
  32 + end
  33 +
  34 + should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do
  35 + env = Environment.default
  36 + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false)
  37 + stubs(:environment).returns(env)
  38 + profile = Profile.new
  39 + assert_nil links_for_balloon(profile)
  40 + end
  41 +
  42 + should 'return ordered list of links to balloon to Person' do
  43 + env = Environment.default
  44 + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
  45 + stubs(:environment).returns(env)
  46 + person = Person.new identifier: 'person'
  47 + person.stubs(:url).returns('url for person')
  48 + person.stubs(:public_profile_url).returns('url for person')
  49 + links = links_for_balloon(person)
  50 + assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first}
  51 + end
  52 +
  53 + should 'return ordered list of links to balloon to Community' do
  54 + env = Environment.default
  55 + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
  56 + stubs(:environment).returns(env)
  57 + community = Community.new identifier: 'comm'
  58 + community.stubs(:url).returns('url for community')
  59 + community.stubs(:public_profile_url).returns('url for community')
  60 + links = links_for_balloon(community)
  61 + assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first}
  62 + end
  63 +
  64 + should 'return ordered list of links to balloon to Enterprise' do
  65 + env = Environment.default
  66 + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true)
  67 + stubs(:environment).returns(env)
  68 + enterprise = Enterprise.new identifier: 'coop'
  69 + enterprise.stubs(:url).returns('url for enterprise')
  70 + enterprise.stubs(:public_profile_url).returns('url for enterprise')
  71 + stubs(:catalog_path)
  72 + links = links_for_balloon(enterprise)
  73 + assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first}
  74 + end
  75 +
  76 + should 'not return mime type of profile icon if not requested' do
  77 + stubs(:profile).returns(Person.new)
  78 + stubs(:current_theme).returns('default')
  79 +
  80 + filename, mime = profile_icon(Person.new, :thumb)
  81 + assert_not_nil filename
  82 + assert_nil mime
  83 + end
  84 +
  85 + should 'return mime type of profile icon' do
  86 + stubs(:profile).returns(Person.new)
  87 + stubs(:current_theme).returns('default')
  88 +
  89 + filename, mime = profile_icon(Person.new, :thumb, true)
  90 + assert_not_nil filename
  91 + assert_not_nil mime
  92 + end
  93 +
  94 + should 'provide sex icon for males' do
  95 + stubs(:environment).returns(Environment.default)
  96 + expects(:content_tag).with(anything, 'male').returns('MALE!!')
  97 + expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL")
  98 + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male'))
  99 + end
  100 +
  101 + should 'provide sex icon for females' do
  102 + stubs(:environment).returns(Environment.default)
  103 + expects(:content_tag).with(anything, 'female').returns('FEMALE!!')
  104 + expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL")
  105 + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female'))
  106 + end
  107 +
  108 + should 'provide undef sex icon' do
  109 + stubs(:environment).returns(Environment.default)
  110 + expects(:content_tag).with(anything, 'undef').returns('UNDEF!!')
  111 + expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL")
  112 + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil))
  113 + end
  114 +
  115 + should 'not draw sex icon for non-person profiles' do
  116 + assert_equal '', profile_sex_icon(Community.new)
  117 + end
  118 +
  119 + should 'not draw sex icon when disabled in the environment' do
  120 + env = fast_create(Environment, :name => 'env test')
  121 + env.expects(:enabled?).with('disable_gender_icon').returns(true)
  122 + stubs(:environment).returns(env)
  123 + assert_equal '', profile_sex_icon(build(Person, :sex => 'male'))
  124 + end
  125 +
  126 + should 'gravatar default parameter' do
  127 + profile = mock
  128 + profile.stubs(:theme).returns('some-theme')
  129 + stubs(:profile).returns(profile)
  130 +
  131 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
  132 + assert_equal gravatar_default, 'crazyvatar'
  133 +
  134 + stubs(:theme_option).returns('gravatar' => 'nicevatar')
  135 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
  136 + assert_equal gravatar_default, 'nicevatar'
  137 + end
  138 +end
0 139 \ No newline at end of file
... ...
test/unit/theme_loader_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +# encoding: UTF-8
  2 +require_relative "../test_helper"
  3 +
  4 +class ThemeLoaderHelperTest < ActionView::TestCase
  5 + include ThemeLoaderHelper
  6 +
  7 + should 'get theme from environment by default' do
  8 + @environment = mock
  9 + @environment.stubs(:theme).returns('my-environment-theme')
  10 + stubs(:profile).returns(nil)
  11 + stubs(:environment).returns(@environment)
  12 + assert_equal 'my-environment-theme', current_theme
  13 + end
  14 +
  15 + should 'get theme from profile when profile is present' do
  16 + profile = mock
  17 + profile.stubs(:theme).returns('my-profile-theme')
  18 + stubs(:profile).returns(profile)
  19 + assert_equal 'my-profile-theme', current_theme
  20 + end
  21 +
  22 + should 'override theme with testing theme from session' do
  23 + stubs(:session).returns(:theme => 'theme-under-test')
  24 + assert_equal 'theme-under-test', current_theme
  25 + end
  26 +
  27 + should 'point to system theme path by default' do
  28 + expects(:current_theme).returns('my-system-theme')
  29 + assert_equal '/designs/themes/my-system-theme', theme_path
  30 + end
  31 +
  32 + should 'point to user theme path when testing theme' do
  33 + stubs(:session).returns({:theme => 'theme-under-test'})
  34 + assert_equal '/user_themes/theme-under-test', theme_path
  35 + end
  36 +end
0 37 \ No newline at end of file
... ...