On Tue, Apr 7, 2009 at 6:43 AM, LAN-SUN-LUK Benjamin
<Benjamin.LAN-SUN-LUK(a)supinfo.com> wrote:
---
app/models/user.rb | 18 ++++++------------
app/views/users/_edit.html.erb | 2 --
app/views/users/show.html.erb | 2 --
public/images/icons/default_avatar.gif | Bin 0 -> 10150 bytes
test/unit/user_test.rb | 2 +-
5 files changed, 7 insertions(+), 17 deletions(-)
create mode 100644 public/images/icons/default_avatar.gif
diff --git a/app/models/user.rb b/app/models/user.rb
index 862cbbf..8532072 100644
NAK. I can't get this patch to apply. I think your repo might be out
of synch. Can you try doing a fresh clone of the git repo and then
apply the patch to see if it works? Also there are a few comments
below.
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -116,20 +116,14 @@ class User < ActiveRecord::Base
(id == project.owner.id) || privileges.admin_projects
end
- # Returns whether the user has an avatar or not.
- def avatar?
- use_gravatar || (!url_for_avatar.nil? && !url_for_avatar.empty?)
- end
-
- # Returns the user's avatar url, or +nil+ if none was defined.
+ # Returns the user's avatar url, or the default avatar url if none was
defined.
def avatar_url
- result = nil
-
- if !use_gravatar && !url_for_avatar.nil? && !url_for_avatar.empty?
+ if use_gravatar
+ result = gravatar_url(!url_for_avatar.blank? ? url_for_avatar :
email)
+ elsif !use_gravatar && !url_for_avatar.blank?
result = url_for_avatar
- elsif use_gravatar
- result = (!url_for_avatar.nil? && !url_for_avatar.empty?) ?
url_for_avatar : email
- result = gravatar_url(result)
+ else
+ result = ConfigProperty.fetch('users.default_avatar_url',
'/images/icons/default_avatar.gif')
I like the idea of making the default avatar configurable. However, if
we do this, there should be a migration added as well to inject the
default value. That way an admin can use the system out of the box
without having to manually inject a record.
<snip>
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 063517c..63dc478 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -63,7 +63,7 @@ class UserTest < ActiveSupport::TestCase
# Ensures that a user with no avatar returns the right value when
queries.
def test_avatar_reports_no
- flunk "User should not say he has an avatar." if
@user_with_no_avatar.avatar?
+ flunk "User should not say he has an avatar." unless
@user_with_no_avatar.avatar_url ==
ConfigProperty.fetch('users.default_avatar_url')
end
# Ensures that a user with an avatar URL returns the right URL.
--
1.6.1
For this one you should rename the unit test to
"test_avatar_default_url" and then verify that it's returning the
default URL rather than nil. Add a fixture to config_properties. yml
for the default avatar and then verify that this method's returning
that URL.
--
Darryl L. Pierce <mcpierce(a)gmail.com>
Visit the Infobahn Offramp: <
http://mcpierce.multiply.com>
"Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant