Commit 04dad198bde9105155fb138052f19454029fc1c4

Authored by ivanvr
1 parent 3fe826df
Exists in master and in 1 other branch production

Fix Gravatar errors when no e-mail is provided

app/helpers/problems_helper.rb
... ... @@ -11,10 +11,14 @@ module ProblemsHelper
11 11 end
12 12  
13 13 def gravatar_tag(email, options = {})
  14 + return nil unless email.present?
  15 +
14 16 image_tag gravatar_url(email, options), :alt => email, :class => 'gravatar'
15 17 end
16 18  
17 19 def gravatar_url(email, options = {})
  20 + return nil unless email.present?
  21 +
18 22 default_options = {
19 23 :d => Errbit::Config.gravatar_default,
20 24 }
... ...
app/views/users/show.html.haml
1 1 - content_for :title, @user.name
2   -- if Errbit::Config.use_gravatar
  2 +- if Errbit::Config.use_gravatar && gravatar = gravatar_url(@user.email, :s => 86)
3 3 - content_for :title_style do
4   - background: url('#{gravatar_url @user.email, :s => 86}') no-repeat;
  4 + background: url('#{gravatar}') no-repeat;
5 5 padding-left: 106px;
6 6  
7 7 - content_for :action_bar do
... ...
spec/helpers/problems_helper_spec.rb
... ... @@ -31,5 +31,21 @@ describe ProblemsHelper do
31 31 helper.gravatar_tag(email, :d => 'retro', :s => 48).should eq(expected)
32 32 end
33 33 end
  34 +
  35 + context "no email" do
  36 + it "should not render the tag" do
  37 + helper.gravatar_tag(nil).should be_nil
  38 + end
  39 + end
  40 + end
  41 +
  42 + describe "#gravatar_url" do
  43 + context "no email" do
  44 + let(:email) { nil }
  45 +
  46 + it "should return nil" do
  47 + helper.gravatar_url(email).should be_nil
  48 + end
  49 + end
34 50 end
35 51 end
... ...