acts_as_gravatar 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +88 -0
- data/Rakefile +1 -0
- data/acts_as_gravatar.gemspec +29 -0
- data/lib/acts_as_gravatar/enums/image_type.rb +12 -0
- data/lib/acts_as_gravatar/enums/rating.rb +12 -0
- data/lib/acts_as_gravatar/gravatar.rb +101 -0
- data/lib/acts_as_gravatar/version.rb +3 -0
- data/lib/acts_as_gravatar.rb +104 -0
- data/spec/acts_as_gravatar/gravatar_spec.rb +75 -0
- data/spec/acts_as_gravatar_spec.rb +103 -0
- data/spec/spec_helper.rb +9 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68830b45a0b35c111dab7a359891b2c227bc10e3
|
4
|
+
data.tar.gz: 3d2a2e37f8c94643c91420b41499e85bad172b3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3b677b38969122b14d93cb473b01734311df60d25ee3af992383e9e501dc11d0f7443692705e777e5e45d1a3bd89ad31562569d18e6d6f886adde44fd8084c4
|
7
|
+
data.tar.gz: 2251ab7811b9f3f0a55653b545bd5036117dd4def7f817ca3a0ab5cb1a149cccc26d9a471289cf0d4608ce3381588dc969d68d1adf081e982d77dc41c4d6e4a5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Atsushi Nakamura
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# ActsAsGravatar
|
2
|
+
|
3
|
+
acts\_as\_gravatar provide simple access to gravatar from ActiveRecord.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'acts_as_gravatar'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install acts_as_gravatar
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Basic
|
22
|
+
Call acts\_as\_gravatar in class of ActiveRecord::Base.
|
23
|
+
|
24
|
+
```
|
25
|
+
class User < ActiveRecord::Base
|
26
|
+
acts_as_gravatar
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
The next method becomes to be usable.
|
31
|
+
|
32
|
+
```
|
33
|
+
user = User.find(1); #
|
34
|
+
|
35
|
+
# get html tag of gravatar.
|
36
|
+
user.gravatar_tag
|
37
|
+
|
38
|
+
# get url of gravatar.
|
39
|
+
user.gravatar_url
|
40
|
+
|
41
|
+
```
|
42
|
+
acts\_as\_gravatar read `email` column.(default)
|
43
|
+
|
44
|
+
### Options
|
45
|
+
when call acts\_as\_gravatar, can set default values.
|
46
|
+
|
47
|
+
```
|
48
|
+
class User < ActiveRecord::Base
|
49
|
+
acts_as_gravatar({
|
50
|
+
:column => :email # set email column.
|
51
|
+
:secure => false # default protocol. (https).
|
52
|
+
:size => 80 # default image size.
|
53
|
+
:default_image => nil # default default_image.
|
54
|
+
:rating => ActsAsGravatar::Enums::Rating # default rating.
|
55
|
+
:image_type => ActsAsGravatar::Enums::ImageType # default image_type.
|
56
|
+
})
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
And can set options, when call `gravatar_tag` or `gravatar_url`.
|
61
|
+
|
62
|
+
```
|
63
|
+
user = User.find(1); #
|
64
|
+
|
65
|
+
# get url of gravatar.
|
66
|
+
user.gravatar_url :secure => true, :size => 200
|
67
|
+
|
68
|
+
```
|
69
|
+
|
70
|
+
gravatar_tag can set some html attributes.
|
71
|
+
|
72
|
+
```
|
73
|
+
user = User.find(1); #
|
74
|
+
|
75
|
+
# get tag of gravatar.
|
76
|
+
user.gravatar_tag {:secure => true, :size => 200}, {:width => "200px"}
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. Fork it
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create new Pull Request
|
87
|
+
|
88
|
+
# I have poor English. Please help meeeeeeeee!!!!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acts_as_gravatar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acts_as_gravatar"
|
8
|
+
spec.version = ActsAsGravatar::VERSION
|
9
|
+
spec.authors = ["Atsushi Nakamura"]
|
10
|
+
spec.email = ["a.nkmr.ja@gmail.com"]
|
11
|
+
spec.description = "acts_as_gravatar provide simple access to gravatar from ActiveRecord.Can interoperate with devise, etc.."
|
12
|
+
spec.summary = "acts_as_gravatar provide simple access to gravatar from ActiveRecord.Can interoperate with devise, etc.."
|
13
|
+
spec.homepage = "https://github.com/alfa-jpn/acts_as_gravatar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
25
|
+
spec.add_development_dependency "yard", "~> 0.8.7.3"
|
26
|
+
|
27
|
+
spec.add_dependency "inum", "~> 1.3.7"
|
28
|
+
spec.add_dependency "activerecord"
|
29
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module ActsAsGravatar
|
2
|
+
require 'cgi'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'acts_as_gravatar/enums/image_type'
|
5
|
+
require 'acts_as_gravatar/enums/rating'
|
6
|
+
|
7
|
+
# This class provide some utils of gravatar.
|
8
|
+
class Gravatar
|
9
|
+
URL='http://www.gravatar.com/avatar/'
|
10
|
+
URL_SSL='https://secure.gravatar.com/avatar/'
|
11
|
+
|
12
|
+
# Generate a URL of Gravatar image.
|
13
|
+
# @If use a default of gravatar(without email), set nil.
|
14
|
+
#
|
15
|
+
# @param email [String] Email.
|
16
|
+
# @param secure [Boolean] Use SSL?
|
17
|
+
# @param size [Integer] Size of Icon.
|
18
|
+
# @param default_image [String] Url of default image.
|
19
|
+
# @param rating [ActsAsGravatar::Enums::Rating] Rating of image.
|
20
|
+
# @param image_type [ActsAsGravatar::Enums::ImageType] Type of image.
|
21
|
+
#
|
22
|
+
# @return [String] Url of Gravatar image.
|
23
|
+
def self.generate_url(email, secure=false, size=nil, default_image=nil, rating=nil, image_type=nil)
|
24
|
+
url = generate_base_url(email, secure, image_type)
|
25
|
+
opt = generate_options_url(size, default_image, rating)
|
26
|
+
|
27
|
+
if opt
|
28
|
+
"#{url}?#{opt}"
|
29
|
+
else
|
30
|
+
url
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generate a tag of Gravatar image.
|
35
|
+
# @If use a default of gravatar(without email), set nil.
|
36
|
+
#
|
37
|
+
# @param email [String] Email.
|
38
|
+
# @param secure [Boolean] Use SSL?
|
39
|
+
# @param size [Integer] Size of Icon.
|
40
|
+
# @param default_image [String] Url of default image.
|
41
|
+
# @param rating [ActsAsGravatar::Enums::Rating] Rating of image.
|
42
|
+
# @param image_type [ActsAsGravatar::Enums::ImageType] Type of image.
|
43
|
+
# @param option [Hash] option of attribute.
|
44
|
+
#
|
45
|
+
# @return [String] Url of Gravatar image.
|
46
|
+
def self.generate_tag(email, secure=false, size=nil, default_image=nil, rating=nil, image_type=nil, option={})
|
47
|
+
attrs = []
|
48
|
+
image = generate_url(email, secure, size, default_image, rating, image_type)
|
49
|
+
option.each do |key, value|
|
50
|
+
attrs << "#{key}=\"#{value}\""
|
51
|
+
end
|
52
|
+
|
53
|
+
"<img src=\"#{image}\" #{attrs.join(' ')}>"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
# Generate a base url of Gravatar image.
|
58
|
+
#
|
59
|
+
# @param email [String] Email.
|
60
|
+
# @param secure [Boolean] Use SSL?
|
61
|
+
# @param image_type [ActsAsGravatar::Enums::ImageType] Type of image.
|
62
|
+
#
|
63
|
+
# @return [String] Url of Gravatar image.
|
64
|
+
def self.generate_base_url(email, secure, image_type)
|
65
|
+
url = []
|
66
|
+
|
67
|
+
if secure
|
68
|
+
url << URL_SSL
|
69
|
+
else
|
70
|
+
url << URL
|
71
|
+
end
|
72
|
+
|
73
|
+
url << Digest::MD5.hexdigest(email.downcase)
|
74
|
+
|
75
|
+
url << ".#{image_type.to_u}" if image_type
|
76
|
+
|
77
|
+
url.join
|
78
|
+
end
|
79
|
+
|
80
|
+
# Generate a options of url.
|
81
|
+
#
|
82
|
+
# @param size [Integer] Size of Icon.
|
83
|
+
# @param default_image [String] Url of default image.
|
84
|
+
# @param rating [ActsAsGravatar::Enums::Rating] Rating of image.
|
85
|
+
#
|
86
|
+
# @return [String] Url of Gravatar image. or nil.
|
87
|
+
def self.generate_options_url(size=nil, default_image=nil, rating=nil)
|
88
|
+
opts = []
|
89
|
+
|
90
|
+
opts << "s=#{size}" if size
|
91
|
+
opts << "d=#{CGI.escape(default_image)}" if default_image
|
92
|
+
opts << "r=#{rating.to_u}" if rating
|
93
|
+
|
94
|
+
if opts.length < 1
|
95
|
+
nil
|
96
|
+
else
|
97
|
+
opts.join('&')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "acts_as_gravatar/version"
|
2
|
+
require "acts_as_gravatar/gravatar"
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
module ActsAsGravatar
|
6
|
+
# Macro for ActiveRecord::Base.
|
7
|
+
module Macro
|
8
|
+
# Use acts_as_gravatar in model.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# acts_as_gravatar {
|
12
|
+
# :column => :email # email column.
|
13
|
+
# :secure => false # default protocol. (https).
|
14
|
+
# :size => 80 # default image size.
|
15
|
+
# :default_image => nil # default default_image.
|
16
|
+
# :rating => ActsAsGravatar::Enums::Rating # default rating.
|
17
|
+
# :image_type => ActsAsGravatar::Enums::ImageType # default image_type.
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
# @params params [Hash] Options of ActsAsGravatar.
|
21
|
+
def acts_as_gravatar(params = {})
|
22
|
+
options = {
|
23
|
+
:column => :email,
|
24
|
+
:secure => false,
|
25
|
+
:size => nil,
|
26
|
+
:default_image => nil,
|
27
|
+
:rating => nil,
|
28
|
+
:image_type => nil
|
29
|
+
}.merge(params)
|
30
|
+
|
31
|
+
include ActsAsGravatar::Methods
|
32
|
+
instance_variable_set(:@acts_as_gravatar_params, options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Methods of ActiveRecord::Base.
|
37
|
+
module Methods
|
38
|
+
|
39
|
+
# Generate a URL of Gravatar image.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# user = User.find(1)
|
43
|
+
# # get url with default options.
|
44
|
+
# url = user.gravatar_url
|
45
|
+
#
|
46
|
+
# # with option.
|
47
|
+
# url = user.gravatar_url {
|
48
|
+
# :secure => false # default protocol. (https).
|
49
|
+
# :size => 80 # default image size.
|
50
|
+
# :default_image => nil # default default_image.
|
51
|
+
# :rating => ActsAsGravatar::Enums::Rating # default rating.
|
52
|
+
# :image_type => ActsAsGravatar::Enums::ImageType # default image_type.
|
53
|
+
# }
|
54
|
+
#
|
55
|
+
# @param options [Hash] Option of gravatar.
|
56
|
+
#
|
57
|
+
# @return [String] Url of Gravatar image.
|
58
|
+
def gravatar_url(options={})
|
59
|
+
opt = self.class.instance_variable_get(:@acts_as_gravatar_params).merge(options)
|
60
|
+
email = send(opt[:column])
|
61
|
+
|
62
|
+
ActsAsGravatar::Gravatar.generate_url(
|
63
|
+
email, opt[:secure], opt[:size], opt[:default_image], opt[:rating], opt[:image_type]
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Generate a tag of Gravatar image.
|
68
|
+
# @example
|
69
|
+
# user = User.find(1)
|
70
|
+
# # get url with default options.
|
71
|
+
# tag = user.gravatar_tag
|
72
|
+
#
|
73
|
+
# # with option.
|
74
|
+
# tag = user.gravatar_tag {
|
75
|
+
# :secure => false # default protocol. (https).
|
76
|
+
# :size => 80 # default image size.
|
77
|
+
# :default_image => nil # default default_image.
|
78
|
+
# :rating => ActsAsGravatar::Enums::Rating # default rating.
|
79
|
+
# :image_type => ActsAsGravatar::Enums::ImageType # default image_type.
|
80
|
+
# }
|
81
|
+
#
|
82
|
+
# # with attributes of tag.
|
83
|
+
# tag = user.gravatar_tag {},{
|
84
|
+
# width: "100px",
|
85
|
+
# height: "100px"
|
86
|
+
# }
|
87
|
+
#
|
88
|
+
# @param options [Hash] Option of gravatar.
|
89
|
+
# @param attributes [Hash] Attributes of tag.
|
90
|
+
#
|
91
|
+
# @return [String] tag of Gravatar image.
|
92
|
+
def gravatar_tag(options={}, attributes={})
|
93
|
+
opt = self.class.instance_variable_get(:@acts_as_gravatar_params).merge(options)
|
94
|
+
email = send(opt[:column])
|
95
|
+
|
96
|
+
ActsAsGravatar::Gravatar.generate_tag(
|
97
|
+
email, opt[:secure], opt[:size], opt[:default_image], opt[:rating], opt[:image_type], attributes
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
ActiveRecord::Base.send :extend, ActsAsGravatar::Macro
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsGravatar::Gravatar do
|
4
|
+
before(:each) do
|
5
|
+
@params = [
|
6
|
+
'nyarukosan@nyaruko.com',
|
7
|
+
false,
|
8
|
+
200,
|
9
|
+
'http://nyaruko.com/',
|
10
|
+
ActsAsGravatar::Enums::Rating::PG,
|
11
|
+
ActsAsGravatar::Enums::ImageType::Jpg
|
12
|
+
]
|
13
|
+
|
14
|
+
@email_md5 = Digest::MD5.hexdigest(@params[0])
|
15
|
+
@url_escaped = CGI.escape(@params[3])
|
16
|
+
|
17
|
+
@base_url = "http://www.gravatar.com/avatar/"
|
18
|
+
@base_url_ssl = "https://secure.gravatar.com/avatar/"
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it 'generate url.' do
|
25
|
+
url = ActsAsGravatar::Gravatar.generate_url(@params[0])
|
26
|
+
|
27
|
+
expect(url).to eq("#{@base_url}#{@email_md5}")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'generate ssl url.' do
|
31
|
+
url = ActsAsGravatar::Gravatar.generate_url(@params[0], true)
|
32
|
+
expect(url).to eq("#{@base_url_ssl}#{@email_md5}")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'generate url with a size option.' do
|
36
|
+
url = ActsAsGravatar::Gravatar.generate_url(*@params[0 .. 2])
|
37
|
+
expect(url).to eq("#{@base_url}#{@email_md5}?s=200")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'generate url with a default_image option.' do
|
41
|
+
url = ActsAsGravatar::Gravatar.generate_url(@params[0], nil, nil, @params[3])
|
42
|
+
expect(url).to eq("#{@base_url}#{@email_md5}?d=#{@url_escaped}")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'generate url with a rating option.' do
|
46
|
+
url = ActsAsGravatar::Gravatar.generate_url(@params[0], nil, nil, nil, @params[4])
|
47
|
+
expect(url).to eq("#{@base_url}#{@email_md5}?r=pg")
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'generate url with a image_type option.' do
|
51
|
+
url = ActsAsGravatar::Gravatar.generate_url(@params[0], nil, nil, nil, nil, @params[5])
|
52
|
+
expect(url).to eq("#{@base_url}#{@email_md5}.jpg")
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'generate url with all options.' do
|
56
|
+
url = ActsAsGravatar::Gravatar.generate_url(*@params)
|
57
|
+
expect(url).to eq("#{@base_url}#{@email_md5}.jpg?s=200&d=#{@url_escaped}&r=pg")
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'generate tag.' do
|
61
|
+
tag = ActsAsGravatar::Gravatar.generate_tag(@params[0])
|
62
|
+
expect(tag).to eq("<img src=\"#{@base_url}#{@email_md5}\" >")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'generate tag with an attribute.' do
|
66
|
+
tag = ActsAsGravatar::Gravatar.generate_tag(@params[0], nil, nil, nil, nil, nil, with:"100px")
|
67
|
+
expect(tag).to eq("<img src=\"#{@base_url}#{@email_md5}\" with=\"100px\">")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'generate tag with some attributes.' do
|
71
|
+
tag = ActsAsGravatar::Gravatar.generate_tag(@params[0], nil, nil, nil, nil, nil, with:"100px", height:"100px")
|
72
|
+
expect(tag).to eq("<img src=\"#{@base_url}#{@email_md5}\" with=\"100px\" height=\"100px\">")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsGravatar do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
test_db = 'tmp/test_db'
|
7
|
+
|
8
|
+
File.delete(test_db) if File.exist?(test_db)
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => test_db
|
11
|
+
ActiveRecord::Base.connection.execute 'CREATE TABLE tests(id integer not null primary key, email string)'
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'after acts_as_gravatar,' do
|
15
|
+
before(:each) do
|
16
|
+
class Test < ActiveRecord::Base
|
17
|
+
acts_as_gravatar
|
18
|
+
attr_accessor :email
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@email = 'nyarukosan@nyaruko.com'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'gravatar_url exists.' do
|
27
|
+
expect(Test.method_defined?(:gravatar_url))
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'gravatar_tag exists.' do
|
31
|
+
expect(Test.method_defined?(:gravatar_tag))
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'instance of ActiveRecord::Base' do
|
35
|
+
before(:each) do
|
36
|
+
@test_instance = Test.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'gravatar_url call ActsAsGravatar.generate_url' do
|
40
|
+
ActsAsGravatar::Gravatar.should_receive(:generate_url).with('nyarukosan@nyaruko.com', false, nil, nil, nil, nil)
|
41
|
+
@test_instance.gravatar_url
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'gravatar_tag call ActsAsGravatar.generate_tag' do
|
45
|
+
ActsAsGravatar::Gravatar.should_receive(:generate_tag).with('nyarukosan@nyaruko.com', false, nil, nil, nil, nil, {})
|
46
|
+
@test_instance.gravatar_tag
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'after acts_as_gravatar with options,' do
|
52
|
+
before(:each) do
|
53
|
+
class Test < ActiveRecord::Base
|
54
|
+
acts_as_gravatar({
|
55
|
+
:secure => true,
|
56
|
+
:size => 200,
|
57
|
+
:default_image => 'http://nyaruko.com/',
|
58
|
+
:rating => ActsAsGravatar::Enums::Rating::PG,
|
59
|
+
:image_type => ActsAsGravatar::Enums::ImageType::Gif
|
60
|
+
})
|
61
|
+
|
62
|
+
attr_accessor :email
|
63
|
+
|
64
|
+
def initialize
|
65
|
+
@email = 'nyarukosan@nyaruko.com'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'instance of ActiveRecord::Base' do
|
71
|
+
before(:each) do
|
72
|
+
@test_instance = Test.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'gravatar_url call ActsAsGravatar.generate_url' do
|
76
|
+
ActsAsGravatar::Gravatar.should_receive(:generate_url).with(
|
77
|
+
'nyarukosan@nyaruko.com',
|
78
|
+
true,
|
79
|
+
200,
|
80
|
+
'http://nyaruko.com/',
|
81
|
+
ActsAsGravatar::Enums::Rating::PG,
|
82
|
+
ActsAsGravatar::Enums::ImageType::Gif
|
83
|
+
)
|
84
|
+
|
85
|
+
@test_instance.gravatar_url
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'gravatar_tag call ActsAsGravatar.generate_tag' do
|
89
|
+
attributes = {width: "500px"}
|
90
|
+
ActsAsGravatar::Gravatar.should_receive(:generate_tag).with(
|
91
|
+
'nyarukosan@nyaruko.com',
|
92
|
+
true,
|
93
|
+
200,
|
94
|
+
'http://nyaruko.com/',
|
95
|
+
ActsAsGravatar::Enums::Rating::PG,
|
96
|
+
ActsAsGravatar::Enums::ImageType::Gif,
|
97
|
+
attributes
|
98
|
+
)
|
99
|
+
@test_instance.gravatar_tag({}, attributes)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_gravatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Atsushi Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.7.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.7.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: inum
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.7
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.7
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: acts_as_gravatar provide simple access to gravatar from ActiveRecord.Can
|
112
|
+
interoperate with devise, etc..
|
113
|
+
email:
|
114
|
+
- a.nkmr.ja@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- acts_as_gravatar.gemspec
|
125
|
+
- lib/acts_as_gravatar.rb
|
126
|
+
- lib/acts_as_gravatar/enums/image_type.rb
|
127
|
+
- lib/acts_as_gravatar/enums/rating.rb
|
128
|
+
- lib/acts_as_gravatar/gravatar.rb
|
129
|
+
- lib/acts_as_gravatar/version.rb
|
130
|
+
- spec/acts_as_gravatar/gravatar_spec.rb
|
131
|
+
- spec/acts_as_gravatar_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
homepage: https://github.com/alfa-jpn/acts_as_gravatar
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: acts_as_gravatar provide simple access to gravatar from ActiveRecord.Can
|
157
|
+
interoperate with devise, etc..
|
158
|
+
test_files:
|
159
|
+
- spec/acts_as_gravatar/gravatar_spec.rb
|
160
|
+
- spec/acts_as_gravatar_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
has_rdoc:
|