Commit 2942e278d2df7bd14a2bb165fd9c4f63cf618ab8

Authored by Rafael Reggiani Manzo
1 parent 73d01160

Extract methods from ApplicationHelper

The method for build profile_image_link was part of ApplicationHelper
but will also be necessary for building proper tests on a upcoming
refactor for PeopleBlockPlugin.

As including ApplicationHelper on unit tests has already caused issues
with unwanted block behaviour regarding their visibility, this is a move
in the direction of avoiding such issues before they happen and allow
reliable future tests.
app/helpers/application_helper.rb
@@ -50,6 +50,10 @@ module ApplicationHelper @@ -50,6 +50,10 @@ module ApplicationHelper
50 50
51 include ButtonsHelper 51 include ButtonsHelper
52 52
  53 + include ProfileImageHelper
  54 +
  55 + include ThemeLoaderHelper
  56 +
53 def locale 57 def locale
54 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale 58 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
55 end 59 end
@@ -281,48 +285,6 @@ module ApplicationHelper @@ -281,48 +285,6 @@ module ApplicationHelper
281 end 285 end
282 end 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 def theme_view_file(template, theme=nil) 288 def theme_view_file(template, theme=nil)
327 # Since we cannot control what people are doing in external themes, we 289 # Since we cannot control what people are doing in external themes, we
328 # will keep looking for the deprecated .rhtml extension here. 290 # will keep looking for the deprecated .rhtml extension here.
@@ -395,141 +357,6 @@ module ApplicationHelper @@ -395,141 +357,6 @@ module ApplicationHelper
395 Theme.find(current_theme).owner.identifier 357 Theme.find(current_theme).owner.identifier
396 end 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 def popover_menu(title,menu_title,links,html_options={}) 360 def popover_menu(title,menu_title,links,html_options={})
534 html_options[:class] = "" unless html_options[:class] 361 html_options[:class] = "" unless html_options[:class]
535 html_options[:class] << " menu-submenu-trigger" 362 html_options[:class] << " menu-submenu-trigger"
@@ -538,10 +365,6 @@ module ApplicationHelper @@ -538,10 +365,6 @@ module ApplicationHelper
538 link_to(content_tag(:span, title), '#', html_options) 365 link_to(content_tag(:span, title), '#', html_options)
539 end 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 attr_reader :environment 368 attr_reader :environment
546 369
547 def select_categories(object_name, title=nil, title_size=4) 370 def select_categories(object_name, title=nil, title_size=4)
app/helpers/profile_image_helper.rb 0 → 100644
@@ -0,0 +1,140 @@ @@ -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 \ No newline at end of file 141 \ No newline at end of file
app/helpers/theme_loader_helper.rb 0 → 100644
@@ -0,0 +1,43 @@ @@ -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
test/unit/application_helper_test.rb
@@ -145,35 +145,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -145,35 +145,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
145 assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator' 145 assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator'
146 end 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 should 'render theme footer' do 148 should 'render theme footer' do
178 stubs(:theme_path).returns('/user_themes/mytheme') 149 stubs(:theme_path).returns('/user_themes/mytheme')
179 footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') 150 footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb')
@@ -295,38 +266,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -295,38 +266,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
295 assert_nil select_categories(mock) 266 assert_nil select_categories(mock)
296 end 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 should 'display field on person signup' do 269 should 'display field on person signup' do
331 env = create(Environment, :name => 'env test') 270 env = create(Environment, :name => 'env test')
332 stubs(:environment).returns(env) 271 stubs(:environment).returns(env)
@@ -524,19 +463,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -524,19 +463,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
524 assert_equal Environment.default.name, page_title 463 assert_equal Environment.default.name, page_title
525 end 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 should 'use theme passed via param when in development mode' do 466 should 'use theme passed via param when in development mode' do
541 stubs(:environment).returns(build(Environment, :theme => 'environment-theme')) 467 stubs(:environment).returns(build(Environment, :theme => 'environment-theme'))
542 Rails.env.stubs(:development?).returns(true) 468 Rails.env.stubs(:development?).returns(true)
@@ -558,48 +484,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -558,48 +484,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
558 assert_equal environment.theme, current_theme 484 assert_equal environment.theme, current_theme
559 end 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 should 'use favicon from environment theme if does not have profile' do 487 should 'use favicon from environment theme if does not have profile' do
604 stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme')) 488 stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme'))
605 stubs(:profile).returns(nil) 489 stubs(:profile).returns(nil)
@@ -651,24 +535,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -651,24 +535,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
651 assert admin_link.present? 535 assert admin_link.present?
652 end 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 should 'pluralize without count' do 538 should 'pluralize without count' do
673 assert_equal "tests", pluralize_without_count(2, "test") 539 assert_equal "tests", pluralize_without_count(2, "test")
674 assert_equal "test", pluralize_without_count(1, "test") 540 assert_equal "test", pluralize_without_count(1, "test")
@@ -1037,31 +903,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase @@ -1037,31 +903,6 @@ class ApplicationHelperTest &lt; ActionView::TestCase
1037 assert_equal c.top_url, top_url 903 assert_equal c.top_url, top_url
1038 end 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 protected 906 protected
1066 include NoosferoTestHelper 907 include NoosferoTestHelper
1067 908
test/unit/profile_image_helper_test.rb 0 → 100644
@@ -0,0 +1,138 @@ @@ -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 \ No newline at end of file 139 \ No newline at end of file
test/unit/theme_loader_helper_test.rb 0 → 100644
@@ -0,0 +1,36 @@ @@ -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 \ No newline at end of file 37 \ No newline at end of file