gravatarify 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  doc/
2
2
  pkg/
3
3
  .yardoc
4
- *.gemspec
data/README.md CHANGED
@@ -67,7 +67,7 @@ This then provides three helper methods: `gravatar_url`, `gravatar_attrs` and `g
67
67
  To just build a simple `<img/>` tag, pass in an object (if it responds to `email` or `mail`)
68
68
  or a string containing the e-mail address:
69
69
 
70
- <%= gravatar_tag @user %> # => assumes @user has email or mail field!
70
+ <%= gravatar_tag @user %> # => assumes @user.respond_to?(:email) or @user.respond_to?(:mail)
71
71
 
72
72
  This builds a neat `<img/>`-tag. To display an "X" rated avatar which is 25x25 pixel in size
73
73
  and the `<img/>` tag should have a class attribute, do:
@@ -79,7 +79,7 @@ pass them in the `:html` option as hash. If more control is needed, or just the
79
79
  required, resort to `gravatar_url`, which returns a string with the (unescaped) url:
80
80
 
81
81
  <img src="<%= h(gravatar_url(@user.author_email, :size => 16)) %>" alt="Gravatar"/>
82
-
82
+
83
83
  Using styles
84
84
  ------------
85
85
 
@@ -94,7 +94,7 @@ these are reusable presets of options:
94
94
  <%= gravatar_tag @user, :mini %> # => <img alt="" class="gravatar gravatar-mini" height="16" src.... />
95
95
 
96
96
  # or in/another/view.html.haml:
97
- %img{gravatar_attrs(@user, :default)/ # => <img alt="" class="gravatar" height="45" ... />
97
+ %img{ gravatar_attrs(@user, :default) }/ # => <img alt="" class="gravatar" height="45" ... />
98
98
 
99
99
  Need to change to size of all `:mini` gravatars? Easy, just change the definition in `Gravatarify.styles`.
100
100
  Of course settings via `Gravatarify.options` are "mixed-in" as well, so:
@@ -208,9 +208,9 @@ to generate an image url, based on the request size:
208
208
  end
209
209
 
210
210
  # now each time a gravatar url is generated, the Proc is evaluated:
211
- @user.gravatar_url
211
+ gravatar_url(@user)
212
212
  # => "http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar-80.jpg"
213
- @user.gravatar_url(:size => 16)
213
+ gravatar_url(@user, :size => 16)
214
214
  # => "http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar-16.jpg&s=16"
215
215
 
216
216
  Into the block is passed the options hash and as second parameter the object itself, so it's possible to do stuff like
@@ -218,7 +218,7 @@ Into the block is passed the options hash and as second parameter the object its
218
218
  # doing stuff like showing default avatar based on gender...
219
219
  @user = User.new(:gender => :female, :email => 'bella@gmail.com') # => @user.female? = true
220
220
 
221
- @user.gravatar_url :default => Proc.new { |opts, obj| "http://example.com/avatar#{obj.respond_to?(:female) && obj.female? ? '_female' : ''}.jpg" }
221
+ gravatar_url @user, :default => Proc.new { |opts, obj| "http://example.com/avatar#{obj.respond_to?(:female) && obj.female? ? '_female' : ''}.jpg" }
222
222
  # => http://0.gravatar.com/...jpg?d=http%3A%2F%2Fexample.com%2Fgravatar_female.jpg
223
223
 
224
224
  Not only the `:default` option accepts a Proc, but also `:secure`, can be useful to handle cases where
@@ -248,7 +248,7 @@ it's used, then...
248
248
 
249
249
  1. Remove all occurences of `gravatarify` in the models
250
250
  2. Change calls from `<%= image_tag @user.gravatar_url %>` to
251
- saner `<%= gravatar_tag @user %>` calls or of course if just the url
251
+ saner `<%= gravatar_tag @user %>` calls, or if just the url
252
252
  is required to `gravatar_url(@user)`.
253
253
 
254
254
  If the model used `gravatarify :author_email`, then changes in the views must reflect that and use it
data/Rakefile CHANGED
@@ -1,10 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'yard'
4
-
5
- def gravatarify_version
6
- @gravatarify_version ||= (tmp = YAML.load(File.read('VERSION.yml'))) && [tmp[:major], tmp[:minor], tmp[:patch]] * '.'
7
- end
4
+ require File.join(File.dirname(__FILE__), 'lib', 'gravatarify')
8
5
 
9
6
  desc 'Default: run unit tests.'
10
7
  task :default => :test
@@ -22,19 +19,21 @@ YARD::Rake::YardocTask.new(:doc) do |t|
22
19
  t.files = ['lib/**/*.rb']
23
20
  t.options = [
24
21
  "--readme", "README.md",
25
- "--title", "gravatarify (v#{gravatarify_version}) API Documentation"
22
+ "--title", "gravatarify (v#{Gravatarify::VERSION}) API Documentation"
26
23
  ]
27
24
  end
28
25
 
29
26
  begin
30
27
  require 'jeweler'
31
28
  Jeweler::Tasks.new do |gemspec|
29
+ gemspec.version = Gravatarify::VERSION
32
30
  gemspec.name = "gravatarify"
33
31
  gemspec.summary = "Awesome gravatar support for Ruby (and Rails)."
34
32
  description = <<-DESC
35
33
  Awesome gravatar support for Ruby (and Rails) -
36
- with unique options like Proc's for default images, or
37
- support for gravatar.com's multiple host names.
34
+ with unique options like Proc's for default images,
35
+ support for gravatar.com's multiple host names, ability to
36
+ define reusable styles and much more...
38
37
  DESC
39
38
  gemspec.description = description.strip
40
39
  gemspec.email = "lukas.westermann@gmail.com"
@@ -42,6 +41,10 @@ begin
42
41
  gemspec.authors = ["Lukas Westermann"]
43
42
  gemspec.licenses = %w{LICENSE}
44
43
  gemspec.extra_rdoc_files = %w{README.md}
44
+
45
+ gemspec.add_development_dependency('shoulda', '>= 2.10.2')
46
+ gemspec.add_development_dependency('rr', '>= 0.10.5')
47
+ gemspec.add_development_dependency('activesupport', '>= 2.3.5')
45
48
  end
46
49
  Jeweler::GemcutterTasks.new
47
50
  rescue LoadError
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gravatarify}
8
+ s.version = "2.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Lukas Westermann"]
12
+ s.date = %q{2010-03-09}
13
+ s.description = %q{Awesome gravatar support for Ruby (and Rails) -
14
+ with unique options like Proc's for default images,
15
+ support for gravatar.com's multiple host names, ability to
16
+ define reusable styles and much more...}
17
+ s.email = %q{lukas.westermann@gmail.com}
18
+ s.extra_rdoc_files = [
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.md",
25
+ "Rakefile",
26
+ "gravatarify.gemspec",
27
+ "lib/gravatarify.rb",
28
+ "lib/gravatarify/base.rb",
29
+ "lib/gravatarify/helper.rb",
30
+ "lib/gravatarify/utils.rb",
31
+ "rails/init.rb",
32
+ "test/benchmark/benchmark.rb",
33
+ "test/test_helper.rb",
34
+ "test/unit/gravatarify_base_test.rb",
35
+ "test/unit/gravatarify_helper_test.rb",
36
+ "test/unit/gravatarify_styles_test.rb",
37
+ "test/unit/gravatarify_subdomain_test.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/lwe/gravatarify}
40
+ s.licenses = ["LICENSE"]
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{Awesome gravatar support for Ruby (and Rails).}
45
+ s.test_files = [
46
+ "test/benchmark/benchmark.rb",
47
+ "test/test_helper.rb",
48
+ "test/unit/gravatarify_base_test.rb",
49
+ "test/unit/gravatarify_helper_test.rb",
50
+ "test/unit/gravatarify_styles_test.rb",
51
+ "test/unit/gravatarify_subdomain_test.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
60
+ s.add_development_dependency(%q<rr>, [">= 0.10.5"])
61
+ s.add_development_dependency(%q<activesupport>, [">= 2.3.5"])
62
+ else
63
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
64
+ s.add_dependency(%q<rr>, [">= 0.10.5"])
65
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
69
+ s.add_dependency(%q<rr>, [">= 0.10.5"])
70
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
71
+ end
72
+ end
73
+
data/lib/gravatarify.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # Loads all required submodules
2
+ module Gravatarify
3
+ # current API version, as defined by http://semver.org/
4
+ VERSION = "2.1.0".freeze
5
+
6
+ autoload :Base, 'gravatarify/base'
7
+ autoload :Utils, 'gravatarify/utils'
8
+ autoload :Helper, 'gravatarify/helper'
9
+ end
2
10
 
3
- # Base -> provides the basic gravatar_url method, can also be used for
4
- # custom implementations, just include Gravatarify::Base.
5
- require 'gravatarify/base'
6
- require 'gravatarify/utils'
7
- require 'gravatarify/helper'
8
-
9
- # and HAML support (if defined)
11
+ # and add HAML support (if defined)
10
12
  Haml::Helpers.send(:include, Gravatarify::Helper) if defined?(Haml)
@@ -48,7 +48,7 @@ module Gravatarify
48
48
  # defined.
49
49
  def subdomain(str) #:nodoc:
50
50
  @subdomains ||= %w{ 0 1 2 www }
51
- @subdomains[str.hash % @subdomains.size] || 'www'
51
+ (@subdomains.empty? ? nil : @subdomains[str.hash % @subdomains.size]) || 'www'
52
52
  end
53
53
  end
54
54
 
@@ -96,13 +96,14 @@ module Gravatarify
96
96
  url_options = Utils.merge_gravatar_options(*params)
97
97
  email_hash = Digest::MD5.hexdigest(Utils.smart_email(email))
98
98
  extension = (ext = url_options.delete(:filetype) and ext != '') ? ".#{ext || 'jpg'}" : '' # slightly adapted from gudleik's implementation
99
- build_gravatar_host(email_hash, url_options.delete(:secure)) + "/avatar/#{email_hash}#{extension}#{build_gravatar_options(email, url_options)}"
99
+ host = Base.gravatar_host(self, email_hash, url_options.delete(:secure))
100
+ "#{host}/avatar/#{email_hash}#{extension}#{Base.gravatar_params(email, url_options)}"
100
101
  end
101
102
 
102
103
  # For backwards compatibility.
103
104
  alias_method :build_gravatar_url, :gravatar_url
104
-
105
- private
105
+
106
+ protected
106
107
  # Builds gravatar host name from supplied e-mail hash.
107
108
  # Ensures that for the same +str_hash+ always the same subdomain is used.
108
109
  #
@@ -111,22 +112,22 @@ module Gravatarify
111
112
  # else that subdomain magic. If it's passed in a +Proc+, it's evaluated and the result (+true+/+false+) is used
112
113
  # for the same decicion.
113
114
  # @return [String] Protocol and hostname (like <tt>http://www.gravatar.com</tt>), without trailing slash.
114
- def build_gravatar_host(str_hash, secure = false)
115
- secure = secure.call(self) if secure.respond_to?(:call)
116
- secure ? "https://secure.gravatar.com" : "http://#{Gravatarify.subdomain(str_hash)}.gravatar.com"
115
+ def self.gravatar_host(context, str_hash, secure = false)
116
+ use_ssl_host = secure.is_a?(Proc) ? secure.call(context) : secure
117
+ use_ssl_host ? "https://secure.gravatar.com" : "http://#{Gravatarify.subdomain(str_hash)}.gravatar.com"
117
118
  end
118
-
119
+
119
120
  # Builds a query string from all passed in options.
120
- def build_gravatar_options(source, url_options = {})
121
+ def self.gravatar_params(source, url_options = {})
121
122
  params = url_options.inject([]) do |params, (key, value)|
122
- key = (GRAVATAR_ABBREV_OPTIONS[key] || key).to_sym # shorten key
123
+ key = (GRAVATAR_ABBREV_OPTIONS[key] || key).to_sym # shorten & symbolize key
123
124
  unless key == :html
124
- value = value.call(url_options, source) if key == :d and value.respond_to?(:call)
125
+ value = value.call(url_options, source) if key == :d and value.is_a?(Proc)
125
126
  params << "#{key}=#{CGI.escape(value.to_s)}" if value
126
127
  end
127
128
  params
128
129
  end
129
130
  "?#{params.sort * '&'}" unless params.empty?
130
- end
131
- end
131
+ end
132
+ end
132
133
  end
@@ -32,7 +32,6 @@ module Gravatarify::Helper
32
32
  # @return [String] a complete and hopefully valid +img+ tag.
33
33
  def gravatar_tag(email, *params)
34
34
  html_attrs = gravatar_attrs(email, *params).map { |key,value| "#{key}=\"#{CGI.escapeHTML(value.to_s)}\"" }.sort.join(" ")
35
- html = "<img #{html_attrs} />"
36
- Gravatarify::Utils.with_xss? ? html.html_safe! : html
35
+ Gravatarify::Utils.make_html_safe_if_available("<img #{html_attrs} />");
37
36
  end
38
37
  end
@@ -1,6 +1,6 @@
1
1
  module Gravatarify
2
2
  # Set of common utility methods to e.g. deep merge options etc.
3
- module Utils #:nodoc:
3
+ module Utils #:nodoc:
4
4
  # Merge supplied list of +params+ with the globally defined default options and
5
5
  # any params. Then merge remaining params as hash.
6
6
  def self.merge_gravatar_options(*params)
@@ -24,8 +24,13 @@ module Gravatarify
24
24
  def self.smart_email(obj)
25
25
  (obj.respond_to?(:email) ? obj.send(:email) : (obj.respond_to?(:mail) ? obj.send(:mail) : obj)).to_s.strip.downcase
26
26
  end
27
-
28
- # Returns +true+ when those XSS methods are available, else +false+ is returned.
29
- def self.with_xss?; "".respond_to?(:html_safe!) end
27
+
28
+ # Kinda a workaround for Rails 3.x and it's newly introduced +html_safe+ method, which
29
+ # is used over old school +html_safe!+ method. Well, well.
30
+ def self.make_html_safe_if_available(str)
31
+ return str.html_safe if str.respond_to?(:html_safe)
32
+ return str.html_safe! if str.respond_to?(:html_safe!)
33
+ str
34
+ end
30
35
  end
31
36
  end
@@ -4,7 +4,7 @@ require 'benchmark'
4
4
  include Gravatarify::Helper
5
5
 
6
6
  emails = ['foo@bar.com', 'foobar_didum_asdf@asdasd.com',
7
- 'ASDASDSA@aasd_ASDSAd.com', ' sad@asdASdssasd .ch', 'Master <asdASD@asdasd.com >']
7
+ 'ASDASDSA@aasd_ASDSAd.com', ' sad@asdASdssasd.ch', ' didum@asdasd.com ']
8
8
  n = 10000
9
9
  Benchmark.bm(23) do |bm|
10
10
  bm.report("gravatar_url w/o args: ") { for i in 1..n do gravatar_url(emails[i % 5]) end }
data/test/test_helper.rb CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'rr'
5
-
6
5
  require 'gravatarify'
7
6
 
8
7
  Test::Unit::TestCase.send :include, RR::Adapters::TestUnit
@@ -15,6 +14,6 @@ def reset_gravatarify!
15
14
  end
16
15
 
17
16
  # some often used values...
18
- BELLA_AT_GMAIL = "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d"
17
+ BELLA_AT_GMAIL = "http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d"
19
18
  BELLA_AT_GMAIL_JPG = "#{BELLA_AT_GMAIL}.jpg"
20
- NIL_JPG = "http://1.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e.jpg"
19
+ NIL_JPG = "http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e.jpg"
@@ -7,7 +7,7 @@ end
7
7
  class GravatarifyBaseTest < Test::Unit::TestCase
8
8
  include Gravatarify::Base
9
9
 
10
- def setup; reset_gravatarify! end
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
@@ -32,7 +32,7 @@ class GravatarifyBaseTest < Test::Unit::TestCase
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
- assert_equal "#{BELLA_AT_GMAIL_JPG}?s=16", gravatar_url('bella@gmail.com', :size => 16)
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
@@ -104,11 +104,11 @@ class GravatarifyBaseTest < Test::Unit::TestCase
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
- assert_equal "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg", gravatar_url('bella@gmail.com')
107
+ assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg\z}, gravatar_url('bella@gmail.com')
108
108
  assert_equal gravatar_url('bella@gmail.com'), gravatar_url('bella@gmail.com')
109
- assert_equal "http://1.gravatar.com/avatar/41d86cad3dd465d6913d5a3232744441.jpg", gravatar_url('bella@bella.com')
110
- assert_equal "http://2.gravatar.com/avatar/8f3af64e9c215d158b062a7b154e071e.jpg", gravatar_url('bella@hotmail.com')
111
- assert_equal "http://www.gravatar.com/avatar/d2279c22a33da2cb57defd21c33c8ec5.jpg", gravatar_url('bella@yahoo.de')
109
+ assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/41d86cad3dd465d6913d5a3232744441.jpg\z}, gravatar_url('bella@bella.com')
110
+ assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/8f3af64e9c215d158b062a7b154e071e.jpg\z}, gravatar_url('bella@hotmail.com')
111
+ assert_match %r{\Ahttp://(0|1|2|www).gravatar.com/avatar/d2279c22a33da2cb57defd21c33c8ec5.jpg\z}, gravatar_url('bella@yahoo.de')
112
112
  end
113
113
 
114
114
  should "switch to https://secure.gravatar.com if :secure => true is supplied" do
@@ -7,6 +7,7 @@ class GravatarifyHelpersTest < Test::Unit::TestCase
7
7
  def setup
8
8
  # just ensure that no global options are defined when starting next test
9
9
  reset_gravatarify!
10
+ Gravatarify.subdomains = %w{www}
10
11
  end
11
12
 
12
13
  context "#gravatar_attrs" do
@@ -32,23 +33,24 @@ class GravatarifyHelpersTest < Test::Unit::TestCase
32
33
 
33
34
  context "#gravatar_tag helper" do
34
35
  should "create <img/> tag with correct gravatar urls" do
35
- assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />', gravatar_tag('bella@gmail.com')
36
+ assert_equal '<img alt="" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />', gravatar_tag('bella@gmail.com')
36
37
  end
37
38
 
38
39
  should "create <img/> tags and handle all options correctly, other options should be passed to Rails' image_tag" do
39
- assert_equal '<img alt="" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" width="16" />',
40
+ assert_equal '<img alt="" height="16" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=16" width="16" />',
40
41
  gravatar_tag('bella@gmail.com', :size => 16)
41
- assert_equal '<img alt="" class="gravatar" height="16" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?d=x&amp;s=16" width="16" />',
42
+ assert_equal '<img alt="" class="gravatar" height="16" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?d=x&amp;s=16" width="16" />',
42
43
  gravatar_tag('bella@gmail.com', :html => { :class => "gravatar" }, :size => 16, :d => "x")
43
44
  end
44
45
 
45
46
  should "ensure that all values are correctly html-esacped!" do
46
- assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="&lt;&gt;" width="80" />',
47
+ assert_equal '<img alt="" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="&lt;&gt;" width="80" />',
47
48
  gravatar_tag('bella@gmail.com', :html => { :title => '<>' })
48
49
  end
49
50
 
50
- should "be html_safe if rails 2.3.5" do
51
+ should "be html_safe if rails ~> 2.3.5" do
51
52
  require 'active_support'
53
+ require 'active_support/core_ext/string/output_safety' # for rails 3, be explicit...
52
54
  assert gravatar_tag('bella@gmail.com').html_safe?, "#html_safe? expected to return <true>"
53
55
  end
54
56
  end
@@ -58,7 +60,7 @@ class GravatarifyHelpersTest < Test::Unit::TestCase
58
60
  obj = Object.new
59
61
  mock(obj).email { "bella@gmail.com" }
60
62
 
61
- assert_equal '<img alt="" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
63
+ assert_equal '<img alt="" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
62
64
  gravatar_tag(obj)
63
65
  end
64
66
  end
@@ -67,11 +69,11 @@ class GravatarifyHelpersTest < Test::Unit::TestCase
67
69
  should "add be added to all tags/hashes created by gravatar_tag or gravatar_attrs" do
68
70
  Gravatarify.options[:html] = { :title => "Gravatar", :class => "gravatar" } # add a title attribute, yeah neat-o!
69
71
 
70
- assert_equal '<img alt="" class="gravatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="Gravatar" width="80" />',
72
+ assert_equal '<img alt="" class="gravatar" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" title="Gravatar" width="80" />',
71
73
  gravatar_tag('bella@gmail.com')
72
74
  hash = gravatar_attrs('bella@gmail.com', :size => 20, :html => { :title => "Gravatar for Bella", :id => "test" })
73
75
  expected = {
74
- :alt => "", :width => 20, :height => 20, :src => "http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=20",
76
+ :alt => "", :width => 20, :height => 20, :src => "http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=20",
75
77
  :title => "Gravatar for Bella", :id => "test", :class => "gravatar"
76
78
  }
77
79
  assert_equal expected, hash
@@ -80,16 +82,16 @@ class GravatarifyHelpersTest < Test::Unit::TestCase
80
82
  should "not allow :src, :height or :width to be set via global options and all local options should override!" do
81
83
  Gravatarify.options[:html] = { :src => "avatar-30.jpg", :width => 30, :title => "Avatar" }
82
84
 
83
- assert_equal '<img alt="" height="25" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=25" title="Gravatar" width="25" />',
85
+ assert_equal '<img alt="" height="25" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg?s=25" title="Gravatar" width="25" />',
84
86
  gravatar_tag('bella@gmail.com', :size => 25, :html => { :title => 'Gravatar' })
85
87
  end
86
88
 
87
89
  should "allow :alt to be set globally" do
88
90
  Gravatarify.options[:html] = { :alt => "Gravatar" }
89
91
 
90
- assert_equal '<img alt="Gravatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
92
+ assert_equal '<img alt="Gravatar" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d.jpg" width="80" />',
91
93
  gravatar_tag('bella@gmail.com')
92
- assert_equal '<img alt="Avatar" height="80" src="http://0.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d" width="80" />',
94
+ assert_equal '<img alt="Avatar" height="80" src="http://www.gravatar.com/avatar/1cacf1bc403efca2e7a58bcfa9574e4d" width="80" />',
93
95
  gravatar_tag('bella@gmail.com', :filetype => false, :html => { :alt => 'Avatar' })
94
96
  end
95
97
  end
@@ -5,6 +5,7 @@ class GravatarifyStylesTest < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  reset_gravatarify!
8
+ Gravatarify.subdomains = %w{www}
8
9
  Gravatarify.styles.clear
9
10
  end
10
11
 
@@ -10,9 +10,9 @@ class GravatarifySubdomainTest < Test::Unit::TestCase
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
- Gravatarify.subdomains = ['0', '1']
14
- assert_equal "http://0.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", gravatar_url('info@initech.com')
15
- assert_equal "http://1.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
13
+ Gravatarify.subdomains = ['a', 'b']
14
+ assert_match %r{\Ahttp://[ab].gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg\z}, gravatar_url('info@initech.com')
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
@@ -45,8 +45,8 @@ class GravatarifySubdomainTest < Test::Unit::TestCase
45
45
  http = Net::HTTP.new('secure.gravatar.com', 443)
46
46
  http.use_ssl = true
47
47
 
48
- # do not verify peer certificate (just get rid of that warning!)
49
- http.instance_variable_get('@ssl_context').verify_mode = OpenSSL::SSL::VERIFY_NONE
48
+ # do not verify peer certificate (just get rid of that warning!)
49
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
50
 
51
51
  response = http.get '/avatar/4979dd9653e759c78a81d4997f56bae2.jpg'
52
52
  assert_equal 200, response.code.to_i
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravatarify
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ prerelease: false
5
+ segments:
6
+ - 2
7
+ - 1
8
+ - 0
9
+ version: 2.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Lukas Westermann
@@ -9,14 +14,56 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-08 00:00:00 +01:00
17
+ date: 2010-03-09 00:00:00 +01:00
13
18
  default_executable:
14
- dependencies: []
15
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 10
30
+ - 2
31
+ version: 2.10.2
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rr
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 10
44
+ - 5
45
+ version: 0.10.5
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 3
58
+ - 5
59
+ version: 2.3.5
60
+ type: :development
61
+ version_requirements: *id003
16
62
  description: |-
17
63
  Awesome gravatar support for Ruby (and Rails) -
18
- with unique options like Proc's for default images, or
19
- support for gravatar.com's multiple host names.
64
+ with unique options like Proc's for default images,
65
+ support for gravatar.com's multiple host names, ability to
66
+ define reusable styles and much more...
20
67
  email: lukas.westermann@gmail.com
21
68
  executables: []
22
69
 
@@ -29,8 +76,7 @@ files:
29
76
  - LICENSE
30
77
  - README.md
31
78
  - Rakefile
32
- - VERSION.yml
33
- - init.rb
79
+ - gravatarify.gemspec
34
80
  - lib/gravatarify.rb
35
81
  - lib/gravatarify/base.rb
36
82
  - lib/gravatarify/helper.rb
@@ -55,18 +101,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
101
  requirements:
56
102
  - - ">="
57
103
  - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
58
106
  version: "0"
59
- version:
60
107
  required_rubygems_version: !ruby/object:Gem::Requirement
61
108
  requirements:
62
109
  - - ">="
63
110
  - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
64
113
  version: "0"
65
- version:
66
114
  requirements: []
67
115
 
68
116
  rubyforge_project:
69
- rubygems_version: 1.3.5
117
+ rubygems_version: 1.3.6
70
118
  signing_key:
71
119
  specification_version: 3
72
120
  summary: Awesome gravatar support for Ruby (and Rails).
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 2
3
- :minor: 0
4
- :build:
5
- :patch: 4
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'rails', 'init')