Commit c76b4bb662ff0ca619d1fdf1576cf9aedaddd5d3
Exists in
master
and in
22 other branches
Merge commit 'refs/merge-requests/60' of git://gitorious.org/noosfero/noosfero i…
…nto merge-requests/60 Conflicts: test/unit/application_helper_test.rb (ActionItem2125)
Showing
6 changed files
with
62 additions
and
8 deletions
Show diff stats
app/helpers/application_helper.rb
| ... | ... | @@ -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) | |
| 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,7 @@ 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 | |
| 472 | 471 | with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do |
| 473 | 472 | url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 ) |
| 474 | 473 | assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url) |
| ... | ... | @@ -486,6 +485,11 @@ class ApplicationHelperTest < Test::Unit::TestCase |
| 486 | 485 | end |
| 487 | 486 | end |
| 488 | 487 | |
| 488 | + should 'generate a gravatar profile url' do | |
| 489 | + url = gravatar_profile_url( 'rms@gnu.org' ) | |
| 490 | + assert_equal('http://www.gravatar.com/ed5214d4b49154ba0dc397a28ee90eb7', url) | |
| 491 | + end | |
| 492 | + | |
| 489 | 493 | should 'use theme passed via param when in development mode' do |
| 490 | 494 | stubs(:environment).returns(Environment.new(:theme => 'environment-theme')) |
| 491 | 495 | ENV.stubs(:[]).with('RAILS_ENV').returns('development') | ... | ... |