Commit 9a16d8cacf991dc954c94ee8e209d06c3c9dba79
Exists in
master
and in
29 other branches
Merge branch 'merge-requests/60'
Showing
6 changed files
with
67 additions
and
10 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -588,7 +588,7 @@ module ApplicationHelper |
588 | 588 | def gravatar_url_for(email, options = {}) |
589 | 589 | # Ta dando erro de roteamento |
590 | 590 | default = theme_option['gravatar'] || NOOSFERO_CONF['gravatar'] || nil |
591 | - url_for( { :gravatar_id => Digest::MD5.hexdigest(email), | |
591 | + url_for( { :gravatar_id => Digest::MD5.hexdigest(email.to_s), | |
592 | 592 | :host => 'www.gravatar.com', |
593 | 593 | :protocol => 'http://', |
594 | 594 | :only_path => false, |
... | ... | @@ -600,7 +600,7 @@ module ApplicationHelper |
600 | 600 | def str_gravatar_url_for(email, options = {}) |
601 | 601 | default = theme_option['gravatar'] || NOOSFERO_CONF['gravatar'] || nil |
602 | 602 | url = 'http://www.gravatar.com/avatar.php?gravatar_id=' + |
603 | - Digest::MD5.hexdigest(email) | |
603 | + Digest::MD5.hexdigest(email.to_s) | |
604 | 604 | { |
605 | 605 | :only_path => false, |
606 | 606 | :d => default |
... | ... | @@ -610,6 +610,10 @@ module ApplicationHelper |
610 | 610 | url |
611 | 611 | end |
612 | 612 | |
613 | + def gravatar_profile_url(email) | |
614 | + 'http://www.gravatar.com/'+ Digest::MD5.hexdigest(email.to_s) | |
615 | + end | |
616 | + | |
613 | 617 | attr_reader :environment |
614 | 618 | def select_categories(object_name, title=nil, title_size=4) |
615 | 619 | return nil if environment.enabled?(:disable_categories) | ... | ... |
app/views/content_viewer/_comment.rhtml
... | ... | @@ -11,14 +11,21 @@ |
11 | 11 | :title => comment.author_name |
12 | 12 | %> |
13 | 13 | <% else %> |
14 | - <%# unauthenticated user: display gravatar icon %> | |
15 | - <% url_image, status_class = comment.author_id ? [comment.removed_user_image, 'icon-user-removed'] : [str_gravatar_url_for( comment.email, :size => 50 ), 'icon-user-unknown'] %> | |
16 | - <%= content_tag 'span', image_tag(url_image) + | |
17 | - content_tag('span', comment.author_name, :class => 'comment-info') + | |
18 | - content_tag('span', comment.message, :class => 'comment-user-status ' + status_class), | |
14 | + <% url_image, status_class = comment.author_id ? | |
15 | + [comment.removed_user_image, 'icon-user-removed'] : | |
16 | + [str_gravatar_url_for( comment.email, :size => 50, :d=>404 ), 'icon-user-unknown'] %> | |
17 | + | |
18 | + <%= link_to( | |
19 | + image_tag(url_image, :onerror=>'gravatarCommentFailback(this)', | |
20 | + 'data-gravatar'=>str_gravatar_url_for(comment.email, :size=>50)) + | |
21 | + content_tag('span', comment.author_name, :class => 'comment-info') + | |
22 | + content_tag('span', comment.message, | |
23 | + :class => 'comment-user-status ' + status_class), | |
24 | + gravatar_profile_url(comment.email), | |
25 | + :target => '_blank', | |
19 | 26 | :class => 'comment-picture', |
20 | 27 | :title => '%s %s' % [comment.author_name, comment.message] |
21 | - %> | |
28 | + )%> | |
22 | 29 | <% end %> |
23 | 30 | |
24 | 31 | <% comment_balloon do %> | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +Feature: Gravatar Support | |
2 | + Unauthenticated users may comment content and are displayed with Gravatar | |
3 | + pictures. The commenter with registered Gravatar image will have a link to | |
4 | + his/her Gravatar profile, others will have a link to the Gravatar homepage. | |
5 | + | |
6 | + Background: | |
7 | + Given the following users | |
8 | + | login | name | | |
9 | + | manuel | Manuel Silva | | |
10 | + And the following articles | |
11 | + | owner | name | | |
12 | + | manuel | My Article | | |
13 | + And the following comments | |
14 | + | article | author | name | email | title | body | | |
15 | + | My Article | manuel | | | 1 | Hi! | | |
16 | + | My Article | | Aurium | aurium@gmail.com | 2 | Hello! | | |
17 | + | My Article | | NoOne | nobody@colivre.coop.br | 3 | Bye! | | |
18 | + | |
19 | + @selenium | |
20 | + Scenario: The Aurium's gravatar picture must link to his gravatar profile | |
21 | + # because Aurium has his picture registered at garvatar.com. | |
22 | + When I go to article "My Article" | |
23 | + Then I should see "Aurium" linking to "http://www.gravatar.com/24a625896a07aa37fdb2352e302e96de" | |
24 | + | |
25 | + @selenium | |
26 | + Scenario: The NoOne's gravatar picture must link to Gravatar homepage | |
27 | + # because NoOne <nobody@colivre.coop.br> has no picture registered. | |
28 | + When I go to article "My Article" | |
29 | + Then I should see "NoOne" linking to "http://www.gravatar.com" | |
30 | + | ... | ... |
features/support/paths.rb
... | ... | @@ -14,6 +14,9 @@ module NavigationHelpers |
14 | 14 | when /^\// |
15 | 15 | page_name |
16 | 16 | |
17 | + when /article "([^"]+)"\s*$/ | |
18 | + url_for( Article.find_by_name($1).url ) | |
19 | + | |
17 | 20 | when /edit "(.+)" by (.+)/ |
18 | 21 | article_id = Person[$2].articles.find_by_slug($1.to_slug).id |
19 | 22 | "/myprofile/#{$2}/cms/edit/#{article_id}" | ... | ... |
public/javascripts/application.js
... | ... | @@ -680,6 +680,12 @@ function original_image_dimensions(src) { |
680 | 680 | return { 'width' : img.width, 'height' : img.height }; |
681 | 681 | } |
682 | 682 | |
683 | +function gravatarCommentFailback(img) { | |
684 | + var link = img.parentNode; | |
685 | + link.href = "http://www.gravatar.com"; | |
686 | + img.src = img.getAttribute("data-gravatar"); | |
687 | +} | |
688 | + | |
683 | 689 | jQuery(function() { |
684 | 690 | jQuery("#ajax-form").before("<div id='ajax-form-loading-area' style='display:block;width:16px;height:16px;'></div>"); |
685 | 691 | jQuery("#ajax-form").before("<div id='ajax-form-message-area'></div>"); | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -467,8 +467,10 @@ class ApplicationHelperTest < Test::Unit::TestCase |
467 | 467 | assert_match(/Community nick/, page_title) |
468 | 468 | end |
469 | 469 | |
470 | - should 'generate a gravatar url' do | |
471 | - stubs(:theme_option).returns({}) | |
470 | + should 'generate a gravatar image url' do | |
471 | + stubs(:environment).returns(Environment.default) | |
472 | + @controller = ApplicationController.new | |
473 | + | |
472 | 474 | with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do |
473 | 475 | url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 ) |
474 | 476 | assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url) |
... | ... | @@ -486,6 +488,11 @@ class ApplicationHelperTest < Test::Unit::TestCase |
486 | 488 | end |
487 | 489 | end |
488 | 490 | |
491 | + should 'generate a gravatar profile url' do | |
492 | + url = gravatar_profile_url( 'rms@gnu.org' ) | |
493 | + assert_equal('http://www.gravatar.com/ed5214d4b49154ba0dc397a28ee90eb7', url) | |
494 | + end | |
495 | + | |
489 | 496 | should 'use theme passed via param when in development mode' do |
490 | 497 | stubs(:environment).returns(Environment.new(:theme => 'environment-theme')) |
491 | 498 | ENV.stubs(:[]).with('RAILS_ENV').returns('development') | ... | ... |