gravatarify 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da6497d2bbb29f19c0754cd5d1e0d86b5595608f
4
+ data.tar.gz: 9738f5fca4d8df44288035b9cf010404999eb9d8
5
+ SHA512:
6
+ metadata.gz: 90a79743136c3cec9eea5ee408ba7b2a3fcf00eec2c25bea8920b1359a67b9bfd938201e407966466701abe616c634180f4a485561121aad943aff9797d3b2ab
7
+ data.tar.gz: f1d88652037de585855d7f968ebc8bd34e95a593f23d6c1cf2a2c5076a7f3044425f823301d842543f3b7cd857792117cf0214261a76ab5e8aabbcf67c7515a1
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.3
5
- - jruby-18mode
3
+ - 2.0.0
4
+ - 2.1.0
6
5
  - jruby-19mode
data/README.md CHANGED
@@ -21,7 +21,7 @@ Ready, Set, Go!
21
21
  **READY** Add gravatarify to your `Gemfile`
22
22
 
23
23
  gem 'gravatarify', '~> 3.0.0'
24
-
24
+
25
25
  **SET** Guess, you are all set :) when using HAML or Sinatra you might to add:
26
26
 
27
27
  # e.g. for Sinatra
@@ -37,11 +37,11 @@ Ready, Set, Go!
37
37
 
38
38
  # creates an 20x20 pixel <img/> tag in your Rails ERB views:
39
39
  <%= gravatar_tag @user.email, :size => 20 %>
40
-
40
+
41
41
  # or in HAML views
42
42
  # (Note: how it's possible to skip the email attribute, btw - that's a feature)
43
43
  %img{ gravatar_attrs(@user, :size => 20) }/
44
-
44
+
45
45
  **More!?** Allright, that was just the quickstart, to get up and running with ease. However, this library provides
46
46
  quite a bit more, like:
47
47
 
@@ -78,31 +78,31 @@ and the `<img/>` tag should have a class attribute, do:
78
78
  If any additional HTML attributes are needed on the tag, or in the `gravatar_attrs`, just
79
79
  pass them in the `:html` option as hash. If more control is needed, or just the plain URL is
80
80
  required, resort to `gravatar_url`, which returns a string with the (unescaped) url:
81
-
81
+
82
82
  <img src="<%= h(gravatar_url(@user.author_email, :size => 16)) %>" alt="Gravatar"/>
83
-
83
+
84
84
  Using styles
85
85
  ------------
86
86
 
87
87
  With styles it's possible to easily change e.g. the size of all gravatars based on a name,
88
88
  these are reusable presets of options:
89
-
89
+
90
90
  # in config/initializers/gravatarify.rb or similar:
91
91
  Gravatarify.styles[:mini] = { :size => 16, :html => { :class => 'gravatar gravatar-mini' } }
92
92
  Gravatarify.styles[:default] = { :size => 45, :html => { :class => 'gravatar' } }
93
-
93
+
94
94
  # then in/some/view.html.erb:
95
95
  <%= gravatar_tag @user, :mini %> # => <img alt="" class="gravatar gravatar-mini" height="16" src.... />
96
-
97
- # or in/another/view.html.haml:
96
+
97
+ # or in/another/view.html.haml:
98
98
  %img{ gravatar_attrs(@user, :default) }/ # => <img alt="" class="gravatar" height="45" ... />
99
-
99
+
100
100
  Need to change to size of all `:mini` gravatars? Easy, just change the definition in `Gravatarify.styles`.
101
101
  Of course settings via `Gravatarify.options` are "mixed-in" as well, so:
102
102
 
103
103
  Gravatarify.options[:default] = Proc.new { |*params| "http://example.com/avatar-#{params.first[:size] || 80}.jpg" }
104
104
  Gravatarify.styles[:mini] => { :size => 16 }
105
-
105
+
106
106
  <%= gravatar_tag @user, :mini %> # => <img alt="" height="16" src=".....?d=http://example.com/avatar-16.jpg" width="16" />
107
107
 
108
108
  All methods accept a style, i.e. a style parameter can be passed in to `gravatar_attrs`, `gravatar_tag` and
@@ -117,7 +117,7 @@ Back to the roots?
117
117
 
118
118
  No need for sophisticated stuff like view helpers, want to go back to the roots?
119
119
  Then feel free to use `Gravatarify::Base#gravatar_url` directly.
120
-
120
+
121
121
  When the ability to display image tags is required in different view frameworks (like liquid!?),
122
122
  then just ensure that `Gravatarify::Helper` is included in the framework in question.
123
123
  See {Gravatarify::Base#gravatar_url} and of course {Gravatarify::Helper} for more informations
@@ -170,7 +170,7 @@ Need more control?
170
170
  <tr>
171
171
  <td><tt>:filetype</tt></td>
172
172
  <td>String, Symbol</td>
173
- <td>Change image type, gravatar.com supports <tt>:gif</tt>, <tt>:png</tt> and <tt>:jpg</tt>. If set to <tt>false</tt>
173
+ <td>Change image type, gravatar.com supports <tt>:gif</tt>, <tt>:png</tt> and <tt>:jpg</tt>. If set to <tt>false</tt>
174
174
  then a URL without an extension will be built (and gravatar.com then returns a JPG image).</td>
175
175
  <td><tt>:jpg</tt></td>
176
176
  </tr>
@@ -189,15 +189,15 @@ gravatar urls there. Of course all settings can be overridden locally:
189
189
  # disable suffix and set default size to 16x16px
190
190
  Gravatarify.options[:filetype] = false
191
191
  Gravatarify.options[:size] = 16
192
-
192
+
193
193
  gravatar_url(@user.email) # => http://0.gravatar.com/avatar/..f93ff1e?s=16
194
194
  gravatar_url(@user.email, :filetype => :png) # => http://0.gravatar.com/avatar/..f93ff1e.png?s=16
195
-
195
+
196
196
  To define global HTML attributes go ahead and do something like:
197
197
 
198
198
  # add title attribute
199
199
  Gravatarify.options[:html] = { :title => "Gravatar" }
200
-
200
+
201
201
  ## Not yet enough?
202
202
 
203
203
  The `:default` option can be passed in a `Proc`, so this is certainly useful to for example
@@ -207,18 +207,18 @@ to generate an image url, based on the request size:
207
207
  Gravatarify.options[:default] = Proc.new do |options, object|
208
208
  "http://example.com/avatar-#{options[:size] || 80}.jpg"
209
209
  end
210
-
210
+
211
211
  # now each time a gravatar url is generated, the Proc is evaluated:
212
212
  gravatar_url(@user)
213
213
  # => "http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar-80.jpg"
214
214
  gravatar_url(@user, :size => 16)
215
215
  # => "http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar-16.jpg&s=16"
216
-
216
+
217
217
  Into the block is passed the options hash and as second parameter the object itself, so it's possible to do stuff like
218
218
 
219
219
  # doing stuff like showing default avatar based on gender...
220
220
  @user = User.new(:gender => :female, :email => 'bella@gmail.com') # => @user.female? = true
221
-
221
+
222
222
  gravatar_url @user, :default => Proc.new { |opts, obj| "http://example.com/avatar#{obj.respond_to?(:female) && obj.female? ? '_female' : ''}.jpg" }
223
223
  # => http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar_female.jpg
224
224
 
@@ -232,16 +232,16 @@ all methods and no magic involved! So instead of doing:
232
232
 
233
233
  gravatar_tag(@user, :size => 30, :class => "gravatar", :title => "Gravatar")
234
234
  # Note: in Version 2.0 this would build an image src like http://..gravatar.com/...../?class=gravatar&s=30&title=Gravatar
235
-
235
+
236
236
  do:
237
237
 
238
238
  gravatar_tag(@user, :size => 30, :html => { :class => "Gravatar", :title => "Gravatar" })
239
-
239
+
240
240
  An important thing to know is that the `:html` is deep merged, with defaults, so stuff like:
241
241
 
242
242
  Gravatarify.options[:html] = { :title => "Gravatar" }
243
243
  gravatar_tag(@user, :html => { :class => "gravatar" }) # => <img alt="" class="gravatar" ... title="Gravatar" .../>
244
-
244
+
245
245
  Furthermore the option `:html` is ignored when building the url parameters.
246
246
 
247
247
  If the `gravatarify` method was not used, there's no need to change anything at all :) Though if
@@ -260,7 +260,7 @@ directly: `<%= gravatar_tag @user.author_email %>`. If the model defines `author
260
260
  class Author < ActiveRecord::Base
261
261
  alias_attribute :email, :author_email
262
262
  end
263
-
263
+
264
264
  # and in the views:
265
265
  <%= gravatar_tag @author %>
266
266
 
@@ -270,7 +270,7 @@ methods! The `gravatarify` method was introduced to provide compatibility with
270
270
  then feel free to fallback and use an older version (i.e. 1.2.1):
271
271
 
272
272
  [sudo] gem install gravatarify -v 1.2.1
273
-
273
+
274
274
 
275
275
  About the code
276
276
  ==============
@@ -281,30 +281,31 @@ of an overkill, though I like neat and tidy classes :)
281
281
  lib/gravatarify.rb # loads the other files from lib/gravatarify
282
282
  # and hooks the necessary modules into
283
283
  # HAML or ActionView.
284
-
284
+
285
285
  lib/gravatarify/base.rb # Provides all logic required to generate
286
286
  # gravatar.com urls from an email address.
287
287
  # Check out Gravatarify::Base.gravatar_url,
288
288
  # this is the absolute core method.
289
-
289
+
290
290
  lib/gravatarify/helper.rb # Defines the view helpers: gravatar_attrs
291
291
  # and gravatar_tag
292
-
292
+
293
293
  lib/gravatarify/utils.rb # Provides commonly used methods, like helpers to
294
294
  # uri and html escape strings or deep mergeing
295
295
  # hashes. Though these utils are only for internal
296
296
  # uses :)
297
-
297
+
298
298
  ### Contribute
299
299
 
300
300
  1. Fork the project and hack away
301
301
  2. Ensure that the changes are well tested
302
302
  3. Send me a pull request
303
-
303
+
304
304
  ### Thanks
305
305
 
306
306
  - [gudleik](https://github.com/gudleik) for his work on allowing an empty `:filetype`
307
307
  - [thegcat](https://github.com/thegcat) travis, jruby and ruby 1.9 support
308
+ - [technoweenie](https://github.com/technoweenie) fix to use consistent hashing: `Zlib.crc32`
308
309
 
309
310
  Licence
310
311
  =======
@@ -1,30 +1,27 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "gravatarify/version"
2
+ require File.expand_path('../lib/gravatarify/version', __FILE__)
4
3
 
5
- Gem::Specification.new do |s|
6
- s.name = "gravatarify"
7
- s.version = Gravatarify::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = "Awesome gravatar support for Ruby (and Rails)."
10
- s.description = "Ruby (and Rails) Gravatar helpers with unique options like Proc's for default images, support for gravatar.com's multiple host names, ability to define reusable styles and much more..."
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "gravatarify"
6
+ gem.version = Gravatarify::VERSION
7
+ gem.summary = "Awesome gravatar support for Ruby (and Rails)."
8
+ gem.description = "Ruby (and Rails) Gravatar helpers with unique options like Proc's for default images, support for gravatar.com's multiple host names, ability to define reusable styles and much more..."
11
9
 
12
- s.required_ruby_version = ">= 1.8.7"
13
- s.required_rubygems_version = ">= 1.3.6"
10
+ gem.required_ruby_version = ">= 1.8.7"
11
+ gem.required_rubygems_version = ">= 1.3.6"
14
12
 
15
- s.authors = ["Lukas Westermann"]
16
- s.email = ["lukas.westermann@gmail.com"]
17
- s.homepage = "http://github.com/lwe/gravatarify"
13
+ gem.authors = ["Lukas Westermann"]
14
+ gem.email = ["lukas.westermann@gmail.com"]
15
+ gem.homepage = "https://github.com/lwe/gravatarify"
18
16
 
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.require_path = 'lib'
22
-
23
- s.license = 'MIT'
24
-
25
- s.add_development_dependency 'shoulda', '>= 2.10.2'
26
- s.add_development_dependency 'rr', '>= 0.10.5'
27
- s.add_development_dependency 'activesupport', '>= 3.0.0'
28
- s.add_development_dependency 'rake'
29
- end
17
+ gem.files = %w{.travis.yml .gitignore Gemfile Rakefile LICENSE README.md gravatarify.gemspec} + Dir['{lib,test}/**/*.rb']
18
+ gem.test_files = gem.files.grep(%r{^test/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.license = 'MIT'
30
22
 
23
+ gem.add_development_dependency 'shoulda', '>= 2.10.2'
24
+ gem.add_development_dependency 'rr', '>= 0.10.5'
25
+ gem.add_development_dependency 'activesupport', '>= 3.0.0'
26
+ gem.add_development_dependency 'rake'
27
+ end
@@ -1,4 +1,5 @@
1
1
  require 'gravatarify/version'
2
+ require 'zlib'
2
3
 
3
4
  # Provides support for adding gravatar images in ruby (and rails)
4
5
  # applications.
@@ -6,9 +7,9 @@ module Gravatarify
6
7
  autoload :Base, 'gravatarify/base'
7
8
  autoload :Helper, 'gravatarify/helper'
8
9
  autoload :Utils, 'gravatarify/utils'
9
-
10
+
10
11
  class << self
11
-
12
+
12
13
  # Global options which are merged on every call to
13
14
  # +gravatar_url+, this is useful to e.g. define a default image.
14
15
  #
@@ -27,46 +28,46 @@ module Gravatarify
27
28
  # Gravatarify.options[:filetype] = false
28
29
  #
29
30
  def options; @options ||= { :filetype => :jpg } end
30
-
31
+
31
32
  # Allows to define some styles, makes it simpler to call by name, instead of always giving a size etc.
32
- #
33
+ #
33
34
  # Gravatarify.styles[:mini] => { :size => 30, :default => "http://example.com/gravatar-mini.jpg" }
34
- #
35
+ #
35
36
  # # in the views, it will then use the stuff defined by styles[:mini]:
36
37
  # <%= gravatar_tag @user, :mini %>
37
38
  #
38
39
  def styles; @styles ||= {} end
39
-
40
+
40
41
  # Globally overide subdomains used to build gravatar urls, normally
41
42
  # +gravatarify+ picks from either +0.gravatar.com+, +1.gravatar.com+,
42
- # +2.gravatar.com+ or +www.gravatar.com+ when building hosts, to use a custom
43
+ # +2.gravatar.com+, +3.gravater.com+ or +www.gravatar.com+ when building hosts, to use a custom
43
44
  # set of subdomains (or none!) do something like:
44
45
  #
45
46
  # Gravatarify.subdomains = %w{ 0 www } # only use 0.gravatar.com and www.gravatar.com
46
47
  #
47
48
  def subdomains=(subdomains) @subdomains = [*subdomains] end
48
-
49
+
49
50
  # Get subdomain for supplied string or returns +www+ if none is
50
51
  # defined.
51
52
  def subdomain(str) #:nodoc:
52
53
  @subdomains ||= []
53
54
  unless @subdomains.empty?
54
- subdomain = @subdomains[str.hash % @subdomains.size]
55
+ subdomain = @subdomains[Zlib.crc32(str) % @subdomains.size]
55
56
  subdomain + "." if subdomain
56
57
  end
57
58
  end
58
-
59
+
59
60
  # Is running rails and at least rails 3.x
60
61
  def rails?
61
62
  defined?(::Rails) && ::Rails.version.to_i >= 3
62
63
  end
63
-
64
+
64
65
  # Loads `Gravatarify::Helper` as view helper via `ActionController::Base.helper`
65
66
  def setup_rails!
66
67
  ActiveSupport.on_load(:action_controller) { ActionController::Base.helper(Gravatarify::Helper) }
67
68
  end
68
- end
69
+ end
69
70
  end
70
71
 
71
- # Try to init rails3
72
+ # Try to init rails
72
73
  Gravatarify.setup_rails! if Gravatarify.rails?
@@ -4,10 +4,10 @@ require 'cgi'
4
4
  module Gravatarify
5
5
  # Hash of :ultra_long_option_name => :abbr_opt
6
6
  GRAVATAR_ABBREV_OPTIONS = { 'default' => :d, :default => :d, 'rating' => :r, :rating => :r, 'size' => :s, :size => :s }
7
-
7
+
8
8
  # Provides core support to build gravatar urls based on supplied e-mail strings.
9
9
  module Base
10
-
10
+
11
11
  # Method which builds a gravatar url based on a supplied email and options as
12
12
  # defined by gravatar.com (http://en.gravatar.com/site/implement/url).
13
13
  #
@@ -19,11 +19,11 @@ module Gravatarify
19
19
  #
20
20
  # If supplied +email+ responds to either a method named +email+ or +mail+, the value of that method
21
21
  # is used instead to build the gravatar hash. Very useful to just pass in ActiveRecord object for instance:
22
- #
22
+ #
23
23
  # @user = User.find_by_email("samir@initech.com")
24
24
  # gravatar_url(@user) # => "http://2.gravatar.com/avatar/58cf31c817d76605d5180ce1a550d0d0.jpg"
25
25
  # gravatar_url(@user.email) # same as above!
26
- #
26
+ #
27
27
  # Among all options as defined by gravatar.com's specification, there also exist some special options:
28
28
  #
29
29
  # gravatar_url(@user, :secure => true) # => https://secure.gravatar.com/ava....
@@ -52,10 +52,10 @@ module Gravatarify
52
52
  host = Base.gravatar_host(self, email_hash, url_options.delete(:secure))
53
53
  "#{host}/avatar/#{email_hash}#{extension}#{Base.gravatar_params(email, url_options)}"
54
54
  end
55
-
55
+
56
56
  # For backwards compatibility.
57
57
  alias_method :build_gravatar_url, :gravatar_url
58
-
58
+
59
59
  protected
60
60
  # Builds gravatar host name from supplied e-mail hash.
61
61
  # Ensures that for the same +str_hash+ always the same subdomain is used.
@@ -65,22 +65,22 @@ module Gravatarify
65
65
  # else that subdomain magic. If it's passed in a +Proc+, it's evaluated and the result (+true+/+false+) is used
66
66
  # for the same decicion.
67
67
  # @return [String] Protocol and hostname (like <tt>http://www.gravatar.com</tt>), without trailing slash.
68
- def self.gravatar_host(context, str_hash, secure = false)
69
- use_ssl_host = secure.is_a?(Proc) ? secure.call(context) : secure
70
- use_ssl_host ? "https://secure.gravatar.com" : "http://#{Gravatarify.subdomain(str_hash)}gravatar.com"
68
+ def self.gravatar_host(context, str_hash, secure = false)
69
+ use_https = secure.respond_to?(:call) ? secure.call(context) : secure
70
+ "#{use_https ? 'https' : 'http'}://#{Gravatarify.subdomain(str_hash)}gravatar.com"
71
71
  end
72
-
72
+
73
73
  # Builds a query string from all passed in options.
74
74
  def self.gravatar_params(source, url_options = {})
75
75
  params = url_options.inject([]) do |params, (key, value)|
76
76
  key = (GRAVATAR_ABBREV_OPTIONS[key] || key).to_sym # shorten & symbolize key
77
77
  unless key == :html
78
- value = value.call(url_options, source) if key == :d and value.is_a?(Proc)
78
+ value = value.call(url_options, source) if key == :d && value.respond_to?(:call)
79
79
  params << "#{key}=#{CGI.escape(value.to_s)}" if value
80
80
  end
81
81
  params
82
82
  end
83
83
  "?#{params.sort * '&'}" unless params.empty?
84
- end
84
+ end
85
85
  end
86
- end
86
+ end
@@ -1,4 +1,4 @@
1
1
  module Gravatarify
2
2
  # current API version, as defined by http://semver.org/
3
- VERSION = "3.1.0"
3
+ VERSION = "3.1.1"
4
4
  end
@@ -6,9 +6,9 @@ end
6
6
 
7
7
  class GravatarifyBaseTest < Test::Unit::TestCase
8
8
  include Gravatarify::Base
9
-
9
+
10
10
  def setup; reset_gravatarify!; Gravatarify.subdomains = %w{www} end
11
-
11
+
12
12
  context "#gravatar_url, but without any options yet" do
13
13
  should "generate correct url for hash without options" do
14
14
  assert_equal BELLA_AT_GMAIL_JPG, gravatar_url('bella@gmail.com')
@@ -24,32 +24,32 @@ class GravatarifyBaseTest < Test::Unit::TestCase
24
24
  assert_equal NIL_JPG, gravatar_url(nil)
25
25
  assert_equal NIL_JPG, gravatar_url('')
26
26
  end
27
-
27
+
28
28
  should "be aliased to #build_gravatar_url, for backwards compatibility" do
29
29
  assert_equal BELLA_AT_GMAIL_JPG, build_gravatar_url('bella@gmail.com')
30
30
  end
31
31
  end
32
-
32
+
33
33
  context "#gravatar_url, with options" do
34
34
  should "add well known options like size, rating or default and always in alphabetical order" do
35
35
  assert_match "#{BELLA_AT_GMAIL_JPG}?s=16", gravatar_url('bella@gmail.com', :size => 16)
36
36
  assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Ftest.jpg&s=20", gravatar_url('bella@gmail.com', :size => 20, :default => 'http://example.com/test.jpg')
37
37
  assert_equal "#{BELLA_AT_GMAIL_JPG}?other=escaped%26yes%3F&r=x&s=30", gravatar_url('bella@gmail.com', :size => 30, :rating => :x, :other => "escaped&yes?")
38
38
  end
39
-
39
+
40
40
  should "ensure that all options are escaped correctly" do
41
41
  assert_equal "#{BELLA_AT_GMAIL_JPG}?unescaped=escaped%2Fme", gravatar_url('bella@gmail.com', 'unescaped' => 'escaped/me')
42
42
  end
43
-
43
+
44
44
  should "ignore false or nil options" do
45
45
  assert_equal "#{BELLA_AT_GMAIL_JPG}?s=24", gravatar_url('bella@gmail.com', :s => 24, :invalid => false, :other => nil)
46
46
  end
47
-
47
+
48
48
  should "allow different :filetype to be set, like 'gif' or 'png'" do
49
49
  assert_equal "#{BELLA_AT_GMAIL}.gif", gravatar_url('bella@gmail.com', :filetype => :gif)
50
50
  assert_equal "#{BELLA_AT_GMAIL}.png", gravatar_url('bella@gmail.com', :filetype => :png)
51
51
  end
52
-
52
+
53
53
  should "skip :filetype if set to false, nil or ''" do
54
54
  assert_equal "#{BELLA_AT_GMAIL}", gravatar_url('bella@gmail.com', :filetype => false)
55
55
  assert_equal "#{BELLA_AT_GMAIL}", gravatar_url('bella@gmail.com', :filetype => nil)
@@ -57,51 +57,51 @@ class GravatarifyBaseTest < Test::Unit::TestCase
57
57
  assert_equal "#{BELLA_AT_GMAIL}.foobar", gravatar_url('bella@gmail.com', :filetype => 'foobar')
58
58
  assert_equal "#{BELLA_AT_GMAIL}.gif", gravatar_url('bella@gmail.com', :filetype => :gif)
59
59
  end
60
-
60
+
61
61
  should "handle Procs as :default, to easily generate default urls based on supplied :size" do
62
62
  default = Proc.new { |*args| "http://example.com/gravatar#{args.first[:size] ? '-' + args.first[:size].to_s : ''}.jpg" }
63
- assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url('bella@gmail.com', :default => default)
63
+ assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url('bella@gmail.com', :default => default)
64
64
  assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Fgravatar-25.jpg&s=25", gravatar_url('bella@gmail.com', :size => 25, :d => default)
65
65
  assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Fgravatar-20.jpg&s=20", gravatar_url('bella@gmail.com', :size => 20, 'd' => default)
66
- end
66
+ end
67
67
  end
68
-
68
+
69
69
  context "#gravatar_url when passed in an object" do
70
70
  should "look for :email method and use it to generate gravatar_url from" do
71
71
  obj = Object.new
72
72
  mock(obj).email { "bella@gmail.com" }
73
-
73
+
74
74
  assert_equal BELLA_AT_GMAIL_JPG, gravatar_url(obj)
75
75
  end
76
-
76
+
77
77
  should "look for :mail of field :email does not exist" do
78
78
  obj = Object.new
79
79
  mock(obj).mail { "bella@gmail.com" }
80
-
81
- assert_equal BELLA_AT_GMAIL_JPG, gravatar_url(obj)
80
+
81
+ assert_equal BELLA_AT_GMAIL_JPG, gravatar_url(obj)
82
82
  end
83
-
83
+
84
84
  should "finally just use to_s... if neither :email nor :mail exists" do
85
85
  obj = Object.new
86
86
  mock(obj).to_s { "bella@gmail.com" }
87
-
88
- assert_equal BELLA_AT_GMAIL_JPG, gravatar_url(obj)
87
+
88
+ assert_equal BELLA_AT_GMAIL_JPG, gravatar_url(obj)
89
89
  end
90
-
90
+
91
91
  should "handle Procs as :default and pass in the 'object' as second parameter" do
92
92
  default = Proc.new { |options, object| "http://example.com/gravatar#{object.respond_to?(:female?) && object.female? ? '_girl' : ''}.jpg" }
93
93
  girl = Object.new
94
94
  mock(girl).email { "bella@gmail.com" }
95
- mock(girl).female? { true }
95
+ mock(girl).female? { true }
96
96
  assert_equal "#{BELLA_AT_GMAIL_JPG}?d=http%3A%2F%2Fexample.com%2Fgravatar_girl.jpg", gravatar_url(girl, :default => default)
97
-
97
+
98
98
  boy = Object.new
99
99
  mock(boy).email { "hans@gmail.com" }
100
100
  mock(boy).female? { false }
101
- assert_equal "http://www.gravatar.com/avatar/b6987c8f1d734e684cf9721970b906e5.jpg?d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url(boy, :default => default)
102
- end
101
+ assert_equal "http://www.gravatar.com/avatar/b6987c8f1d734e684cf9721970b906e5.jpg?d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url(boy, :default => default)
102
+ end
103
103
  end
104
-
104
+
105
105
  context "Gravatar hosts support" do
106
106
  should "switch to different hosts based on generated email hash, yet always the same for consecutive calls with the same email!" do
107
107
  assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg\z}, gravatar_url('bella@gmail.com')
@@ -110,41 +110,41 @@ class GravatarifyBaseTest < Test::Unit::TestCase
110
110
  assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/8f3af64e9c215d158b062a7b154e071e.jpg\z}, gravatar_url('bella@hotmail.com')
111
111
  assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/d2279c22a33da2cb57defd21c33c8ec5.jpg\z}, gravatar_url('bella@yahoo.de')
112
112
  end
113
-
114
- should "switch to https://secure.gravatar.com if :secure => true is supplied" do
115
- assert_equal "https://secure.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg", gravatar_url('bella@gmail.com', :secure => true)
116
- assert_equal "https://secure.gravatar.com/avatar/41d86cad3dd465d6913d5a3232744441.jpg", gravatar_url('bella@bella.com', :secure => true)
117
- assert_equal "https://secure.gravatar.com/avatar/d2279c22a33da2cb57defd21c33c8ec5.jpg", gravatar_url('bella@yahoo.de', :secure => true)
113
+
114
+ should "switch to https://www.gravatar.com if :secure => true is supplied" do
115
+ assert_equal "https://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg", gravatar_url('bella@gmail.com', :secure => true)
116
+ assert_equal "https://www.gravatar.com/avatar/41d86cad3dd465d6913d5a3232744441.jpg", gravatar_url('bella@bella.com', :secure => true)
117
+ assert_equal "https://www.gravatar.com/avatar/d2279c22a33da2cb57defd21c33c8ec5.jpg", gravatar_url('bella@yahoo.de', :secure => true)
118
118
  end
119
-
119
+
120
120
  should "allow Procs for :secure option, enables pretty cool stuff for stuff like request.ssl?" do
121
121
  Gravatarify.options[:secure] = Proc.new { |obj| obj.request.ssl? }
122
-
122
+
123
123
  mock_ssl = MockView.new
124
- mock(mock_ssl).request.stub!.ssl? { true }
125
- assert_equal "https://secure.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg", mock_ssl.gravatar_url('bella@gmail.com')
126
-
124
+ mock(mock_ssl).request.stub!.ssl? { true }
125
+ assert_equal "https://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg", mock_ssl.gravatar_url('bella@gmail.com')
126
+
127
127
  mock_no_ssl = MockView.new
128
128
  mock(mock_no_ssl).request.stub!.ssl? { false }
129
129
  assert_equal BELLA_AT_GMAIL_JPG, mock_no_ssl.gravatar_url('bella@gmail.com')
130
130
  end
131
131
  end
132
-
132
+
133
133
  context "Gravatarify#options" do
134
134
  setup do
135
135
  Gravatarify.options[:anything] = "test"
136
136
  Gravatarify.options[:filetype] = "png"
137
137
  Gravatarify.options[:default] = "http://example.com/gravatar.jpg"
138
138
  end
139
-
139
+
140
140
  should "ensure that default options are always added" do
141
141
  assert_equal "#{BELLA_AT_GMAIL}.png?anything=test&d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url('bella@gmail.com')
142
142
  end
143
-
143
+
144
144
  should "ensure that default options can be overriden by passing options into gravatar_url call" do
145
145
  assert_equal "#{BELLA_AT_GMAIL}.gif?anything=else&d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url('bella@gmail.com', :anything => "else", :filetype => :gif)
146
146
  end
147
-
147
+
148
148
  should "ensure that no filetypes are added when :filetype set to false, unless locally specified" do
149
149
  Gravatarify.options[:filetype] = false
150
150
  assert_equal "#{BELLA_AT_GMAIL}?anything=test&d=http%3A%2F%2Fexample.com%2Fgravatar.jpg", gravatar_url('bella@gmail.com')
@@ -5,52 +5,50 @@ require 'uri'
5
5
 
6
6
  class GravatarifySubdomainTest < Test::Unit::TestCase
7
7
  include Gravatarify::Base
8
-
8
+
9
9
  def setup; reset_gravatarify! end
10
-
10
+
11
11
  context "changing hosts through Gravatarify#subdomains" do
12
12
  should "override default subdomains (useful to e.g. switch back to 'www' only)" do
13
13
  Gravatarify.subdomains = ['a', 'b']
14
14
  assert_match %r{\Ahttp://[ab].gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg\z}, gravatar_url('info@initech.com')
15
15
  assert_match %r{\Ahttp://[ab].gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg\z}, gravatar_url('support@initech.com')
16
16
  end
17
-
17
+
18
18
  should "take in a string only argument, like www" do
19
19
  Gravatarify.subdomains = 'www'
20
20
  assert_equal "http://www.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", gravatar_url('info@initech.com')
21
- assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
21
+ assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
22
22
  end
23
-
23
+
24
24
  should "still work as expected if passed in `nil` and return urls without subdomain (default)" do
25
25
  Gravatarify.subdomains = []
26
26
  assert_equal "http://gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", gravatar_url('info@initech.com')
27
- assert_equal "http://gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
27
+ assert_equal "http://gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
28
28
  end
29
29
  end
30
-
30
+
31
31
  context "with Net::HTTP the gravatar.com subdomains" do
32
- should "return an image of type image/jpeg" do
33
- %w{ 0 1 2 www }.each do |subdomain|
32
+ %w{ 0 1 2 3 www secure }.each do |subdomain|
33
+ should "respond to http://#{subdomain}.gravatar.com/" do
34
34
  response = Net::HTTP.get_response URI.parse("http://#{subdomain}.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg")
35
35
  assert_equal 200, response.code.to_i
36
36
  assert_equal "image/jpeg", response.content_type
37
37
  end
38
+
39
+ should "respond to https://#{subdomain}.gravatar.com/ urls as well" do
40
+ http = Net::HTTP.new("#{subdomain}.gravatar.com", 443)
41
+ http.use_ssl = true
42
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
43
+
44
+ response = http.get '/avatar/4979dd9653e759c78a81d4997f56bae2.jpg'
45
+ assert_equal 200, response.code.to_i
46
+ assert_equal "image/jpeg", response.content_type
47
+ end
38
48
  end
39
-
40
- should "not respond to 3.gravatar.com, if so add to subdomains dude!!!" do
41
- assert_raises(SocketError) { Net::HTTP.get_response URI.parse('http://3.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg') }
42
- end
43
-
44
- should "respond to https://secure.gravatar.com/ urls as well" do
45
- http = Net::HTTP.new('secure.gravatar.com', 443)
46
- http.use_ssl = true
47
-
48
- # do not verify peer certificate (just get rid of that warning!)
49
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
-
51
- response = http.get '/avatar/4979dd9653e759c78a81d4997f56bae2.jpg'
52
- assert_equal 200, response.code.to_i
53
- assert_equal "image/jpeg", response.content_type
49
+
50
+ should "not respond to 4.gravatar.com, if so add to subdomains dude!!!" do
51
+ assert_raises(SocketError) { Net::HTTP.get_response URI.parse('http://4.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg') }
54
52
  end
55
53
  end
56
- end
54
+ end
metadata CHANGED
@@ -1,98 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gravatarify
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease:
6
- segments:
7
- - 3
8
- - 1
9
- - 0
10
- version: 3.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Lukas Westermann
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-06-10 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
25
17
  - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 35
28
- segments:
29
- - 2
30
- - 10
31
- - 2
18
+ - !ruby/object:Gem::Version
32
19
  version: 2.10.2
33
- requirement: *id001
34
20
  type: :development
35
- name: shoulda
36
- - !ruby/object:Gem::Dependency
37
21
  prerelease: false
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
41
24
  - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 61
44
- segments:
45
- - 0
46
- - 10
47
- - 5
25
+ - !ruby/object:Gem::Version
26
+ version: 2.10.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
48
33
  version: 0.10.5
49
- requirement: *id002
50
34
  type: :development
51
- name: rr
52
- - !ruby/object:Gem::Dependency
53
35
  prerelease: false
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
57
38
  - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 7
60
- segments:
61
- - 3
62
- - 0
63
- - 0
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
64
47
  version: 3.0.0
65
- requirement: *id003
66
48
  type: :development
67
- name: activesupport
68
- - !ruby/object:Gem::Dependency
69
49
  prerelease: false
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
73
52
  - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
79
- requirement: *id004
80
- type: :development
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
81
56
  name: rake
82
- description: Ruby (and Rails) Gravatar helpers with unique options like Proc's for default images, support for gravatar.com's multiple host names, ability to define reusable styles and much more...
83
- email:
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby (and Rails) Gravatar helpers with unique options like Proc's for
70
+ default images, support for gravatar.com's multiple host names, ability to define
71
+ reusable styles and much more...
72
+ email:
84
73
  - lukas.westermann@gmail.com
85
74
  executables: []
86
-
87
75
  extensions: []
88
-
89
76
  extra_rdoc_files: []
90
-
91
- files:
92
- - .gitignore
93
- - .travis.yml
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
94
80
  - Gemfile
95
- - Gemfile.lock
96
81
  - LICENSE
97
82
  - README.md
98
83
  - Rakefile
@@ -108,44 +93,31 @@ files:
108
93
  - test/unit/gravatarify_helper_test.rb
109
94
  - test/unit/gravatarify_styles_test.rb
110
95
  - test/unit/gravatarify_subdomain_test.rb
111
- homepage: http://github.com/lwe/gravatarify
112
- licenses:
96
+ homepage: https://github.com/lwe/gravatarify
97
+ licenses:
113
98
  - MIT
99
+ metadata: {}
114
100
  post_install_message:
115
101
  rdoc_options: []
116
-
117
- require_paths:
102
+ require_paths:
118
103
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
- requirements:
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
122
106
  - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 57
125
- segments:
126
- - 1
127
- - 8
128
- - 7
107
+ - !ruby/object:Gem::Version
129
108
  version: 1.8.7
130
- required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
- requirements:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
133
111
  - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 23
136
- segments:
137
- - 1
138
- - 3
139
- - 6
112
+ - !ruby/object:Gem::Version
140
113
  version: 1.3.6
141
114
  requirements: []
142
-
143
115
  rubyforge_project:
144
- rubygems_version: 1.8.15
116
+ rubygems_version: 2.2.0
145
117
  signing_key:
146
- specification_version: 3
118
+ specification_version: 4
147
119
  summary: Awesome gravatar support for Ruby (and Rails).
148
- test_files:
120
+ test_files:
149
121
  - test/benchmark/benchmark.rb
150
122
  - test/test_helper.rb
151
123
  - test/unit/gravatarify_base_test.rb
@@ -1,31 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- gravatarify (3.1.0)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- activesupport (3.2.5)
10
- i18n (~> 0.6)
11
- multi_json (~> 1.0)
12
- i18n (0.6.0)
13
- multi_json (1.3.6)
14
- rake (0.9.2.2)
15
- rr (1.0.4)
16
- shoulda (3.0.1)
17
- shoulda-context (~> 1.0.0)
18
- shoulda-matchers (~> 1.0.0)
19
- shoulda-context (1.0.0)
20
- shoulda-matchers (1.0.0)
21
-
22
- PLATFORMS
23
- ruby
24
-
25
- DEPENDENCIES
26
- activesupport (>= 3.0.0)
27
- gravatarify!
28
- jruby-openssl
29
- rake
30
- rr (>= 0.10.5)
31
- shoulda (>= 2.10.2)