gravatarify 1.2.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,34 +11,26 @@ class GravatarifySubdomainTest < Test::Unit::TestCase
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 = ['0', '1']
14
- assert_equal "http://0.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", build_gravatar_url('info@initech.com')
15
- assert_equal "http://1.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", build_gravatar_url('support@initech.com')
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')
16
16
  end
17
17
 
18
- should "take in a string only argument, like www (and be aliased to 'subdomain' to singularize it :D)" do
19
- Gravatarify.subdomain = 'www'
20
- assert_equal "http://www.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", build_gravatar_url('info@initech.com')
21
- assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", build_gravatar_url('support@initech.com')
18
+ should "take in a string only argument, like www" do
19
+ Gravatarify.subdomains = 'www'
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')
22
22
  end
23
23
 
24
24
  should "still work as expected if passed in `nil` and return urls with default subdomain `www`" do
25
- Gravatarify.subdomain = nil
26
- assert_equal "http://www.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", build_gravatar_url('info@initech.com')
27
- assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", build_gravatar_url('support@initech.com')
25
+ Gravatarify.subdomains = nil
26
+ assert_equal "http://www.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", gravatar_url('info@initech.com')
27
+ assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", gravatar_url('support@initech.com')
28
28
  end
29
29
  end
30
-
31
- context "Gravatarify#use_only_www!" do
32
- should "only generate www.gravatar.com urls" do
33
- Gravatarify.use_www_only!
34
- assert_equal "http://www.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg", build_gravatar_url('info@initech.com')
35
- assert_equal "http://www.gravatar.com/avatar/d4489907918035d0bc6ff3f6c76e760d.jpg", build_gravatar_url('support@initech.com')
36
- end
37
- end
38
-
30
+
39
31
  context "with Net::HTTP the gravatar.com subdomains" do
40
32
  should "return an image of type image/jpeg" do
41
- Gravatarify.subdomains.each do |subdomain|
33
+ %w{ 0 1 2 www }.each do |subdomain|
42
34
  response = Net::HTTP.get_response URI.parse("http://#{subdomain}.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg")
43
35
  assert_equal 200, response.code.to_i
44
36
  assert_equal "image/jpeg", response.content_type
@@ -53,12 +45,12 @@ class GravatarifySubdomainTest < Test::Unit::TestCase
53
45
  http = Net::HTTP.new('secure.gravatar.com', 443)
54
46
  http.use_ssl = true
55
47
 
56
- # do not verify peer certificate (get rid of that warning dude!)
48
+ # do not verify peer certificate (just get rid of that warning!)
57
49
  http.instance_variable_get('@ssl_context').verify_mode = OpenSSL::SSL::VERIFY_NONE
58
50
 
59
51
  response = http.get '/avatar/4979dd9653e759c78a81d4997f56bae2.jpg'
60
52
  assert_equal 200, response.code.to_i
61
- assert_equal "image/jpeg", response.content_type
53
+ assert_equal "image/jpeg", response.content_type
62
54
  end
63
55
  end
64
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravatarify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Westermann
@@ -9,12 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 +01:00
12
+ date: 2009-11-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: |-
17
- Awesome gravatar support for Ruby (and Rails, DataMapper, Haml) -
17
+ Awesome gravatar support for Ruby (and Rails) -
18
18
  with unique options like Proc's for default images, or
19
19
  support for gravatar.com's multiple host names.
20
20
  email: lukas.westermann@gmail.com
@@ -34,14 +34,13 @@ files:
34
34
  - lib/gravatarify.rb
35
35
  - lib/gravatarify/base.rb
36
36
  - lib/gravatarify/helper.rb
37
- - lib/gravatarify/object_support.rb
37
+ - lib/gravatarify/utils.rb
38
38
  - rails/init.rb
39
39
  - test/test_helper.rb
40
- - test/unit/gravatarify_ar_dm_test.rb
41
40
  - test/unit/gravatarify_base_test.rb
42
41
  - test/unit/gravatarify_helper_test.rb
43
- - test/unit/gravatarify_object_support_test.rb
44
42
  - test/unit/gravatarify_rack_vs_cgi_test.rb
43
+ - test/unit/gravatarify_styles_test.rb
45
44
  - test/unit/gravatarify_subdomain_test.rb
46
45
  has_rdoc: true
47
46
  homepage: http://github.com/lwe/gravatarify
@@ -70,12 +69,11 @@ rubyforge_project:
70
69
  rubygems_version: 1.3.5
71
70
  signing_key:
72
71
  specification_version: 3
73
- summary: Awesome gravatar support for Ruby (and Rails, DataMapper, Haml).
72
+ summary: Awesome gravatar support for Ruby (and Rails).
74
73
  test_files:
75
74
  - test/test_helper.rb
76
- - test/unit/gravatarify_ar_dm_test.rb
77
75
  - test/unit/gravatarify_base_test.rb
78
76
  - test/unit/gravatarify_helper_test.rb
79
- - test/unit/gravatarify_object_support_test.rb
80
77
  - test/unit/gravatarify_rack_vs_cgi_test.rb
78
+ - test/unit/gravatarify_styles_test.rb
81
79
  - test/unit/gravatarify_subdomain_test.rb
@@ -1,59 +0,0 @@
1
- # Enables +gravatarify+ support in any plain old ruby object, ActiveRecord, DataMapper or wherever you like :)
2
- #
3
- # Provides the {ClassMethods#gravatarify} method to handle the creation of
4
- # a +gravatar_url+ method for a ruby object.
5
- #
6
- # An ActiveRecord example:
7
- #
8
- # class User < ActiveRecord::Base
9
- # gravatarify
10
- # end
11
- # @user.gravatar_url # that's it!
12
- #
13
- # A DataMapper example:
14
- #
15
- # class User
16
- # include DataMapper::Resource
17
- # property ...
18
- # property :author_email, String
19
- # gravatarify :author_email
20
- # end
21
- # @user.gravatar_url # that's it, using the specified field!
22
- #
23
- # And finally, using a plain old ruby object:
24
- #
25
- # class SimpleUser
26
- # include Gravatarify::ObjectSupport
27
- # attr_accessor :email
28
- # gravatarify
29
- # end
30
- # @user.gravatar_url # that's it!!!
31
- #
32
- # If more fine grained controller is required, feel free to use {Gravatarify::Base#build_gravatar_url}
33
- # directly.
34
- module Gravatarify::ObjectSupport
35
- include Gravatarify::Base
36
-
37
- def self.included(base) #:nodoc:
38
- base.send :extend, ClassMethods
39
- end
40
-
41
- module ClassMethods
42
- def gravatarify(*args)
43
- options = args.last.is_a?(Hash) ? args.pop : {}
44
- source = args.shift
45
- define_method(:gravatar_url) do |*params|
46
- source = :email if !source and respond_to?(:email)
47
- source = :mail if !source and respond_to?(:mail)
48
- build_gravatar_url send(source || :email), options.merge(params.first || {})
49
- end
50
- # has more
51
- args.each do |src|
52
- method = "#{src}_gravatar_url".sub(/_e?mail/, '')
53
- define_method(method) do |*params|
54
- build_gravatar_url send(src), options.merge(params.first || {})
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,60 +0,0 @@
1
- require 'test_helper'
2
-
3
- class GravatarifyArDmTest < Test::Unit::TestCase
4
- def setup; reset_gravatarify! end
5
-
6
- context "ActiveRecord::Base" do
7
- if defined?(ActiveRecord)
8
- should "include Gravatarify::ObjectSupport" do
9
- assert ActiveRecord::Base.included_modules.include?(Gravatarify::ObjectSupport)
10
- end
11
-
12
- should "respond to #gravatarify" do
13
- assert_respond_to ActiveRecord::Base, :gravatarify
14
- end
15
- else
16
- context "tests" do
17
- should "be run (but looks like ActiveRecord is not available)" do
18
- flunk "ActiveRecord not available -> thus tests are incomplete (error can be ignored though!)"
19
- end
20
- end
21
- end
22
- end
23
-
24
- context "DataMapper model (User)" do
25
- if defined?(DataMapper)
26
- setup do
27
- class User
28
- include DataMapper::Resource
29
- property :id, Serial
30
- property :name, String
31
- property :email, String
32
- property :author_email, String
33
-
34
- gravatarify
35
- end
36
- end
37
-
38
- should "include Gravatarify::ObjectSupport" do
39
- assert User.included_modules.include?(Gravatarify::ObjectSupport)
40
- end
41
-
42
- should "respond to #gravatarify" do
43
- assert_respond_to User, :gravatarify
44
- end
45
-
46
- context "as instance" do
47
- should "be able to build correct gravatar_url's!" do
48
- u = User.new(:email => "peter.gibbons@initech.com")
49
- assert_equal "http://0.gravatar.com/avatar/cb7865556d41a3d800ae7dbb31d51d54.jpg", u.gravatar_url
50
- end
51
- end
52
- else
53
- context "tests" do
54
- should "be run (but looks like DataMapper is not available)" do
55
- flunk "DataMapper not available -> thus tests are incomplete (error can be ignored though!)"
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,107 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PoroUser
4
- include Gravatarify::ObjectSupport
5
- attr_accessor :email, :gender
6
- def initialize(attributes = {})
7
- attributes.each do |key, value|
8
- self.send "#{key}=", value
9
- end
10
- end
11
- end
12
-
13
- class GravatarifyObjectSupportTest < Test::Unit::TestCase
14
- def setup; reset_gravatarify! end
15
-
16
- context "#gravatarify" do
17
- should "add support for #gravatar_url to POROs (plain old ruby objects, yeah POJO sounds better!)" do
18
- poro = Class.new(PoroUser) { gravatarify }
19
- mike_shiva = poro.new(:email => 'mike@shiva.ch')
20
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg", mike_shiva.gravatar_url
21
- assert_equal "https://secure.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg", mike_shiva.gravatar_url(:secure => true)
22
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.gif?r=x&s=16", mike_shiva.gravatar_url(:filetype => :gif, :rating => :x, :size => 16)
23
- end
24
-
25
- should "allow some default options to be passed, which can be overriden locally, though" do
26
- poro = Class.new(PoroUser) { gravatarify :secure => true, :filetype => :gif }
27
- mike_shiva = poro.new(:email => 'mike@shiva.ch')
28
- assert_equal "https://secure.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.gif", mike_shiva.gravatar_url
29
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.gif", mike_shiva.gravatar_url(:secure => false)
30
- assert_equal "https://secure.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg?r=x&s=16", mike_shiva.gravatar_url(:filetype => :jpg, :rating => :x, :size => 16)
31
- end
32
-
33
- should "still respect options set by Gravatarify#options" do
34
- Gravatarify.options[:size] = 20
35
- poro = Class.new(PoroUser) { gravatarify }
36
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg?s=20", poro.new(:email => 'mike@shiva.ch').gravatar_url
37
- end
38
-
39
- should "be able to override options set by Gravatarify#options" do
40
- Gravatarify.options[:size] = 20
41
- poro = Class.new(PoroUser) { gravatarify :size => 25 }
42
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg?s=25", poro.new(:email => 'mike@shiva.ch').gravatar_url
43
- end
44
- end
45
-
46
- context "#gravatarify with custom fields" do
47
- should "detect and use the 'email' field automatically" do
48
- poro = Class.new(PoroUser) { gravatarify }
49
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg", poro.new(:email => 'mike@shiva.ch').gravatar_url
50
- end
51
-
52
- should "fallback to 'mail' if 'email' is not defined" do
53
- poro = Class.new(PoroUser) do
54
- gravatarify
55
- undef :email, :email=
56
- attr_accessor :mail
57
- end
58
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg", poro.new(:mail => 'mike@shiva.ch').gravatar_url
59
- end
60
-
61
- should "raise NoMethodError if object does not respond to source" do
62
- poro = Class.new do
63
- include Gravatarify::ObjectSupport
64
- gravatarify
65
- end
66
- assert_raise(NoMethodError) { poro.new.gravatar_url }
67
- end
68
-
69
- should "allow to set custom source, like author_email" do
70
- poro = Class.new(PoroUser) do
71
- gravatarify :author_email
72
- attr_accessor :author_email
73
- end
74
- assert_equal "http://0.gravatar.com/avatar/1b2818d77eadd6c9dbbe7f3beb1492c3.jpg", poro.new(:author_email => 'mike@shiva.ch').gravatar_url
75
- end
76
-
77
- should "allow multiple sources to be defined, yet still handle options!" do
78
- poro = Class.new(PoroUser) do
79
- gravatarify :email, :employee_email, :default => Proc.new { |*args| "http://initech.com/avatar-#{args.first[:size] || 80}.jpg" }
80
- attr_accessor :employee_email
81
- end
82
- peter_gibbons = poro.new(:email => 'info@initech.com', :employee_email => 'peter.gibbons@initech.com')
83
- assert_equal "http://2.gravatar.com/avatar/4979dd9653e759c78a81d4997f56bae2.jpg?d=http%3A%2F%2Finitech.com%2Favatar-20.jpg&s=20", peter_gibbons.gravatar_url(:size => 20)
84
- assert_equal "http://0.gravatar.com/avatar/cb7865556d41a3d800ae7dbb31d51d54.jpg?d=http%3A%2F%2Finitech.com%2Favatar-25.jpg&s=25", peter_gibbons.employee_gravatar_url(:size => 25)
85
- end
86
-
87
- should "use full prefix, if not suffixed by email" do
88
- poro = Class.new(PoroUser) do
89
- gravatarify :email, :employee_login
90
- attr_accessor :employee_login
91
- end
92
- peter_gibbons = poro.new(:email => 'peter.gibbons@initech.com', :employee_login => 'peter.gibbons@initech.com')
93
- assert_respond_to peter_gibbons, :employee_login_gravatar_url
94
- assert_equal "http://0.gravatar.com/avatar/cb7865556d41a3d800ae7dbb31d51d54.jpg?s=25", peter_gibbons.employee_login_gravatar_url(:size => 25)
95
- end
96
-
97
- should "pass in object as second parameter, not supplied string" do
98
- poro = Class.new(PoroUser) do
99
- gravatarify :default => Proc.new { |opts, obj| "http://initech.com/avatar#{obj.respond_to?(:gender) && obj.gender == :female ? '_girl' : ''}.jpg" }
100
- end
101
- peter_gibbons = poro.new(:email => 'peter.gibbons@initech.com', :gender => :male)
102
- jane = poro.new(:email => 'jane@initech.com', :gender => :female)
103
- assert_equal "http://0.gravatar.com/avatar/cb7865556d41a3d800ae7dbb31d51d54.jpg?d=http%3A%2F%2Finitech.com%2Favatar.jpg&s=25", peter_gibbons.gravatar_url(:s => 25)
104
- assert_equal "http://1.gravatar.com/avatar/9b78f3f45cf32d7c52d304a63f6aef06.jpg?d=http%3A%2F%2Finitech.com%2Favatar_girl.jpg&s=35", jane.gravatar_url(:s => 35)
105
- end
106
- end
107
- end