Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Move avatar_url method to posts helper because view stuff shouldn't b…

…e in the model.
  • Loading branch information...
commit 1f1b0f278be73091763b9133db6660b504f63fac 1 parent 46877fb
Uģis Ozols ugisozols authored
5 app/helpers/refinery/blog/posts_helper.rb
@@ -28,6 +28,11 @@ def blog_archive_dates(cutoff=Time.now.beginning_of_month)
28 28 Refinery::Blog::Post.published_dates_older_than(cutoff)
29 29 end
30 30
  31 + def avatar_url(email, options = {:size => 60})
  32 + require 'digest/md5'
  33 + "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s.strip.downcase)}?s=#{options[:size]}.jpg"
  34 + end
  35 +
31 36 class ArchiveWidget
32 37 delegate :t, :link_to, :refinery, :render, :to => :view_context
33 38 attr_reader :view_context
7 app/models/refinery/blog/comment.rb
@@ -33,13 +33,6 @@ def rejected
33 33
34 34 self.per_page = Refinery::Blog.comments_per_page
35 35
36   - def avatar_url(options = {})
37   - options = {:size => 60}
38   - require 'digest/md5'
39   - size = ("?s=#{options[:size]}" if options[:size])
40   - "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
41   - end
42   -
43 36 def approve!
44 37 self.update_column(:state, 'approved')
45 38 end
2  app/views/refinery/blog/posts/_comment.html.erb
... ... @@ -1,5 +1,5 @@
1 1 <article class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'>
2   - <%= image_tag comment.avatar_url, :alt => comment.name, :class => 'avatar' %>
  2 + <%= image_tag avatar_url(comment.email), :alt => comment.name, :class => 'avatar' %>
3 3 <%= simple_format auto_link(comment.message.to_s) %>
4 4 <footer class='blog_comment_author'>
5 5 <p>
12 spec/helpers/refinery/blog/posts_helper_spec.rb
@@ -66,6 +66,18 @@ module Blog
66 66 end
67 67 end
68 68 end
  69 +
  70 + describe "#avatar_url" do
  71 + let(:email) { "test@test.com" }
  72 +
  73 + it "returns gravatar url" do
  74 + helper.avatar_url(email).should eq("http://gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=60.jpg")
  75 + end
  76 +
  77 + it "accepts options hash to change default size" do
  78 + helper.avatar_url(email, :size => 55).should eq("http://gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=55.jpg")
  79 + end
  80 + end
69 81 end
70 82 end
71 83 end

0 comments on commit 1f1b0f2

Please sign in to comment.
Something went wrong with that request. Please try again.