gravtastic 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -2
- data/Rakefile +74 -70
- data/lib/gravtastic.rb +53 -154
- data/spec/gravtastic_integration_spec.rb +22 -22
- data/spec/gravtastic_spec.rb +46 -189
- data/spec/spec_helper.rb +7 -1
- metadata +4 -2
data/README.textile
CHANGED
@@ -35,7 +35,7 @@ Now, you can access your object's gravatar with the @gravatar_url@ method:
|
|
35
35
|
|
36
36
|
Note that it defaults to a PG rating. You can specify extra options with a hash:
|
37
37
|
|
38
|
-
current_user.gravatar_url(:rating => '
|
38
|
+
current_user.gravatar_url(:rating => 'R', :size => 512)
|
39
39
|
=> "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512"
|
40
40
|
|
41
41
|
current_user.gravatar_url(:secure => true)
|
@@ -43,7 +43,7 @@ Note that it defaults to a PG rating. You can specify extra options with a hash:
|
|
43
43
|
|
44
44
|
However, to DRY things up you can specify defaults in the class declaration.
|
45
45
|
|
46
|
-
is_gravtastic :with => :author_email, :rating => '
|
46
|
+
is_gravtastic :with => :author_email, :rating => 'R', :size => 20
|
47
47
|
|
48
48
|
Nice, now all the calls to gravatar_url will have the defaults you have specified. Any options that you pass when you use @gravatar_url@ will over-ride these class-defaults.
|
49
49
|
|
@@ -69,6 +69,8 @@ h2. Thanks
|
|
69
69
|
|
70
70
|
* "Xavier Shay":http://rhnh.net and others for "Enki":http://enkiblog.com (the reason this was written)
|
71
71
|
* "Matthew Moore":http://www.matthewpaulmoore.com/ for helpful suggestions and for submitting it to the official list of Gravatar implementations.
|
72
|
+
* "Vincent Charles":http://vincentcharles.com/ For an updated README.
|
73
|
+
|
72
74
|
|
73
75
|
|
74
76
|
h2. License
|
data/Rakefile
CHANGED
@@ -1,72 +1,76 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake/gempackagetask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
require 'rubygems/specification'
|
5
|
-
require 'spec/rake/spectask'
|
6
|
-
require 'date'
|
1
|
+
require 'mg'
|
7
2
|
|
8
|
-
|
9
|
-
GEM_VERSION = "2.0.0"
|
10
|
-
AUTHOR = "Chris Lloyd"
|
11
|
-
EMAIL = "christopher.lloyd@gmail.com"
|
12
|
-
HOMEPAGE = "http://github.com/chrislloyd/gravtastic"
|
13
|
-
SUMMARY = "Easily add Gravatars to your Ruby objects."
|
3
|
+
MG.new('gravtastic.gemspec')
|
14
4
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
5
|
+
# require 'rubygems'
|
6
|
+
# require 'rake/gempackagetask'
|
7
|
+
# require 'rake/rdoctask'
|
8
|
+
# require 'rubygems/specification'
|
9
|
+
# require 'spec/rake/spectask'
|
10
|
+
# require 'date'
|
11
|
+
#
|
12
|
+
# GEM = "gravtastic"
|
13
|
+
# GEM_VERSION = "2.0.0"
|
14
|
+
# AUTHOR = "Chris Lloyd"
|
15
|
+
# EMAIL = "christopher.lloyd@gmail.com"
|
16
|
+
# HOMEPAGE = "http://github.com/chrislloyd/gravtastic"
|
17
|
+
# SUMMARY = "Easily add Gravatars to your Ruby objects."
|
18
|
+
#
|
19
|
+
# spec = Gem::Specification.new do |s|
|
20
|
+
# s.name = GEM
|
21
|
+
# s.version = GEM_VERSION
|
22
|
+
# s.platform = Gem::Platform::RUBY
|
23
|
+
# s.rubyforge_project = GEM
|
24
|
+
# s.has_rdoc = true
|
25
|
+
# s.extra_rdoc_files = ['README.textile', 'LICENSE']
|
26
|
+
# s.summary = SUMMARY
|
27
|
+
# s.description = s.summary
|
28
|
+
# s.author = AUTHOR
|
29
|
+
# s.email = EMAIL
|
30
|
+
# s.homepage = HOMEPAGE
|
31
|
+
#
|
32
|
+
# # Uncomment this to add a dependency
|
33
|
+
# # s.add_dependency "foo"
|
34
|
+
#
|
35
|
+
# s.require_path = 'lib'
|
36
|
+
# s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# desc "Run Specs"
|
40
|
+
# Rake::GemPackageTask.new(spec) do |pkg|
|
41
|
+
# pkg.gem_spec = spec
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# desc "Generate Documentation"
|
45
|
+
# Rake::RDocTask.new do |rdoc|
|
46
|
+
# rdoc.rdoc_dir = 'doc'
|
47
|
+
# rdoc.title = 'Gravtastic'
|
48
|
+
# rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'Gravtastic'
|
49
|
+
# rdoc.rdoc_files.include(FileList[ 'lib/**/*.rb', 'README.textile', 'LICENSE'])
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# task :default => :spec
|
53
|
+
# task :specs => :spec
|
54
|
+
#
|
55
|
+
# desc "Run all examples"
|
56
|
+
# Spec::Rake::SpecTask.new('spec') do |t|
|
57
|
+
# t.spec_opts = ['--options','spec/spec.opts']
|
58
|
+
# t.spec_files = FileList['spec/**/*.rb']
|
59
|
+
# # t.rcov = true
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# desc "install the gem locally"
|
63
|
+
# task :install => [:package] do
|
64
|
+
# sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# desc "create a gemspec file"
|
68
|
+
# task :make_spec do
|
69
|
+
# File.open("#{GEM}.gemspec", "w") do |file|
|
70
|
+
# file.puts spec.to_ruby
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# task :bugs do
|
75
|
+
# sh %{ditz html ; open html/index.html}
|
76
|
+
# end
|
data/lib/gravtastic.rb
CHANGED
@@ -3,180 +3,79 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
|
4
4
|
require 'digest/md5'
|
5
5
|
require 'cgi'
|
6
|
+
require 'uri'
|
6
7
|
|
7
|
-
# = Gravtastic - Easily add Gravatars to your Ruby objects.
|
8
|
-
#
|
9
|
-
# Copyright (C) 2008 mailto:christopher.lloyd@gmail.com
|
10
|
-
#
|
11
|
-
# == Example
|
12
|
-
#
|
13
|
-
# Somewhere in your application you need to <tt>require 'gravtastic'</tt>. In Rails >= 2.1 you can forego this and just add a dependency gem dependency for Gravtastic.
|
14
|
-
#
|
15
|
-
# config.gem 'gravtastic'
|
16
|
-
#
|
17
|
-
# If you are using Merb & DataMapper you can add do the same by adding the following to your init.rb file:
|
18
|
-
#
|
19
|
-
# dependency 'gravtastic'
|
20
|
-
#
|
21
|
-
# Make sure you add this after either the <tt>use_orm :datamapper</tt> line or after a DataMapper extension. The next step is to give your model a Gravatar:
|
22
|
-
#
|
23
|
-
# class User
|
24
|
-
# is_gravtastic
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# If you are using a standard Ruby class you have to add the line <tt>include Gravtastic::Resource</tt> before <tt>is_gravtastic</tt>.
|
28
|
-
#
|
29
|
-
# This defaults to looking for the gravatar ID on the <tt>email</tt> method. So, if your <tt>User</tt> has an <tt>email</tt> then it will send that to Gravatar to get their picture. You can change the default gravatar source like this:
|
30
|
-
#
|
31
|
-
# is_gravtastic :with => :author_email
|
32
|
-
#
|
33
|
-
# Now, you can access your object's gravatar with the <tt>gravatar_url</tt> method:
|
34
|
-
#
|
35
|
-
# current_user.gravatar_url
|
36
|
-
# => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
|
37
|
-
#
|
38
|
-
# Note that it defaults to a PG rating. You can specify extra options with a hash:
|
39
|
-
#
|
40
|
-
# current_user.gravatar_url(:rating => 'R18', :size => 512)
|
41
|
-
# => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512"
|
42
|
-
#
|
43
|
-
# current_user.gravatar_url(:secure => true)
|
44
|
-
# => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
|
45
|
-
#
|
46
|
-
# However, to DRY things up you can specify defaults in the class declaration.
|
47
|
-
#
|
48
|
-
# is_gravtastic :with => :author_email, :rating => 'R18', :size => 20
|
49
|
-
#
|
50
|
-
# Nice, now all the calls to gravatar_url will have the defaults you have specified. Any options that you pass when you use <tt>gravatar_url</tt> will over-ride these class-defaults.
|
51
|
-
#
|
52
8
|
module Gravtastic
|
53
|
-
module Resource
|
54
9
|
|
55
|
-
|
56
|
-
|
10
|
+
def self.included(base)
|
11
|
+
base.extend(SingletonMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
module SingletonMethods
|
15
|
+
|
16
|
+
def is_gravtastic(source = :email, options={})
|
17
|
+
extend ClassMethods
|
18
|
+
include InstanceMethods
|
19
|
+
|
20
|
+
@gravatar_defaults = {
|
21
|
+
:rating => 'PG',
|
22
|
+
:secure => false,
|
23
|
+
:filetype => :png
|
24
|
+
}.merge(options)
|
25
|
+
@gravatar_source = source
|
26
|
+
end
|
27
|
+
|
28
|
+
alias :has_gravatar :is_gravtastic
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
|
34
|
+
# attr_reader :gravatar_source, :gravatar_defaults
|
35
|
+
|
36
|
+
def gravatar_source
|
37
|
+
@gravatar_source
|
57
38
|
end
|
58
|
-
|
59
|
-
module ClassMethods
|
60
|
-
|
61
|
-
#
|
62
|
-
# Sets the gravatar_source. Basically starts this whole shindig.
|
63
|
-
#
|
64
|
-
# Examples:
|
65
|
-
#
|
66
|
-
# is_gravtastic
|
67
|
-
#
|
68
|
-
# is_gravtastic :with => :author_email
|
69
|
-
#
|
70
|
-
# is_gravtastic :with => :author_email, :rating => 'R18', :secure => true
|
71
|
-
#
|
72
|
-
def is_gravtastic(options={})
|
73
|
-
@gravatar_source = options[:with] || :email
|
74
|
-
|
75
|
-
options.delete_if {|key,_| ![:size, :rating, :default, :secure].include?(key) }
|
76
|
-
@gravatar_defaults = {:rating => 'PG', :secure => false}.merge(options)
|
77
|
-
end
|
78
|
-
|
79
|
-
alias :has_gravatar :is_gravtastic
|
80
|
-
|
81
|
-
#
|
82
|
-
# Returns a symbol of the instance method where the Gravatar is pulled from.
|
83
|
-
#
|
84
|
-
# For example, if your users email is returned by the method <tt>#gobagaldy_gook</tt> then it
|
85
|
-
# will return the symbol <tt>:gobagaldy_gook</tt>.
|
86
|
-
#
|
87
|
-
def gravatar_source
|
88
|
-
@gravatar_source
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# Returns a hash of all the default gravtastic options.
|
93
|
-
#
|
94
|
-
def gravatar_defaults
|
95
|
-
@gravatar_defaults
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# Returns <tt>true</tt> if the gravatar_source is set. <tt>false</tt> if not. Easy!
|
100
|
-
#
|
101
|
-
def has_gravatar?
|
102
|
-
!!gravatar_source
|
103
|
-
end
|
104
39
|
|
40
|
+
def gravatar_defaults
|
41
|
+
@gravatar_defaults
|
105
42
|
end
|
106
43
|
|
107
|
-
|
108
|
-
|
109
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
module InstanceMethods
|
47
|
+
|
110
48
|
def gravatar_id
|
111
|
-
|
112
|
-
@gravatar_id = Digest::MD5.hexdigest(value.to_s.downcase)
|
113
|
-
end
|
49
|
+
Digest::MD5.hexdigest(send(self.class.gravatar_source).to_s.downcase)
|
114
50
|
end
|
115
51
|
|
116
|
-
|
117
|
-
# Returns a string with the URL for the instance's Gravatar.
|
118
|
-
#
|
119
|
-
# It defaults to <tt>:rating => 'PG'</tt> and <tt>:secure => false</tt>
|
120
|
-
#
|
121
|
-
# Examples:
|
122
|
-
#
|
123
|
-
# current_user.gravatar_url
|
124
|
-
# => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
|
125
|
-
#
|
126
|
-
# current_user.gravatar_url(:rating => 'R18', :size => 512, :default => 'http://example.com/images/example.jpg')
|
127
|
-
# => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?d=http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg&r=R18&s=512"
|
128
|
-
#
|
129
|
-
# current_user.gravatar_url(:secure => true)
|
130
|
-
# => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
|
131
|
-
#
|
132
|
-
def gravatar_url(options={})
|
52
|
+
def gravatar_url(options={})
|
133
53
|
options = self.class.gravatar_defaults.merge(options)
|
134
|
-
|
135
|
-
|
54
|
+
gravatar_hostname(options.delete(:secure)) +
|
55
|
+
gravatar_filename(options.delete(:filetype)) +
|
56
|
+
url_params_from_hash(options)
|
136
57
|
end
|
137
58
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
unless options.empty?
|
147
|
-
'?' + options.map do |pair|
|
148
|
-
pair[0] = pair[0].to_s[0,1] # Get the first character of the option
|
149
|
-
pair.map{|item| item = CGI::escape(item.to_s) }.join('=') # Join key & value together
|
150
|
-
end.sort.join('&') # Join options together
|
151
|
-
else
|
152
|
-
''
|
153
|
-
end
|
59
|
+
private
|
60
|
+
|
61
|
+
def url_params_from_hash(hash)
|
62
|
+
'?' + hash.map do |pair|
|
63
|
+
pair[0] = pair[0].to_s[0,1]
|
64
|
+
pair.map{|item| item = CGI::escape(item.to_s) }.join('=')
|
65
|
+
end.sort.join('&')
|
154
66
|
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Returns the Gravatar.com hostname
|
158
|
-
#
|
67
|
+
|
159
68
|
def gravatar_hostname(secure)
|
160
69
|
'http' + (secure ? 's://secure.' : '://') + 'gravatar.com/avatar/'
|
161
70
|
end
|
162
71
|
|
163
|
-
|
164
|
-
|
165
|
-
#
|
166
|
-
def gravatar_filename
|
167
|
-
if gravatar_id
|
168
|
-
gravatar_id + '.png'
|
169
|
-
else
|
170
|
-
''
|
171
|
-
end
|
72
|
+
def gravatar_filename(filetype)
|
73
|
+
"#{gravatar_id}.#{filetype}"
|
172
74
|
end
|
173
75
|
|
174
76
|
end
|
175
|
-
end
|
176
77
|
|
177
|
-
|
78
|
+
end
|
178
79
|
|
179
|
-
if defined?(
|
180
|
-
|
181
|
-
DataMapper::Model.append_extensions Gravtastic::Resource::ClassMethods
|
182
|
-
end
|
80
|
+
ActiveRecord::Base.send(:include, Gravtastic) if defined?(ActiveRecord) # :nodoc:
|
81
|
+
DataMapper::Resource.append_inclusions(Gravtastic) if defined?(DataMapper) # :nodoc:
|
@@ -2,37 +2,37 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
require 'rubygems'
|
3
3
|
|
4
4
|
require 'activerecord'
|
5
|
-
require 'dm-core'
|
5
|
+
# require 'dm-core'
|
6
|
+
require 'gravtastic'
|
6
7
|
|
7
|
-
reload_gravtastic!
|
8
8
|
|
9
|
-
class User
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
# class User
|
10
|
+
# include DataMapper::Resource
|
11
|
+
# is_gravtastic
|
12
|
+
# end
|
13
13
|
|
14
14
|
describe ActiveRecord::Base do
|
15
|
-
|
16
|
-
it "includes Gravtastic
|
17
|
-
ActiveRecord::Base.included_modules.should include(Gravtastic
|
15
|
+
|
16
|
+
it "includes Gravtastic" do
|
17
|
+
ActiveRecord::Base.included_modules.should include(Gravtastic)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "responds to .is_gravtastic" do
|
21
21
|
ActiveRecord::Base.should respond_to(:is_gravtastic)
|
22
22
|
end
|
23
|
-
|
24
|
-
end
|
25
23
|
|
26
|
-
describe DataMapper::Resource do
|
27
|
-
|
28
|
-
it "includes Gravtastic::Resource" do
|
29
|
-
User.included_modules.should include(Gravtastic::Resource)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "responds to .is_gravtastic" do
|
33
|
-
User.should respond_to(:is_gravtastic)
|
34
|
-
end
|
35
|
-
|
36
24
|
end
|
37
25
|
|
26
|
+
# describe DataMapper::Resource do
|
27
|
+
#
|
28
|
+
# it "includes Gravtastic::Resource" do
|
29
|
+
# User.included_modules.should include(Gravtastic)
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# it "responds to .is_gravtastic" do
|
33
|
+
# User.should respond_to(:is_gravtastic)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# end
|
37
|
+
|
38
38
|
|
data/spec/gravtastic_spec.rb
CHANGED
@@ -1,218 +1,75 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'gravtastic'
|
2
3
|
|
3
|
-
describe Gravtastic
|
4
|
+
describe Gravtastic do
|
4
5
|
|
5
6
|
before(:each) do
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
describe ".gravatar_source" do
|
12
|
-
|
13
|
-
it "is nil if unset" do
|
14
|
-
@klass.gravatar_source.should be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns the value of @gravatar_source" do
|
18
|
-
@klass.instance_variable_set('@gravatar_source', :foo)
|
19
|
-
@klass.gravatar_source.should == :foo
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".gravatar_defaults" do
|
25
|
-
|
26
|
-
it "it nil if unset" do
|
27
|
-
@klass.gravatar_defaults.should be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns the value of @gravatar_defaults" do
|
31
|
-
@klass.instance_variable_set('@gravatar_defaults', :foo)
|
32
|
-
@klass.gravatar_source.should == :foo
|
7
|
+
@g = Class.new do |c|
|
8
|
+
c.send(:include, Gravtastic)
|
9
|
+
c.is_gravtastic
|
33
10
|
end
|
34
|
-
|
35
11
|
end
|
36
|
-
|
12
|
+
|
37
13
|
describe ".is_gravtastic" do
|
38
|
-
|
39
|
-
it "
|
40
|
-
@
|
41
|
-
@klass.gravatar_source.should == :email
|
42
|
-
end
|
43
|
-
|
44
|
-
it "sets .gravatar_defaults to { :rating => 'PG', :secure => false } by default" do
|
45
|
-
@klass.is_gravtastic
|
46
|
-
@klass.gravatar_defaults.should == { :rating => 'PG', :secure => false }
|
47
|
-
end
|
48
|
-
|
49
|
-
it "sets .gravatar_source to :email by default, even when defaults are supplied" do
|
50
|
-
@klass.is_gravtastic :secure => true
|
51
|
-
@klass.gravatar_source.should == :email
|
52
|
-
end
|
53
|
-
|
54
|
-
it "keeps either :rating or :secure if only the other is passed as a default" do
|
55
|
-
@klass.is_gravtastic :secure => true
|
56
|
-
@klass.gravatar_defaults.should == { :rating => 'PG', :secure => true }
|
57
|
-
end
|
58
|
-
|
59
|
-
it "changes .gravatar_source" do
|
60
|
-
lambda {
|
61
|
-
@klass.is_gravtastic :with => :other_method
|
62
|
-
}.should change(@klass, :gravatar_source)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "changes .gravatar_defaults" do
|
66
|
-
lambda {
|
67
|
-
@klass.is_gravtastic :rating => 'R18'
|
68
|
-
}.should change(@klass, :gravatar_defaults)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sets .gravatar_source to the value of :on" do
|
72
|
-
@klass.is_gravtastic :with => :other_method
|
73
|
-
@klass.gravatar_source.should == :other_method
|
74
|
-
end
|
75
|
-
|
76
|
-
it "sets .gravatar_defaults to the value of :defaults" do
|
77
|
-
@klass.is_gravtastic :rating => 'R18'
|
78
|
-
@klass.gravatar_defaults.should == { :rating => 'R18', :secure => false }
|
14
|
+
|
15
|
+
it "includes the methods" do
|
16
|
+
@g.included_modules.should include(Gravtastic::InstanceMethods)
|
79
17
|
end
|
80
|
-
|
18
|
+
|
81
19
|
end
|
82
20
|
|
83
|
-
describe
|
84
|
-
|
85
|
-
it "
|
86
|
-
@
|
87
|
-
@user.class.should have_gravatar
|
21
|
+
describe 'default' do
|
22
|
+
|
23
|
+
it "options are {:rating => 'PG', :secure => false, :filetype => :png}" do
|
24
|
+
@g.gravatar_defaults.should == {:rating => 'PG', :secure => false, :filetype => :png}
|
88
25
|
end
|
89
|
-
|
90
|
-
it "
|
91
|
-
@
|
92
|
-
@user.class.should_not have_gravatar
|
26
|
+
|
27
|
+
it "source is :email" do
|
28
|
+
@g.gravatar_source.should == :email
|
93
29
|
end
|
94
|
-
|
30
|
+
|
95
31
|
end
|
96
32
|
|
97
33
|
describe "#gravatar_id" do
|
98
34
|
|
99
|
-
|
100
|
-
@
|
101
|
-
|
102
|
-
@
|
103
|
-
|
104
|
-
|
105
|
-
it "is not nil when .gravatar_source is not nil" do
|
106
|
-
@user.gravatar_id.should_not be_nil
|
107
|
-
end
|
108
|
-
|
109
|
-
it "is nil when .gravatar_source is nil" do
|
110
|
-
@user.class.stub!(:gravatar_source).and_return(nil)
|
111
|
-
@user.gravatar_id.should be_nil
|
35
|
+
it "downcases email" do
|
36
|
+
a = @g.new
|
37
|
+
stub(a).email{ 'USER@EXAMPLE.COM' }
|
38
|
+
b = @g.new
|
39
|
+
stub(b).email{ 'user@example.com' }
|
40
|
+
a.gravatar_id.should == b.gravatar_id
|
112
41
|
end
|
113
42
|
|
114
|
-
it "changes when .gravatar_source is changed" do
|
115
|
-
lambda {
|
116
|
-
@user.class.stub!(:gravatar_source).and_return(:name)
|
117
|
-
}.should change(@user, :gravatar_id)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "is a MD5 hash" do
|
121
|
-
@user.gravatar_id.should == 'f5b8fb60c6116331da07c65b96a8a1d1'
|
122
|
-
end
|
123
|
-
|
124
|
-
it "downcases any imput" do
|
125
|
-
@user.stub!(:email).and_return('JOE@EXAMPLE.COM')
|
126
|
-
@user.gravatar_id.should == 'f5b8fb60c6116331da07c65b96a8a1d1'
|
127
|
-
end
|
128
|
-
|
129
|
-
it "is nil when email is not a string" do
|
130
|
-
@user.stub!(:email).and_return(nil)
|
131
|
-
@user.gravatar_id.should == nil
|
132
|
-
end
|
133
|
-
|
134
43
|
end
|
135
|
-
|
44
|
+
|
136
45
|
describe "#gravatar_url" do
|
137
|
-
|
46
|
+
|
138
47
|
before(:each) do
|
139
|
-
@user
|
140
|
-
@user
|
141
|
-
@user.class.stub!(:gravatar_source).and_return(:email)
|
142
|
-
@user.class.stub!(:gravatar_defaults).and_return({:rating => 'PG'})
|
143
|
-
end
|
144
|
-
|
145
|
-
it "is not nil when .gravatar_source is not nil" do
|
146
|
-
@user.gravatar_url.should_not be_nil
|
147
|
-
end
|
148
|
-
|
149
|
-
it "returns a default Gravatar url when .gravatar_source is nil" do
|
150
|
-
@user.class.stub!(:gravatar_source).and_return(nil)
|
151
|
-
@user.gravatar_url.should =~ /http:\/\/gravatar.com\/avatar/
|
152
|
-
end
|
153
|
-
|
154
|
-
it "always specifies a png resource type" do
|
155
|
-
@user.gravatar_url.should match(/.png/)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "returns a valid gravatar URL" do
|
159
|
-
@user.gravatar_url.should == valid_gravatar_url + '?r=PG'
|
160
|
-
end
|
161
|
-
|
162
|
-
it "returns a valid SSL gravatar URL" do
|
163
|
-
@user.gravatar_url(:secure => true).should == 'https://secure.gravatar.com/avatar/f5b8fb60c6116331da07c65b96a8a1d1.png?r=PG'
|
164
|
-
end
|
165
|
-
|
166
|
-
it "returns a url without the 'www'" do
|
167
|
-
@user.gravatar_url.should_not match(/www/)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "returns a valid gravatar URL even when invalid option is passed" do
|
171
|
-
@user.gravatar_url(:foo => :bar).should == valid_gravatar_url + '?r=PG'
|
172
|
-
end
|
173
|
-
|
174
|
-
it "parses a size" do
|
175
|
-
@user.gravatar_url(:size => 512).should == valid_gravatar_url + '?r=PG&s=512'
|
48
|
+
@user = @g.new
|
49
|
+
stub(@user).email{ 'user@example.com' }
|
176
50
|
end
|
177
|
-
|
178
|
-
it "
|
179
|
-
@user.gravatar_url
|
180
|
-
end
|
181
|
-
|
182
|
-
it "returns a valid gravatar URL when the rating option is unescaped" do
|
183
|
-
@user.gravatar_url(:rating => 'Unescaped String').should == valid_gravatar_url + '?r=Unescaped+String'
|
184
|
-
end
|
185
|
-
|
186
|
-
it "parses a default image type" do
|
187
|
-
@user.gravatar_url(:default => :identicon).should == valid_gravatar_url + '?d=identicon&r=PG'
|
188
|
-
end
|
189
|
-
|
190
|
-
it "parses a default image URL" do
|
191
|
-
@user.gravatar_url(:default => 'http://example.com/images/example.jpg').should == valid_gravatar_url + '?d=http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg&r=PG'
|
192
|
-
end
|
193
|
-
|
194
|
-
it "parses multiple options" do
|
195
|
-
@user.gravatar_url(:size => 20, :rating => 'R18', :default => :monsterid).should == valid_gravatar_url + '?d=monsterid&r=R18&s=20'
|
51
|
+
|
52
|
+
it "makes a pretty URL" do
|
53
|
+
@user.gravatar_url.should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
|
196
54
|
end
|
197
|
-
|
198
|
-
it "
|
199
|
-
@user.gravatar_url(:
|
55
|
+
|
56
|
+
it "makes a secure URL" do
|
57
|
+
@user.gravatar_url(:secure => true).should == 'https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
|
200
58
|
end
|
201
|
-
|
202
|
-
it "
|
203
|
-
@user.
|
204
|
-
@user.gravatar_url.should == valid_gravatar_url + '?r=R18&s=20'
|
59
|
+
|
60
|
+
it "makes a jpeggy URL" do
|
61
|
+
@user.gravatar_url(:filetype => :jpg).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?r=PG'
|
205
62
|
end
|
206
|
-
|
207
|
-
it "
|
208
|
-
@user.
|
209
|
-
@user.gravatar_url.should =~ /http:\/\/gravatar.com\/avatar/
|
63
|
+
|
64
|
+
it "makes a saucy URL" do
|
65
|
+
@user.gravatar_url(:rating => 'R').should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R'
|
210
66
|
end
|
211
|
-
|
212
|
-
|
213
|
-
|
67
|
+
|
68
|
+
it "makes a URL from the defaults" do
|
69
|
+
stub(@user.class).gravatar_defaults{ {:size => 20, :rating => 'R18', :secure => true, :filetype => :png} }
|
70
|
+
@user.gravatar_url.should == 'https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R18&s=20'
|
214
71
|
end
|
215
|
-
|
72
|
+
|
216
73
|
end
|
217
|
-
|
74
|
+
|
218
75
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Lloyd
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- spec/spec_helper.rb
|
34
34
|
has_rdoc: true
|
35
35
|
homepage: http://github.com/chrislloyd/gravtastic
|
36
|
+
licenses: []
|
37
|
+
|
36
38
|
post_install_message:
|
37
39
|
rdoc_options: []
|
38
40
|
|
@@ -53,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
55
|
requirements: []
|
54
56
|
|
55
57
|
rubyforge_project: gravtastic
|
56
|
-
rubygems_version: 1.2
|
58
|
+
rubygems_version: 1.3.2
|
57
59
|
signing_key:
|
58
60
|
specification_version: 2
|
59
61
|
summary: Easily add Gravatars to your Ruby objects.
|