Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move avatar_url method to posts helper because view stuff shouldn't b…
…e in the model.
  • Loading branch information
ugisozols committed Jul 31, 2012
1 parent 46877fb commit 1f1b0f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/helpers/refinery/blog/posts_helper.rb
Expand Up @@ -28,6 +28,11 @@ def blog_archive_dates(cutoff=Time.now.beginning_of_month)
Refinery::Blog::Post.published_dates_older_than(cutoff) Refinery::Blog::Post.published_dates_older_than(cutoff)
end end


def avatar_url(email, options = {:size => 60})
require 'digest/md5'
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s.strip.downcase)}?s=#{options[:size]}.jpg"
end

class ArchiveWidget class ArchiveWidget
delegate :t, :link_to, :refinery, :render, :to => :view_context delegate :t, :link_to, :refinery, :render, :to => :view_context
attr_reader :view_context attr_reader :view_context
Expand Down
7 changes: 0 additions & 7 deletions app/models/refinery/blog/comment.rb
Expand Up @@ -33,13 +33,6 @@ def rejected


self.per_page = Refinery::Blog.comments_per_page self.per_page = Refinery::Blog.comments_per_page


def avatar_url(options = {})
options = {:size => 60}
require 'digest/md5'
size = ("?s=#{options[:size]}" if options[:size])
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
end

def approve! def approve!
self.update_column(:state, 'approved') self.update_column(:state, 'approved')
end end
Expand Down
2 changes: 1 addition & 1 deletion app/views/refinery/blog/posts/_comment.html.erb
@@ -1,5 +1,5 @@
<article class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'> <article class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'>
<%= image_tag comment.avatar_url, :alt => comment.name, :class => 'avatar' %> <%= image_tag avatar_url(comment.email), :alt => comment.name, :class => 'avatar' %>
<%= simple_format auto_link(comment.message.to_s) %> <%= simple_format auto_link(comment.message.to_s) %>
<footer class='blog_comment_author'> <footer class='blog_comment_author'>
<p> <p>
Expand Down
12 changes: 12 additions & 0 deletions spec/helpers/refinery/blog/posts_helper_spec.rb
Expand Up @@ -66,6 +66,18 @@ module Blog
end end
end end
end end

describe "#avatar_url" do
let(:email) { "test@test.com" }

it "returns gravatar url" do
helper.avatar_url(email).should eq("http://gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=60.jpg")
end

it "accepts options hash to change default size" do
helper.avatar_url(email, :size => 55).should eq("http://gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=55.jpg")
end
end
end end
end end
end end

0 comments on commit 1f1b0f2

Please sign in to comment.