gravtastic 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -32,7 +32,7 @@ Now, you can access your object's gravatar with the @gravatar_url@ method:
32
32
  Note that it defaults to a PG rating. You can specify extra options with a hash:
33
33
 
34
34
  current_user.gravatar_url(:rating => 'R18', :size => 512)
35
- => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG&s=512"
35
+ => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512"
36
36
 
37
37
  current_user.gravatar_url(:secure => true)
38
38
  => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
@@ -64,7 +64,7 @@ If you submit a successful patch then you'll be given full commit rights to the
64
64
  h2. Thanks
65
65
 
66
66
  * "Xavier Shay":http://rhnh.net and others for "Enki":http://enkiblog.com (the reason this was written)
67
- * "Matthew Moore":http://www.matthewpaulmoore.com/ for helpful suggestions
67
+ * "Matthew Moore":http://www.matthewpaulmoore.com/ for helpful suggestions and for submitting it to the official list of Gravatar implementations.
68
68
 
69
69
 
70
70
  h2. License
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'spec/rake/spectask'
5
5
  require 'date'
6
6
 
7
7
  GEM = "gravtastic"
8
- GEM_VERSION = "1.6.0"
8
+ GEM_VERSION = "1.7.0"
9
9
  AUTHOR = "Chris Lloyd"
10
10
  EMAIL = "christopher.lloyd@gmail.com"
11
11
  HOMEPAGE = "http://github.com/chrislloyd/gravtastic"
data/lib/gravtastic.rb CHANGED
@@ -34,7 +34,7 @@ require 'cgi'
34
34
  # Note that it defaults to a PG rating. You can specify extra options with a hash:
35
35
  #
36
36
  # current_user.gravatar_url(:rating => 'R18', :size => 512)
37
- # => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG&s=512"
37
+ # => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512"
38
38
  #
39
39
  # current_user.gravatar_url(:secure => true)
40
40
  # => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
@@ -95,8 +95,8 @@ module Gravtastic
95
95
  # The raw MD5 hash used by Gravatar, generated from the ClassMethods#gravatar_source.
96
96
  #
97
97
  def gravatar_id
98
- if self.class.gravatar_source && value = send(self.class.gravatar_source).downcase
99
- @gravatar_id = Digest::MD5.hexdigest(value.to_s)
98
+ if self.class.gravatar_source && value = send(self.class.gravatar_source)
99
+ @gravatar_id = Digest::MD5.hexdigest(value.to_s.downcase)
100
100
  end
101
101
  end
102
102
 
@@ -117,12 +117,9 @@ module Gravtastic
117
117
  # => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
118
118
  #
119
119
  def gravatar_url(options={})
120
-
121
120
  options = self.class.gravatar_defaults.merge(options)
122
121
 
123
- if gravatar_id
124
- @gravatar_url = 'http' + (options[:secure] ? 's://secure.' : '://') + 'gravatar.com/avatar/' + gravatar_id + '.png' + parse_url_options_hash(options)
125
- end
122
+ @gravatar_url = gravatar_url_base(options[:secure]) + gravatar_filename + parse_url_options_hash(options)
126
123
  end
127
124
 
128
125
  private
@@ -142,7 +139,19 @@ module Gravtastic
142
139
  ''
143
140
  end
144
141
  end
145
-
142
+
143
+ def gravatar_url_base(secure)
144
+ 'http' + (secure ? 's://secure.' : '://') + 'gravatar.com/avatar/'
145
+ end
146
+
147
+ def gravatar_filename
148
+ if gravatar_id
149
+ gravatar_id + '.png'
150
+ else
151
+ ''
152
+ end
153
+ end
154
+
146
155
  end
147
156
  end
148
157
 
@@ -121,6 +121,11 @@ describe "Gravtastic::Model" do
121
121
  @user.gravatar_id.should == 'f5b8fb60c6116331da07c65b96a8a1d1'
122
122
  end
123
123
 
124
+ it "is nil when email is not a string" do
125
+ @user.stub!(:email).and_return(nil)
126
+ @user.gravatar_id.should == nil
127
+ end
128
+
124
129
  end
125
130
 
126
131
  describe "#gravatar_url" do
@@ -136,9 +141,9 @@ describe "Gravtastic::Model" do
136
141
  @user.gravatar_url.should_not be_nil
137
142
  end
138
143
 
139
- it "is nil when .gravatar_source is nil" do
144
+ it "returns a default Gravatar url when .gravatar_source is nil" do
140
145
  @user.class.stub!(:gravatar_source).and_return(nil)
141
- @user.gravatar_url.should be_nil
146
+ @user.gravatar_url.should =~ /http:\/\/gravatar.com\/avatar/
142
147
  end
143
148
 
144
149
  it "always specifies a png resource type" do
@@ -194,6 +199,11 @@ describe "Gravtastic::Model" do
194
199
  @user.gravatar_url.should == valid_gravatar_url + '?r=R18&s=20'
195
200
  end
196
201
 
202
+ it "returns a default Gravatar url when #gravatar_id is nil" do
203
+ @user.stub!(:email).and_return(nil)
204
+ @user.gravatar_url.should =~ /http:\/\/gravatar.com\/avatar/
205
+ end
206
+
197
207
  def valid_gravatar_url # :nodoc:
198
208
  'http://gravatar.com/avatar/f5b8fb60c6116331da07c65b96a8a1d1.png'
199
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lloyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-28 00:00:00 +10:00
12
+ date: 2008-08-30 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15