aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUģis Ozols <ugis.ozolss@gmail.com>2012-07-31 08:31:12 +0300
committerUģis Ozols <ugis.ozolss@gmail.com>2012-07-31 08:31:12 +0300
commit1f1b0f278be73091763b9133db6660b504f63fac (patch)
tree1c629095bbe75c0425f3b2226711a0c9dda53aee
parent46877fbc5335fc60b96b218cbfd787387bf7d94e (diff)
downloadrefinerycms-blog-1f1b0f278be73091763b9133db6660b504f63fac.tar.gz
refinerycms-blog-1f1b0f278be73091763b9133db6660b504f63fac.tar.bz2
refinerycms-blog-1f1b0f278be73091763b9133db6660b504f63fac.zip
Move avatar_url method to posts helper because view stuff shouldn't be in the model.
-rw-r--r--app/helpers/refinery/blog/posts_helper.rb5
-rw-r--r--app/models/refinery/blog/comment.rb7
-rw-r--r--app/views/refinery/blog/posts/_comment.html.erb2
-rw-r--r--spec/helpers/refinery/blog/posts_helper_spec.rb12
4 files changed, 18 insertions, 8 deletions
diff --git a/app/helpers/refinery/blog/posts_helper.rb b/app/helpers/refinery/blog/posts_helper.rb
index dfb742a..2daa5f6 100644
--- a/app/helpers/refinery/blog/posts_helper.rb
+++ b/app/helpers/refinery/blog/posts_helper.rb
@@ -28,6 +28,11 @@ module Refinery
Refinery::Blog::Post.published_dates_older_than(cutoff)
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
delegate :t, :link_to, :refinery, :render, :to => :view_context
attr_reader :view_context
diff --git a/app/models/refinery/blog/comment.rb b/app/models/refinery/blog/comment.rb
index b57e16f..afd806f 100644
--- a/app/models/refinery/blog/comment.rb
+++ b/app/models/refinery/blog/comment.rb
@@ -33,13 +33,6 @@ module Refinery
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!
self.update_column(:state, 'approved')
end
diff --git a/app/views/refinery/blog/posts/_comment.html.erb b/app/views/refinery/blog/posts/_comment.html.erb
index 659f433..2df0420 100644
--- a/app/views/refinery/blog/posts/_comment.html.erb
+++ b/app/views/refinery/blog/posts/_comment.html.erb
@@ -1,5 +1,5 @@
<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) %>
<footer class='blog_comment_author'>
<p>
diff --git a/spec/helpers/refinery/blog/posts_helper_spec.rb b/spec/helpers/refinery/blog/posts_helper_spec.rb
index b8c8911..7087bff 100644
--- a/spec/helpers/refinery/blog/posts_helper_spec.rb
+++ b/spec/helpers/refinery/blog/posts_helper_spec.rb
@@ -66,6 +66,18 @@ module Refinery
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