acts_as_gravatar 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68830b45a0b35c111dab7a359891b2c227bc10e3
4
- data.tar.gz: 3d2a2e37f8c94643c91420b41499e85bad172b3e
3
+ metadata.gz: 6b4c47913dc7fd944b2281cdbe9b0e92e5710880
4
+ data.tar.gz: 7975c899b60d71446d296d43086ad9737643d363
5
5
  SHA512:
6
- metadata.gz: e3b677b38969122b14d93cb473b01734311df60d25ee3af992383e9e501dc11d0f7443692705e777e5e45d1a3bd89ad31562569d18e6d6f886adde44fd8084c4
7
- data.tar.gz: 2251ab7811b9f3f0a55653b545bd5036117dd4def7f817ca3a0ab5cb1a149cccc26d9a471289cf0d4608ce3381588dc969d68d1adf081e982d77dc41c4d6e4a5
6
+ metadata.gz: d1b49ae702b606d6d365fb73476efccf76e55cbc44e6e132d4f78f579ca1320d668d758dedbfb1961b04fa700a74911ead2bb9eb949c2850eae1e4d92ea79203
7
+ data.tar.gz: 8c293369b5ef13fa5644a6099a956f79d2c5eefcbaaec201d9a61f567bc7edf47370e866453766bdf0a06757419abc8646e07de7ac5d1f72acfd4a64038f00e2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # ActsAsGravatar
1
+ # acts_as_gravatar
2
2
 
3
3
  acts\_as\_gravatar provide simple access to gravatar from ActiveRecord.
4
+ From the email columns (can set it optionally) such as devices, acts_as_gravatar generate a URL of gravatar.
4
5
 
5
6
  ## Installation
6
7
 
@@ -33,49 +34,47 @@ The next method becomes to be usable.
33
34
  user = User.find(1); #
34
35
 
35
36
  # get html tag of gravatar.
36
- user.gravatar_tag
37
+ user.gravatar_profile # URL of gravatar profile.
37
38
 
38
39
  # get url of gravatar.
39
- user.gravatar_url
40
+ user.gravatar_image # URL of gravatar image.
40
41
 
41
42
  ```
42
43
  acts\_as\_gravatar read `email` column.(default)
43
44
 
44
45
  ### Options
45
46
  when call acts\_as\_gravatar, can set default values.
46
-
47
+ (The option not to appoint at the time of acts_as_gravatar summons becomes the default of gravatar.)
47
48
  ```
48
49
  class User < ActiveRecord::Base
49
50
  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.
51
+ :column => :email, # email column of Model.
52
+ :default_image => nil, # default_image.(URL or gravatar default image param.)
53
+ :force_default => false, # force the default image.
54
+ :image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
55
+ :rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
56
+ :secure => false, # secure protocol. (https).
57
+ :size => 80, # image size.
56
58
  })
57
59
  end
58
60
  ```
59
61
 
60
- And can set options, when call `gravatar_tag` or `gravatar_url`.
62
+ And can set options, when call `gravatar_image` or `gravatar_profile`.
61
63
 
62
64
  ```
63
65
  user = User.find(1); #
64
66
 
65
67
  # get url of gravatar.
66
- user.gravatar_url :secure => true, :size => 200
67
-
68
- ```
68
+ user.gravatar_image :secure => true, :size => 200
69
69
 
70
- gravatar_tag can set some html attributes.
71
-
72
- ```
73
- user = User.find(1); #
74
70
 
75
71
  # get tag of gravatar.
76
- user.gravatar_tag {:secure => true, :size => 200}, {:width => "200px"}
72
+ user.gravatar_tag :column => :other_column
77
73
  ```
78
74
 
75
+ ## API DOCUMENT
76
+
77
+ * [acts_as_gravatar](http://rubydoc.info/github/alfa-jpn/acts_as_gravatar/frames)
79
78
 
80
79
  ## Contributing
81
80
 
@@ -8,17 +8,18 @@ module ActsAsGravatar
8
8
  # Use acts_as_gravatar in model.
9
9
  #
10
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
- # }
11
+ # acts_as_gravatar({
12
+ # :column => :email, # email column of Model.
13
+ # :default_image => nil, # default_image.(URL or gravatar default image param.)
14
+ # :force_default => false, # force the default image.
15
+ # :image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
16
+ # :rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
17
+ # :secure => false, # secure protocol. (https).
18
+ # :size => 80, # image size.
19
+ # })
19
20
  #
20
- # @params params [Hash] Options of ActsAsGravatar.
21
- def acts_as_gravatar(params = {})
21
+ # @params default_options [Hash] Default options of ActsAsGravatar.
22
+ def acts_as_gravatar(default_options = {})
22
23
  options = {
23
24
  :column => :email,
24
25
  :secure => false,
@@ -26,10 +27,10 @@ module ActsAsGravatar
26
27
  :default_image => nil,
27
28
  :rating => nil,
28
29
  :image_type => nil
29
- }.merge(params)
30
+ }.merge(default_options)
30
31
 
31
32
  include ActsAsGravatar::Methods
32
- instance_variable_set(:@acts_as_gravatar_params, options)
33
+ instance_variable_set(:@acts_as_gravatar_default_options, options)
33
34
  end
34
35
  end
35
36
 
@@ -45,57 +46,54 @@ module ActsAsGravatar
45
46
  #
46
47
  # # with option.
47
48
  # 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.
49
+ # :column => :email, # email column of Model.
50
+ # :default_image => nil, # default_image.(URL or gravatar default image param.)
51
+ # :force_default => false, # force the default image.
52
+ # :image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
53
+ # :rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
54
+ # :secure => false, # secure protocol. (https).
55
+ # :size => 80, # image size.
53
56
  # }
54
57
  #
55
- # @param options [Hash] Option of gravatar.
58
+ # @param options [Hash] Option of gravatar image.
56
59
  #
57
60
  # @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
+ def gravatar_image(options = {})
62
+ opts = gravatar_option(options)
63
+ email = send(opts[:column])
61
64
 
62
- ActsAsGravatar::Gravatar.generate_url(
63
- email, opt[:secure], opt[:size], opt[:default_image], opt[:rating], opt[:image_type]
64
- )
65
+ ActsAsGravatar::Gravatar.generate_image(email, opts)
65
66
  end
66
67
 
67
- # Generate a tag of Gravatar image.
68
+ # Generate a URL of Gravatar profile.
68
69
  # @example
69
70
  # user = User.find(1)
70
71
  # # get url with default options.
71
- # tag = user.gravatar_tag
72
+ # profile = user.gravatar_profile
72
73
  #
73
74
  # # 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"
75
+ # profile = user.gravatar_profile {
76
+ # :column => :email
86
77
  # }
87
78
  #
88
- # @param options [Hash] Option of gravatar.
89
- # @param attributes [Hash] Attributes of tag.
79
+ # @param options [Hash] Option of gravatar profile.
90
80
  #
91
81
  # @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])
82
+ def gravatar_profile(options = {})
83
+ opts = gravatar_option(options)
84
+ email = send(opts[:column])
95
85
 
96
- ActsAsGravatar::Gravatar.generate_tag(
97
- email, opt[:secure], opt[:size], opt[:default_image], opt[:rating], opt[:image_type], attributes
98
- )
86
+ ActsAsGravatar::Gravatar.generate_profile(email, opts)
87
+ end
88
+
89
+ private
90
+ # Get options of gravatar.
91
+ # @note return default options merge merge_options.
92
+ #
93
+ # @param merge_options [Hash] Options of gravatar.
94
+ # @return [Hash] Options of gravatar.
95
+ def gravatar_option(merge_options = {})
96
+ self.class.instance_variable_get(:@acts_as_gravatar_default_options).merge(merge_options)
99
97
  end
100
98
 
101
99
  end
@@ -3,10 +3,10 @@ require 'inum'
3
3
  module ActsAsGravatar
4
4
  module Enums
5
5
  class ImageType < Inum::Base
6
- define_enum :Jpg
7
- define_enum :Jpeg
8
- define_enum :Gif
9
- define_enum :Png
6
+ define_enum :JPG
7
+ define_enum :JPEG
8
+ define_enum :GIF
9
+ define_enum :PNG
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -9,4 +9,4 @@ module ActsAsGravatar
9
9
  define_enum :X
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -6,23 +6,30 @@ module ActsAsGravatar
6
6
 
7
7
  # This class provide some utils of gravatar.
8
8
  class Gravatar
9
- URL='http://www.gravatar.com/avatar/'
10
- URL_SSL='https://secure.gravatar.com/avatar/'
9
+ PROFILE_URL = 'http://www.gravatar.com/'
10
+ IMAGE_URL = 'http://www.gravatar.com/avatar/'
11
+ IMAGE_URL_SSL = 'https://secure.gravatar.com/avatar/'
12
+
11
13
 
12
14
  # Generate a URL of Gravatar image.
13
- # @If use a default of gravatar(without email), set nil.
14
15
  #
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.
16
+ # @example
17
+ # generate_image 'nyarukosan@nyaruko.com', {
18
+ # :default_image => nil, # default_image.(URL or gravatar default image param.)
19
+ # :force_default => false, # force the default image.
20
+ # :image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
21
+ # :rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
22
+ # :secure => false, # secure protocol. (https).
23
+ # :size => 80, # image size.
24
+ # }
25
+ #
26
+ # @param email [String] Email.
27
+ # @param options [Hash] Options of gravatar.
21
28
  #
22
29
  # @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)
30
+ def self.generate_image(email, options = {})
31
+ url = generate_image_base_url(email, options)
32
+ opt = generate_image_options(options)
26
33
 
27
34
  if opt
28
35
  "#{url}?#{opt}"
@@ -31,65 +38,53 @@ module ActsAsGravatar
31
38
  end
32
39
  end
33
40
 
34
- # Generate a tag of Gravatar image.
35
- # @If use a default of gravatar(without email), set nil.
41
+ # Generate a URL of Gravatar profile.
36
42
  #
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.
43
+ # @example
44
+ # generate_profile 'nyarukosan@nyaruko.com'
44
45
  #
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(' ')}>"
46
+ # @param email [String] Email.
47
+ # @param options [Hash] Options of gravatar.(There are none now.)
48
+ #
49
+ # @return [String] Url of Gravatar profile.
50
+ def self.generate_profile(email, options = {})
51
+ generate_profile_base_url(email, options)
54
52
  end
55
53
 
56
54
  private
57
55
  # Generate a base url of Gravatar image.
58
56
  #
59
- # @param email [String] Email.
60
- # @param secure [Boolean] Use SSL?
61
- # @param image_type [ActsAsGravatar::Enums::ImageType] Type of image.
57
+ # @param email [String] Email.
58
+ # @param options [Hash] Options of gravatar image.
62
59
  #
63
60
  # @return [String] Url of Gravatar image.
64
- def self.generate_base_url(email, secure, image_type)
61
+ def self.generate_image_base_url(email, options = {})
65
62
  url = []
66
63
 
67
- if secure
68
- url << URL_SSL
64
+ if options[:secure]
65
+ url << IMAGE_URL_SSL
69
66
  else
70
- url << URL
67
+ url << IMAGE_URL
71
68
  end
72
69
 
73
70
  url << Digest::MD5.hexdigest(email.downcase)
74
-
75
- url << ".#{image_type.to_u}" if image_type
71
+ url << ".#{options[:image_type].to_u}" if options[:image_type]
76
72
 
77
73
  url.join
78
74
  end
79
75
 
80
76
  # Generate a options of url.
81
77
  #
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.
78
+ # @param options [Hash] Options of gravatar image.
85
79
  #
86
80
  # @return [String] Url of Gravatar image. or nil.
87
- def self.generate_options_url(size=nil, default_image=nil, rating=nil)
81
+ def self.generate_image_options(options = {})
88
82
  opts = []
89
83
 
90
- opts << "s=#{size}" if size
91
- opts << "d=#{CGI.escape(default_image)}" if default_image
92
- opts << "r=#{rating.to_u}" if rating
84
+ opts << "s=#{options[:size]}" if options[:size]
85
+ opts << "d=#{CGI.escape(options[:default_image])}" if options[:default_image]
86
+ opts << "r=#{options[:rating].to_u}" if options[:rating]
87
+ opts << 'f=y' if options[:force_default]
93
88
 
94
89
  if opts.length < 1
95
90
  nil
@@ -97,5 +92,16 @@ module ActsAsGravatar
97
92
  opts.join('&')
98
93
  end
99
94
  end
95
+
96
+ # Generate a base url of Gravatar profile.
97
+ #
98
+ # @param email [String] Email.
99
+ # @param options [Hash] Options of gravatar profile.
100
+ #
101
+ # @return [String] Url of Gravatar image.
102
+ def self.generate_profile_base_url(email, options = {})
103
+ "#{PROFILE_URL}#{Digest::MD5.hexdigest(email.downcase)}"
104
+ end
105
+
100
106
  end
101
107
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsGravatar
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -2,74 +2,98 @@ require 'spec_helper'
2
2
 
3
3
  describe ActsAsGravatar::Gravatar do
4
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
5
 
14
- @email_md5 = Digest::MD5.hexdigest(@params[0])
15
- @url_escaped = CGI.escape(@params[3])
6
+ # generate_url 'nyarukosan@nyaruko.com', {
7
+ # :default_image => nil, # default_image.(URL or gravatar default image param.)
8
+ # :force_default => false, # force the default image.
9
+ # :image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
10
+ # :rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
11
+ # :secure => false, # secure protocol. (https).
12
+ # :size => 80, # image size.
13
+ # }
16
14
 
17
- @base_url = "http://www.gravatar.com/avatar/"
18
- @base_url_ssl = "https://secure.gravatar.com/avatar/"
15
+ @email = 'nyaruratohotepu@nyaruko.com'
16
+ @email_md5 = Digest::MD5.hexdigest(@email)
17
+
18
+ @url = 'http://nyaruko.com/'
19
+ @url_enc = CGI.escape(@url)
20
+
21
+ @options = {
22
+ default_image: @url,
23
+ force_default: true,
24
+ image_type: ActsAsGravatar::Enums::ImageType::JPG,
25
+ rating: ActsAsGravatar::Enums::Rating::PG,
26
+ secure: true,
27
+ size: 200
28
+ }
29
+
30
+ @profile_url = 'http://www.gravatar.com/'
31
+ @image_url = 'http://www.gravatar.com/avatar/'
32
+ @image_url_ssl = 'https://secure.gravatar.com/avatar/'
19
33
 
20
34
 
21
35
  end
22
36
 
23
37
 
24
- it 'generate url.' do
25
- url = ActsAsGravatar::Gravatar.generate_url(@params[0])
38
+ it 'generate_profile generate profile.' do
39
+ url = ActsAsGravatar::Gravatar.generate_profile(@email)
40
+ expect(url).to eq("#{@profile_url}#{@email_md5}")
41
+ end
26
42
 
27
- expect(url).to eq("#{@base_url}#{@email_md5}")
43
+ it 'generate_profile generate collect profile with disable option.' do
44
+ url = ActsAsGravatar::Gravatar.generate_profile(@email, @options)
45
+ expect(url).to eq("#{@profile_url}#{@email_md5}")
28
46
  end
29
47
 
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}")
48
+ it 'generate_image generate url.' do
49
+ url = ActsAsGravatar::Gravatar.generate_image(@email)
50
+ expect(url).to eq("#{@image_url}#{@email_md5}")
33
51
  end
34
52
 
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")
53
+ it 'generate_image generate collect image with disable option.' do
54
+ url = ActsAsGravatar::Gravatar.generate_image(@email, aaaaaa: false, bbbbb: 'bbbbbb', null: nil)
55
+ expect(url).to eq("#{@image_url}#{@email_md5}")
38
56
  end
39
57
 
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}")
58
+ it 'generate_image generate url with a secure option.' do
59
+ url = ActsAsGravatar::Gravatar.generate_image(@email, secure: true)
60
+ expect(url).to eq("#{@image_url_ssl}#{@email_md5}")
43
61
  end
44
62
 
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")
63
+ it 'generate_image generate url with a size option.' do
64
+ url = ActsAsGravatar::Gravatar.generate_image(@email, size: 200)
65
+ expect(url).to eq("#{@image_url}#{@email_md5}?s=200")
48
66
  end
49
67
 
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")
68
+ it 'generate_image generate url with a url defualt_image option.' do
69
+ url = ActsAsGravatar::Gravatar.generate_image(@email, default_image: @url)
70
+ expect(url).to eq("#{@image_url}#{@email_md5}?d=#{@url_enc}")
53
71
  end
54
72
 
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")
73
+ it 'generate_image generate url with a keyword defualt_image option.' do
74
+ url = ActsAsGravatar::Gravatar.generate_image(@email, default_image: 'mm')
75
+ expect(url).to eq("#{@image_url}#{@email_md5}?d=mm")
58
76
  end
59
77
 
60
- it 'generate tag.' do
61
- tag = ActsAsGravatar::Gravatar.generate_tag(@params[0])
62
- expect(tag).to eq("<img src=\"#{@base_url}#{@email_md5}\" >")
78
+ it 'generate_image generate url with a rating option.' do
79
+ url = ActsAsGravatar::Gravatar.generate_image(@email, rating: ActsAsGravatar::Enums::Rating::PG)
80
+ expect(url).to eq("#{@image_url}#{@email_md5}?r=pg")
63
81
  end
64
82
 
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\">")
83
+ it 'generate_image generate url with a rating option.' do
84
+ url = ActsAsGravatar::Gravatar.generate_image(@email, image_type: ActsAsGravatar::Enums::ImageType::JPG)
85
+ expect(url).to eq("#{@image_url}#{@email_md5}.jpg")
68
86
  end
69
87
 
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\">")
88
+ it 'generate_image generate url with a force_default option.' do
89
+ url = ActsAsGravatar::Gravatar.generate_image(@email, force_default: true)
90
+ expect(url).to eq("#{@image_url}#{@email_md5}?f=y")
73
91
  end
92
+
93
+ it 'generate_image generate url with all option.' do
94
+ url = ActsAsGravatar::Gravatar.generate_image(@email, @options)
95
+ expect(url).to eq("#{@image_url_ssl}#{@email_md5}.jpg?s=200&d=#{@url_enc}&r=pg&f=y")
96
+ end
97
+
74
98
  end
75
99
 
@@ -9,6 +9,15 @@ describe ActsAsGravatar do
9
9
 
10
10
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => test_db
11
11
  ActiveRecord::Base.connection.execute 'CREATE TABLE tests(id integer not null primary key, email string)'
12
+
13
+ @default_option ={
14
+ :column=>:email,
15
+ :secure=>false,
16
+ :size=>nil,
17
+ :default_image=>nil,
18
+ :rating=>nil,
19
+ :image_type=>nil
20
+ }
12
21
  end
13
22
 
14
23
  context 'after acts_as_gravatar,' do
@@ -23,12 +32,12 @@ describe ActsAsGravatar do
23
32
  end
24
33
  end
25
34
 
26
- it 'gravatar_url exists.' do
27
- expect(Test.method_defined?(:gravatar_url))
35
+ it 'gravatar_image exists.' do
36
+ expect(Test.method_defined?(:gravatar_image))
28
37
  end
29
38
 
30
- it 'gravatar_tag exists.' do
31
- expect(Test.method_defined?(:gravatar_tag))
39
+ it 'gravatar_profile exists.' do
40
+ expect(Test.method_defined?(:gravatar_profile))
32
41
  end
33
42
 
34
43
  context 'instance of ActiveRecord::Base' do
@@ -36,14 +45,14 @@ describe ActsAsGravatar do
36
45
  @test_instance = Test.new
37
46
  end
38
47
 
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
48
+ it 'gravatar_image call ActsAsGravatar.generate_image' do
49
+ ActsAsGravatar::Gravatar.should_receive(:generate_image).with('nyarukosan@nyaruko.com', @default_option)
50
+ @test_instance.gravatar_image
42
51
  end
43
52
 
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
53
+ it 'gravatar_profile call ActsAsGravatar.generate_profile' do
54
+ ActsAsGravatar::Gravatar.should_receive(:generate_profile).with('nyarukosan@nyaruko.com', @default_option)
55
+ @test_instance.gravatar_profile
47
56
  end
48
57
  end
49
58
  end
@@ -56,7 +65,7 @@ describe ActsAsGravatar do
56
65
  :size => 200,
57
66
  :default_image => 'http://nyaruko.com/',
58
67
  :rating => ActsAsGravatar::Enums::Rating::PG,
59
- :image_type => ActsAsGravatar::Enums::ImageType::Gif
68
+ :image_type => ActsAsGravatar::Enums::ImageType::GIF
60
69
  })
61
70
 
62
71
  attr_accessor :email
@@ -72,31 +81,64 @@ describe ActsAsGravatar do
72
81
  @test_instance = Test.new
73
82
  end
74
83
 
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
84
+ it 'gravatar_url call ActsAsGravatar.generate_image' do
85
+ ActsAsGravatar::Gravatar.should_receive(:generate_image).with(
86
+ "nyarukosan@nyaruko.com",
87
+ {
88
+ :column => :email,
89
+ :secure => true,
90
+ :size => 200,
91
+ :default_image => 'http://nyaruko.com/',
92
+ :rating => ActsAsGravatar::Enums::Rating::PG,
93
+ :image_type => ActsAsGravatar::Enums::ImageType::GIF
94
+ }
95
+ )
96
+ @test_instance.gravatar_image
97
+ end
98
+
99
+ it 'gravatar_image call ActsAsGravatar.generate_image with merged option.' do
100
+ ActsAsGravatar::Gravatar.should_receive(:generate_image).with(
101
+ "nyarukosan@nyaruko.com",
102
+ {
103
+ :column => :email,
104
+ :secure => true,
105
+ :size => 200,
106
+ :default_image => 'mm',
107
+ :rating => ActsAsGravatar::Enums::Rating::PG,
108
+ :image_type => ActsAsGravatar::Enums::ImageType::GIF
109
+ }
83
110
  )
111
+ @test_instance.gravatar_image :default_image => 'mm'
112
+ end
84
113
 
85
- @test_instance.gravatar_url
114
+ it 'gravatar_profile call ActsAsGravatar.generate_profile' do
115
+ ActsAsGravatar::Gravatar.should_receive(:generate_profile).with(
116
+ "nyarukosan@nyaruko.com",
117
+ {
118
+ :column => :email,
119
+ :secure => true,
120
+ :size => 200,
121
+ :default_image => 'http://nyaruko.com/',
122
+ :rating => ActsAsGravatar::Enums::Rating::PG,
123
+ :image_type => ActsAsGravatar::Enums::ImageType::GIF
124
+ }
125
+ )
126
+ @test_instance.gravatar_profile
86
127
  end
87
128
 
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
129
+ it 'gravatar_profile call ActsAsGravatar.generate_profile with merged option.' do
130
+ ActsAsGravatar::Gravatar.should_receive(:generate_profile).with(
131
+ "nyarukosan@nyaruko.com",
132
+ {
133
+ :column => :email,
134
+ :secure => false,
135
+ :size => 888,
136
+ :default_image => 'http://nyaruko.com/',
137
+ :rating => ActsAsGravatar::Enums::Rating::PG,
138
+ :image_type => ActsAsGravatar::Enums::ImageType::GIF
139
+ }
98
140
  )
99
- @test_instance.gravatar_tag({}, attributes)
141
+ @test_instance.gravatar_profile :secure => false, :size => 888
100
142
  end
101
143
  end
102
144
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_gravatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-02 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler