img_gravatar 0.1.1 → 0.2.0

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.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .idea/*
2
+ coverage/*
3
+ pkg/*
4
+ doc/*
5
+ rdoc/*
6
+ Manifest
7
+ img_gravatar-*.gem
data/README.rdoc CHANGED
@@ -4,7 +4,11 @@ A simple plugin adding the +img_gravatar+ image link helper to ActionViews.
4
4
 
5
5
  == Install
6
6
 
7
- gem install tsalzer-img_gravatar --source http://gems.github.com
7
+ The gem is hosted on http://gemcutter.org, which is the default Ruby gem
8
+ hoster at this time (November 2009). All you need to install the latest
9
+ version is run the following command:
10
+
11
+ gem install img_gravatar
8
12
 
9
13
 
10
14
  == What is a Gravatar?
@@ -13,8 +17,9 @@ A gravatar is a globally recognized avatar. It is an image hosted on the site
13
17
  http://site.gravatar.com, uploaded by the user and referred to on base of
14
18
  an eMail address. News on gravatar can be found at http://blog.gravatar.com.
15
19
 
16
- Each gravatar image can be rated with respect to its content being suiteable to
17
- audience.
20
+ Each gravatar image can be rated with respect to its content being suitable
21
+ for a given audience. You might want to use the rating feature if you run a
22
+ public site.
18
23
 
19
24
  == Usage
20
25
 
@@ -38,7 +43,7 @@ A more complex szenario would include a size definition, and an alt image tag:
38
43
  This would render a downsized image of 40x40 with the alt-tag "That's me.".
39
44
 
40
45
  For a complete description of available parameters see
41
- Gravatar::InstanceMethods#gravatar in the Gravatar::InstanceMethods.
46
+ ImgGravatar::InstanceMethods#gravatar in the ImgGravatar::InstanceMethods.
42
47
 
43
48
  === Configuration Options
44
49
 
@@ -50,7 +55,7 @@ You can modify the following aspects of the displayed gravatar image:
50
55
 
51
56
  == Building a new Gem
52
57
 
53
- To create a new gem, you need to install the echoe gem (see
58
+ To create a new gem, you need to install the jeweler gem (see
54
59
  http://blog.evanweaver.com/files/doc/fauna/echoe/files/README.html).
55
60
  Next, edit the Rakefile to reflect your changes, then run:
56
61
 
@@ -61,6 +66,11 @@ Next, edit the Rakefile to reflect your changes, then run:
61
66
  Now, you can either publish the gem, or build a gem package. See rake -T for
62
67
  available targets.
63
68
 
69
+ == Ruby 1.9
70
+
71
+ ImgGravatar version 0.2.0 and above runs on Ruby 1.9; older version will work
72
+ only on Ruby 1.8.
73
+
64
74
  == License
65
75
 
66
76
  The img_gravatar gem comes to you under the MIT License. You should find the
data/Rakefile CHANGED
@@ -1,16 +1,53 @@
1
- # Rakefile for img_gravatar
2
1
  require 'rubygems'
3
2
  require 'rake'
4
- require 'echoe'
5
-
6
- Echoe.new('img_gravatar', '0.1.1') do |p|
7
- p.description = "Add a img_gravatar helper to ActiveView."
8
- p.url = "http://github.com/tsalzer/img_gravatar"
9
- p.author = "Till Salzer"
10
- p.email = "till.salzer@googlemail.com"
11
- p.ignore_pattern = ["tmp/*", "script/*", "rdoc/*", "pkg/*", "gravatar.tmproj"]
12
- p.development_dependencies = []
13
- p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README.rdoc|^CHANGELOG|^TODO|^MIT-LICENSE|^COPYING$/
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "img_gravatar"
8
+ gem.summary = %Q{Gravatar image helper}
9
+ gem.description = %Q{Add a img_gravatar helper to ActiveView.}
10
+ gem.email = "till.salzer@googlemail.com"
11
+ gem.homepage = "http://github.com/tsalzer/minimapper"
12
+ gem.authors = ["Till Salzer", "Jon Wood"]
13
+ gem.add_development_dependency 'rspec', '>= 1.2.9'
14
+ gem.add_development_dependency 'rcov', '>= 0.9.6'
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ if File.exist?('VERSION.yml')
41
+ config = YAML.load(File.read('VERSION.yml'))
42
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
43
+ else
44
+ version = ""
45
+ end
46
+
47
+ rdoc.rdoc_dir = 'doc'
48
+ rdoc.title = "img_gravatar #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('MIT-LICENSE')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
52
  end
15
53
 
16
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :minor: 2
3
+ :build:
4
+ :patch: 0
5
+ :major: 0
data/img_gravatar.gemspec CHANGED
@@ -1,32 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{img_gravatar}
5
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
6
9
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Till Salzer"]
9
- s.date = %q{2009-02-18}
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Till Salzer", "Jon Wood"]
12
+ s.date = %q{2009-11-26}
10
13
  s.description = %q{Add a img_gravatar helper to ActiveView.}
11
14
  s.email = %q{till.salzer@googlemail.com}
12
- s.extra_rdoc_files = ["lib/img_gravatar.rb", "MIT-LICENSE", "README.rdoc", "tasks/img_gravatar_tasks.rake"]
13
- s.files = ["img_gravatar.gemspec", "init.rb", "install.rb", "lib/img_gravatar.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "tasks/img_gravatar_tasks.rake", "test/img_gravatar_test.rb", "test/module_gravatar_test.rb", "uninstall.rb"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://github.com/tsalzer/img_gravatar}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Img_gravatar", "--main", "README.rdoc"]
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "img_gravatar.gemspec",
25
+ "init.rb",
26
+ "install.rb",
27
+ "lib/img_gravatar.rb",
28
+ "spec/img_gravatar_spec.rb",
29
+ "spec/module_gravatar_spec.rb",
30
+ "spec/spec_helper.rb",
31
+ "tasks/img_gravatar_tasks.rake",
32
+ "uninstall.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/tsalzer/minimapper}
35
+ s.rdoc_options = ["--charset=UTF-8"]
17
36
  s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{img_gravatar}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{Add a img_gravatar helper to ActiveView.}
21
- s.test_files = ["test/img_gravatar_test.rb", "test/module_gravatar_test.rb"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Gravatar image helper}
39
+ s.test_files = [
40
+ "spec/img_gravatar_spec.rb",
41
+ "spec/module_gravatar_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
22
44
 
23
45
  if s.respond_to? :specification_version then
24
46
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
47
+ s.specification_version = 3
26
48
 
27
49
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0.9.6"])
28
52
  else
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<rcov>, [">= 0.9.6"])
29
55
  end
30
56
  else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<rcov>, [">= 0.9.6"])
31
59
  end
32
60
  end
61
+
data/lib/img_gravatar.rb CHANGED
@@ -1,13 +1,18 @@
1
- require 'md5'
1
+ DIGEST_INTERFACE = begin
2
+ require 'md5'
3
+ :ruby18
4
+ rescue LoadError
5
+ require 'digest/md5'
6
+ :ruby19
7
+ end
8
+
2
9
  require 'uri'
3
10
  require 'action_view'
4
11
 
5
- # = Gravatar
12
+ # = ImgGravatar
6
13
  #
7
14
  # Adds the +gravatar+ method to ActionViews.
8
- #
9
- # $Id$
10
- module ImgGravatar #:nodoc:
15
+ module ImgGravatar
11
16
  mattr_reader :gravatar_host
12
17
  @@gravatar_host = 'www.gravatar.com'
13
18
  # gravatar.com base URL.
@@ -36,22 +41,24 @@ module ImgGravatar #:nodoc:
36
41
  ############################################################################
37
42
  # get the Gravatar image.
38
43
  # options:
39
- # :alt - the alternative text for this image
44
+ # :alt - the alternative text for this image (img attribute)
40
45
  # :default_url - the default URL for this gravatar
41
- # :size - the requested gravatar size
46
+ # :size - the requested gravatar size (img attribute, gravatar-attribute)
42
47
  # :rating - the requested maximum rating
43
48
  def self.link_gravatar(email, opts={})
44
49
  # the defaults
45
- alt = nil
46
- alt = opts[:alt] if opts[:alt]
47
-
48
- if alt then
49
- "<img src=\"%s\" alt=\"%s\" />" % [image_url(email, opts), alt]
50
+ tag_options = {}
51
+ tag_options[:alt] =opts[:alt] if opts[:alt]
52
+ tag_options[:size] =opts[:size] if opts[:size] && (opts[:size] >= 1 && opts[:size] <= 512)
53
+
54
+ unless tag_options.empty?
55
+ attributes = tag_options.collect {|key, value| "#{key}=\"#{value}\"" }.join(" ")
56
+ "<img src=\"%s\" %s />" % [image_url(email, opts), attributes]
50
57
  else
51
58
  "<img src=\"%s\" />" % image_url(email, opts)
52
59
  end
53
60
  end
54
-
61
+
55
62
  ############################################################################
56
63
  # get the default Gravatar image.
57
64
  # options:
@@ -75,10 +82,25 @@ module ImgGravatar #:nodoc:
75
82
 
76
83
  #uri = URI::HTTP.new(Gravatar.gravatar_base_url)
77
84
  uri = URI::HTTP.build(:host => ImgGravatar.gravatar_host,
78
- :path => "/avatar/%s" % MD5.md5(email.downcase.strip),
85
+ :path => "/avatar/%s" % encode_md5(email),
79
86
  :query => query)
80
87
  end
81
-
88
+
89
+ # encode an EMail for Gravatar.
90
+ # This will basically take any string, strip is, and hash the result
91
+ # using MD5.
92
+ def self.encode_md5(email)
93
+ value = email.downcase.strip
94
+ case DIGEST_INTERFACE
95
+ when :ruby18
96
+ return MD5.md5(value)
97
+ when :ruby19
98
+ return Digest::MD5.hexdigest(value)
99
+ else
100
+ raise "unknown Ruby Digest interface."
101
+ end
102
+ end
103
+
82
104
  # Methods injected in all ActionView classes.
83
105
  module Base #:nodoc:
84
106
  def self.included(mod) #:nodoc:
@@ -94,7 +116,8 @@ module ImgGravatar #:nodoc:
94
116
  end
95
117
  end
96
118
  end
97
-
119
+
120
+ # Methods available in ActionView.
98
121
  module InstanceMethods
99
122
  ############################################################################
100
123
  # get the Gravatar image.
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ImgGravatar, "ActionView integration" do
4
+ subject do
5
+ class TestView < ActionView::Base ; end
6
+ TestView.new
7
+ end
8
+
9
+ it "should respond to img_gravatar" do
10
+ subject.should respond_to(:img_gravatar)
11
+ end
12
+
13
+ it "should produce the defined image URL" do
14
+ # the reference data from http://en.gravatar.com/site/implement/url
15
+ link_url = subject.img_gravatar(REF_MAIL)
16
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\" \/>/
17
+ # just to have the regexp at hand...
18
+ link_url.should =~ /^<img src="#{BASE_URL}\/[a-z0-9]{32}\" \/>/
19
+ end
20
+
21
+ it "should produce the minimal URL if no further arguments are given" do
22
+ link_url = subject.img_gravatar(REF_MAIL)
23
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\" \/>/
24
+ end
25
+
26
+ ['g', 'r', 'x'].each do |rating|
27
+ it "should generate a specific URL for rating #{rating} when requested" do
28
+ link_url = subject.img_gravatar(REF_MAIL, {:rating => rating})
29
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\?r=#{rating}\" \/>/
30
+ end
31
+ end
32
+
33
+ it "should generate specific size URLs for any dimension in 1..512" do
34
+ (1..512).each do |size|
35
+ link_url = subject.img_gravatar(REF_MAIL, {:size => size})
36
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\?s=#{size}\" size="#{size}" \/>/
37
+ end
38
+ end
39
+
40
+ [0, -1 -10, -65535, -65536, 513, 640, 1024, 65535, 65536, 10000000].each do |size|
41
+ it "should generate a default URL if the illegal size #{size} is given" do
42
+ link_url = subject.img_gravatar(REF_MAIL, {:size => size})
43
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\" \/>/
44
+ end
45
+ end
46
+
47
+ it "should generate a URL pointing to a custom default URL if requested" do
48
+ default_url = "http://example.com/images/example.jpg"
49
+ link_url = subject.img_gravatar(REF_MAIL, {:default_url => default_url})
50
+ link_url.should =~ /^<img src="#{BASE_URL}\/[a-z0-9]{32}\?d=#{default_url}\" \/>/
51
+ end
52
+
53
+ ['identicon', 'monsterid', 'wavatar'].each do |dflt|
54
+ it "should use a URL for #{dflt} if requested" do
55
+ link_url = subject.img_gravatar(REF_MAIL, {:default_url => dflt})
56
+ link_url.should =~ /^<img src="#{BASE_URL}\/#{REF_HASH}\?d=#{dflt}\" \/>/
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ImgGravatar, "module methods" do
4
+ subject { ImgGravatar }
5
+
6
+ [:image_url, :link_gravatar].each do |method|
7
+ it "should respond to #{method}" do
8
+ subject.should respond_to(method)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'img_gravatar'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
10
+
11
+ GRAVATAR_HOST = "www.gravatar.com"
12
+ BASE_URL = "http://#{GRAVATAR_HOST}/avatar"
13
+ REF_MAIL = "iHaveAn@email.com"
14
+ REF_HASH = "3b3be63a4c2a439b013787725dfce802"
metadata CHANGED
@@ -1,18 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img_gravatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Till Salzer
8
+ - Jon Wood
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-02-18 00:00:00 +01:00
13
+ date: 2009-11-26 00:00:00 +01:00
13
14
  default_executable:
14
- dependencies: []
15
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.9
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rcov
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.6
35
+ version:
16
36
  description: Add a img_gravatar helper to ActiveView.
17
37
  email: till.salzer@googlemail.com
18
38
  executables: []
@@ -20,35 +40,29 @@ executables: []
20
40
  extensions: []
21
41
 
22
42
  extra_rdoc_files:
23
- - lib/img_gravatar.rb
24
- - MIT-LICENSE
25
43
  - README.rdoc
26
- - tasks/img_gravatar_tasks.rake
27
44
  files:
45
+ - .gitignore
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION.yml
28
50
  - img_gravatar.gemspec
29
51
  - init.rb
30
52
  - install.rb
31
53
  - lib/img_gravatar.rb
32
- - Manifest
33
- - MIT-LICENSE
34
- - Rakefile
35
- - README.rdoc
54
+ - spec/img_gravatar_spec.rb
55
+ - spec/module_gravatar_spec.rb
56
+ - spec/spec_helper.rb
36
57
  - tasks/img_gravatar_tasks.rake
37
- - test/img_gravatar_test.rb
38
- - test/module_gravatar_test.rb
39
58
  - uninstall.rb
40
59
  has_rdoc: true
41
- homepage: http://github.com/tsalzer/img_gravatar
60
+ homepage: http://github.com/tsalzer/minimapper
42
61
  licenses: []
43
62
 
44
63
  post_install_message:
45
64
  rdoc_options:
46
- - --line-numbers
47
- - --inline-source
48
- - --title
49
- - Img_gravatar
50
- - --main
51
- - README.rdoc
65
+ - --charset=UTF-8
52
66
  require_paths:
53
67
  - lib
54
68
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -61,15 +75,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
75
  requirements:
62
76
  - - ">="
63
77
  - !ruby/object:Gem::Version
64
- version: "1.2"
78
+ version: "0"
65
79
  version:
66
80
  requirements: []
67
81
 
68
- rubyforge_project: img_gravatar
69
- rubygems_version: 1.3.4
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
70
84
  signing_key:
71
- specification_version: 2
72
- summary: Add a img_gravatar helper to ActiveView.
85
+ specification_version: 3
86
+ summary: Gravatar image helper
73
87
  test_files:
74
- - test/img_gravatar_test.rb
75
- - test/module_gravatar_test.rb
88
+ - spec/img_gravatar_spec.rb
89
+ - spec/module_gravatar_spec.rb
90
+ - spec/spec_helper.rb
data/Manifest DELETED
@@ -1,12 +0,0 @@
1
- img_gravatar.gemspec
2
- init.rb
3
- install.rb
4
- lib/img_gravatar.rb
5
- Manifest
6
- MIT-LICENSE
7
- Rakefile
8
- README.rdoc
9
- tasks/img_gravatar_tasks.rake
10
- test/img_gravatar_test.rb
11
- test/module_gravatar_test.rb
12
- uninstall.rb
@@ -1,88 +0,0 @@
1
- # Unit tests for ImgGravatar
2
- require 'test/unit'
3
- require 'img_gravatar'
4
-
5
- class TestView < ActionView::Base
6
- end
7
-
8
- class ImgGravatarTest < Test::Unit::TestCase
9
- @@gravatar_host = "www.gravatar.com"
10
- @@base_url = "http://#{@@gravatar_host}/avatar"
11
- @@ref_mail = "iHaveAn@email.com"
12
- @@ref_hash = "3b3be63a4c2a439b013787725dfce802"
13
-
14
-
15
- def test_actionview_integration
16
- myview = TestView.new
17
- assert myview.respond_to?('img_gravatar'), "integration into ActionView failed"
18
- end
19
-
20
- def test_reference_data
21
- myview = TestView.new
22
- # the reference data from http://en.gravatar.com/site/implement/url
23
- link_url = myview.img_gravatar(@@ref_mail)
24
- assert_match(/^<img src="#{@@base_url}\/#{@@ref_hash}\" \/>/, link_url)
25
- #assert_match(/^<img src="http:\/\/www\.gravatar\.com\/avatar\/#{ref_hash}\" \/>/, link_url)
26
- end
27
-
28
- def test_actionview_url
29
- myview = TestView.new
30
- link_url = myview.img_gravatar(@@ref_mail)
31
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
32
- end
33
-
34
- def test_defaults
35
- myview = TestView.new
36
- link_url = myview.img_gravatar(@@ref_mail)
37
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
38
- end
39
-
40
- def test_actionview_ratings
41
- myview = TestView.new
42
- ['g', 'r', 'x'].each do |rating|
43
- link_url = myview.img_gravatar(@@ref_mail, {:rating => rating})
44
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?r=#{rating}\" \/>/, link_url)
45
- end
46
- end
47
-
48
- def test_actionview_size
49
- myview = TestView.new
50
- (1..512).each do |size|
51
- link_url = myview.img_gravatar(@@ref_mail, {:size => size})
52
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?s=#{size}\" \/>/, link_url)
53
- end
54
- end
55
-
56
- def test_illegal_small_sizes
57
- myview = TestView.new
58
- (-10..0).each do |size|
59
- link_url = myview.img_gravatar(@@ref_mail, {:size => size})
60
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
61
- end
62
- end
63
-
64
- def test_illegal_large_sizes
65
- myview = TestView.new
66
- (513..10000).each do |size|
67
- link_url = myview.img_gravatar(@@ref_mail, {:size => size})
68
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
69
- end
70
- end
71
-
72
- def test_default_image_encoding
73
- myview = TestView.new
74
- unencoded = "http://example.com/images/example.jpg"
75
- encoded = 'http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg'
76
- link_url = myview.img_gravatar(@@ref_mail, {:default_url => unencoded})
77
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?d=#{encoded}\" \/>/, link_url)
78
- end
79
-
80
- def test_default_image_specials
81
- myview = TestView.new
82
- ['identicon', 'monsterid', 'wavatar'].each do |dflt|
83
- link_url = myview.img_gravatar(@@ref_mail, {:default_url => dflt})
84
- assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?d=#{dflt}\" \/>/, link_url)
85
- end
86
- end
87
-
88
- end
@@ -1,22 +0,0 @@
1
- # Unit tests for ImgGravatar
2
- require 'test/unit'
3
- require 'img_gravatar'
4
-
5
- class ModuleGravatarTest < Test::Unit::TestCase
6
- @@gravatar_host = "www.gravatar.com"
7
- @@base_url = "http://#{@@gravatar_host}/avatar"
8
- @@ref_mail = "iHaveAn@email.com"
9
- @@ref_hash = "3b3be63a4c2a439b013787725dfce802"
10
-
11
- def test_module_functions
12
- assert(ImgGravatar.respond_to?('image_url'), 'Module ImgGravatar does not respond to image_url')
13
- assert(ImgGravatar.respond_to?('link_gravatar'), 'Module ImgGravatar does not respond to link_grevatar')
14
- end
15
-
16
- def test_reference_data
17
- # the reference data from http://en.gravatar.com/site/implement/url
18
- link_url = ImgGravatar.link_gravatar(@@ref_mail)
19
- assert_match(/^<img src="#{@@base_url}\/#{@@ref_hash}\" \/>/, link_url)
20
- #assert_match(/^<img src="http:\/\/www\.gravatar\.com\/avatar\/#{ref_hash}\" \/>/, link_url)
21
- end
22
- end