gravatar-ultimate 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.gitignore +13 -0
  2. data/.travis.yml +16 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +37 -0
  5. data/README.rdoc +19 -25
  6. data/Rakefile +9 -38
  7. data/environments/rails-2.3/README +243 -0
  8. data/environments/rails-2.3/Rakefile +10 -0
  9. data/environments/rails-2.3/app/controllers/application_controller.rb +10 -0
  10. data/environments/rails-2.3/app/helpers/application_helper.rb +3 -0
  11. data/environments/rails-2.3/config/boot.rb +114 -0
  12. data/environments/rails-2.3/config/database.yml +22 -0
  13. data/environments/rails-2.3/config/environment.rb +43 -0
  14. data/environments/rails-2.3/config/environments/development.rb +17 -0
  15. data/environments/rails-2.3/config/environments/production.rb +28 -0
  16. data/environments/rails-2.3/config/environments/test.rb +28 -0
  17. data/environments/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
  18. data/environments/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
  19. data/environments/rails-2.3/config/initializers/inflections.rb +10 -0
  20. data/environments/rails-2.3/config/initializers/mime_types.rb +5 -0
  21. data/environments/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
  22. data/environments/rails-2.3/config/initializers/session_store.rb +15 -0
  23. data/environments/rails-2.3/config/locales/en.yml +5 -0
  24. data/environments/rails-2.3/config/routes.rb +43 -0
  25. data/environments/rails-2.3/db/seeds.rb +7 -0
  26. data/environments/rails-2.3/doc/README_FOR_APP +2 -0
  27. data/environments/rails-2.3/public/404.html +30 -0
  28. data/environments/rails-2.3/public/422.html +30 -0
  29. data/environments/rails-2.3/public/500.html +30 -0
  30. data/environments/rails-2.3/public/favicon.ico +0 -0
  31. data/environments/rails-2.3/public/images/rails.png +0 -0
  32. data/environments/rails-2.3/public/index.html +275 -0
  33. data/environments/rails-2.3/public/javascripts/application.js +2 -0
  34. data/environments/rails-2.3/public/javascripts/controls.js +963 -0
  35. data/environments/rails-2.3/public/javascripts/dragdrop.js +973 -0
  36. data/environments/rails-2.3/public/javascripts/effects.js +1128 -0
  37. data/environments/rails-2.3/public/javascripts/prototype.js +4320 -0
  38. data/environments/rails-2.3/public/robots.txt +5 -0
  39. data/environments/rails-2.3/script/about +4 -0
  40. data/environments/rails-2.3/script/console +3 -0
  41. data/environments/rails-2.3/script/dbconsole +3 -0
  42. data/environments/rails-2.3/script/destroy +3 -0
  43. data/environments/rails-2.3/script/generate +3 -0
  44. data/environments/rails-2.3/script/performance/benchmarker +3 -0
  45. data/environments/rails-2.3/script/performance/profiler +3 -0
  46. data/environments/rails-2.3/script/plugin +3 -0
  47. data/environments/rails-2.3/script/runner +3 -0
  48. data/environments/rails-2.3/script/server +3 -0
  49. data/environments/rails-2.3/test/performance/browsing_test.rb +9 -0
  50. data/environments/rails-2.3/test/test_helper.rb +38 -0
  51. data/environments/rails-3.1/.gitignore +15 -0
  52. data/environments/rails-3.1/README +261 -0
  53. data/environments/rails-3.1/Rakefile +7 -0
  54. data/environments/rails-3.1/app/assets/images/rails.png +0 -0
  55. data/environments/rails-3.1/app/assets/javascripts/application.js +9 -0
  56. data/environments/rails-3.1/app/assets/stylesheets/application.css +7 -0
  57. data/environments/rails-3.1/app/controllers/application_controller.rb +3 -0
  58. data/environments/rails-3.1/app/helpers/application_helper.rb +2 -0
  59. data/environments/rails-3.1/app/mailers/.gitkeep +0 -0
  60. data/environments/rails-3.1/app/models/.gitkeep +0 -0
  61. data/environments/rails-3.1/app/views/layouts/application.html.erb +14 -0
  62. data/environments/rails-3.1/config.ru +4 -0
  63. data/environments/rails-3.1/config/application.rb +48 -0
  64. data/environments/rails-3.1/config/boot.rb +6 -0
  65. data/environments/rails-3.1/config/database.yml +25 -0
  66. data/environments/rails-3.1/config/environment.rb +5 -0
  67. data/environments/rails-3.1/config/environments/development.rb +30 -0
  68. data/environments/rails-3.1/config/environments/production.rb +60 -0
  69. data/environments/rails-3.1/config/environments/test.rb +39 -0
  70. data/environments/rails-3.1/config/initializers/backtrace_silencers.rb +7 -0
  71. data/environments/rails-3.1/config/initializers/inflections.rb +10 -0
  72. data/environments/rails-3.1/config/initializers/mime_types.rb +5 -0
  73. data/environments/rails-3.1/config/initializers/secret_token.rb +7 -0
  74. data/environments/rails-3.1/config/initializers/session_store.rb +8 -0
  75. data/environments/rails-3.1/config/initializers/wrap_parameters.rb +14 -0
  76. data/environments/rails-3.1/config/locales/en.yml +5 -0
  77. data/environments/rails-3.1/config/routes.rb +58 -0
  78. data/environments/rails-3.1/db/seeds.rb +7 -0
  79. data/environments/rails-3.1/doc/README_FOR_APP +2 -0
  80. data/environments/rails-3.1/lib/assets/.gitkeep +0 -0
  81. data/environments/rails-3.1/lib/tasks/.gitkeep +0 -0
  82. data/environments/rails-3.1/public/404.html +26 -0
  83. data/environments/rails-3.1/public/422.html +26 -0
  84. data/environments/rails-3.1/public/500.html +26 -0
  85. data/environments/rails-3.1/public/favicon.ico +0 -0
  86. data/environments/rails-3.1/public/index.html +241 -0
  87. data/environments/rails-3.1/public/robots.txt +5 -0
  88. data/environments/rails-3.1/script/rails +6 -0
  89. data/environments/rails-3.1/test/fixtures/.gitkeep +0 -0
  90. data/environments/rails-3.1/test/functional/.gitkeep +0 -0
  91. data/environments/rails-3.1/test/integration/.gitkeep +0 -0
  92. data/environments/rails-3.1/test/performance/browsing_test.rb +12 -0
  93. data/environments/rails-3.1/test/test_helper.rb +13 -0
  94. data/environments/rails-3.1/test/unit/.gitkeep +0 -0
  95. data/environments/rails-3.1/vendor/assets/stylesheets/.gitkeep +0 -0
  96. data/environments/rails-3.1/vendor/plugins/.gitkeep +0 -0
  97. data/environments/rails.rb +26 -0
  98. data/gemfiles/rails-2.3.14 +5 -0
  99. data/gemfiles/rails-2.3.14.lock +55 -0
  100. data/gemfiles/rails-3.1.3 +5 -0
  101. data/gemfiles/rails-3.1.3.lock +110 -0
  102. data/gravatar-ultimate.gemspec +13 -53
  103. data/lib/gravatar.rb +68 -30
  104. data/lib/gravatar/cache.rb +27 -21
  105. data/lib/gravatar/dependencies.rb +1 -18
  106. data/lib/gravatar/test_case.rb +105 -0
  107. data/lib/gravatar/version.rb +8 -0
  108. data/spec/fixtures/image.jpg +0 -0
  109. data/spec/fixtures/responses/grav.addresses +24 -0
  110. data/spec/fixtures/responses/grav.deleteUserimage +18 -0
  111. data/spec/fixtures/responses/grav.exists +20 -0
  112. data/spec/fixtures/responses/grav.exists.invalid +20 -0
  113. data/spec/fixtures/responses/grav.exists.multiple_invalid +21 -0
  114. data/spec/fixtures/responses/grav.removeImage +20 -0
  115. data/spec/fixtures/responses/grav.saveData +18 -0
  116. data/spec/fixtures/responses/grav.saveUrl +18 -0
  117. data/spec/fixtures/responses/grav.test +22 -0
  118. data/spec/fixtures/responses/grav.useUserimage +20 -0
  119. data/spec/fixtures/responses/grav.userimages +27 -0
  120. data/spec/lib/gravatar/cache_setup_spec.rb +2 -0
  121. data/spec/lib/gravatar/{cache_and_logger_spec.rb → cache_spec.rb} +12 -1
  122. data/spec/lib/gravatar/test_case_spec.rb +40 -0
  123. data/spec/lib/gravatar_spec.rb +97 -61
  124. data/spec/spec_helper.rb +37 -9
  125. metadata +208 -38
  126. data/VERSION +0 -1
  127. data/spec/lib/gravatar/dependencies_spec.rb +0 -33
@@ -0,0 +1,8 @@
1
+ class Gravatar
2
+ module Version
3
+ MAJOR, MINOR, TINY = 1, 0, 3
4
+ STRING = [MAJOR, MINOR, TINY].join('.')
5
+ end
6
+
7
+ VERSION = Version::STRING
8
+ end
Binary file
@@ -0,0 +1,24 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:03:38 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326992618%7Ce99170b24c4e0980266341fe9624bc8c; expires=Fri, 30-Jan-2054 10:07:16 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 580
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>gravatartest123@gmail.com</name><value><struct>
16
+ <member><name>rating</name><value><int>0</int></value></member>
17
+ <member><name>userimage</name><value><string>fed25d74d58274248095ca6b2fe2beff</string></value></member>
18
+ <member><name>userimage_url</name><value><string>http://en.gravatar.com/userimage/30721149/fed25d74d58274248095ca6b2fe2beff.jpg</string></value></member>
19
+ </struct></value></member>
20
+ </struct>
21
+ </value>
22
+ </param>
23
+ </params>
24
+ </methodResponse>
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 18:24:30 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326997469%7C42587efbd6b763ee850c6df8d4773dce; expires=Fri, 30-Jan-2054 12:48:59 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 163
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <boolean>1</boolean>
15
+ </value>
16
+ </param>
17
+ </params>
18
+ </methodResponse>
@@ -0,0 +1,20 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 18:37:10 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326998230%7Cb89ab5cf21fa3ffa20f17df81a3b12f5; expires=Fri, 30-Jan-2054 13:14:20 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 253
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>ef23bdc1f1fb9e3f46843a00e5832d98</name><value><int>1</int></value></member>
16
+ </struct>
17
+ </value>
18
+ </param>
19
+ </params>
20
+ </methodResponse>
@@ -0,0 +1,20 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:22:37 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326993757%7C72540173b0631c51e85fc01dca61e168; expires=Fri, 30-Jan-2054 10:45:14 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 253
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>719bc43b2d4ded25e0164af83484f8f9</name><value><int>0</int></value></member>
16
+ </struct>
17
+ </value>
18
+ </param>
19
+ </params>
20
+ </methodResponse>
@@ -0,0 +1,21 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:33:37 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326994417%7C848cddd19297979345219d34a7a6a018; expires=Fri, 30-Jan-2054 11:07:14 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 345
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>bdc68bf1ad91e719bf9e9527158b1aa6</name><value><int>0</int></value></member>
16
+ <member><name>09abeab96651fd6be4ae2d3a6f3140ee</name><value><int>0</int></value></member>
17
+ </struct>
18
+ </value>
19
+ </param>
20
+ </params>
21
+ </methodResponse>
@@ -0,0 +1,20 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 18:01:15 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326996075%7C14852bd9e471836f3694c45941fe4786; expires=Fri, 30-Jan-2054 12:02:30 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 254
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>gravatartest123@gmail.com</name><value><boolean>1</boolean></value></member>
16
+ </struct>
17
+ </value>
18
+ </param>
19
+ </params>
20
+ </methodResponse>
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:36:21 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326994581%7C6c6de4cd3ca0d618837a95c62d3040c1; expires=Fri, 30-Jan-2054 11:12:42 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 192
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <string>3fe9302284aa75e9916f364a3f7989e4</string>
15
+ </value>
16
+ </param>
17
+ </params>
18
+ </methodResponse>
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:00:43 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326992442%7C26b54ee039346e757eddd969dfa13bc1; expires=Fri, 30-Jan-2054 10:01:24 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 192
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <string>fed25d74d58274248095ca6b2fe2beff</string>
15
+ </value>
16
+ </param>
17
+ </params>
18
+ </methodResponse>
@@ -0,0 +1,22 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 15:40:29 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326987629%7Cc15a3b35dc03e97ba2b8a22f523579c8; expires=Fri, 30-Jan-2054 07:20:58 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 397
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>password</name><value><string>censored</string></value></member>
16
+ <member><name>greeting</name><value><string>hello</string></value></member>
17
+ <member><name>response</name><value><int>1326382829</int></value></member>
18
+ </struct>
19
+ </value>
20
+ </param>
21
+ </params>
22
+ </methodResponse>
@@ -0,0 +1,20 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 17:59:53 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326995990%7C75ab09270934a8e66a014c71b48ff416; expires=Fri, 30-Jan-2054 11:59:40 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 254
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>gravatartest123@gmail.com</name><value><boolean>1</boolean></value></member>
16
+ </struct>
17
+ </value>
18
+ </param>
19
+ </params>
20
+ </methodResponse>
@@ -0,0 +1,27 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx
3
+ Date: Thu, 12 Jan 2012 18:35:10 GMT
4
+ Content-Type: text/xml;charset=utf-8
5
+ Connection: keep-alive
6
+ Set-Cookie: gravatar=gravatartest1234%7C1326998110%7C19cb75eb75a09f90a26167c872508d90; expires=Fri, 30-Jan-2054 13:10:20 GMT; path=/; domain=.gravatar.com
7
+ Content-Length: 677
8
+
9
+ <?xml version="1.0"?>
10
+ <methodResponse>
11
+ <params>
12
+ <param>
13
+ <value>
14
+ <struct>
15
+ <member><name>fed25d74d58274248095ca6b2fe2beff</name><value><array><data>
16
+ <value><string>0</string></value>
17
+ <value><string>http://en.gravatar.com/userimage/30721149/fed25d74d58274248095ca6b2fe2beff.jpg</string></value>
18
+ </data></array></value></member>
19
+ <member><name>3fe9302284aa75e9916f364a3f7989e4</name><value><array><data>
20
+ <value><string>0</string></value>
21
+ <value><string>http://en.gravatar.com/userimage/30721149/3fe9302284aa75e9916f364a3f7989e4.jpg</string></value>
22
+ </data></array></value></member>
23
+ </struct>
24
+ </value>
25
+ </param>
26
+ </params>
27
+ </methodResponse>
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe "gravatar cache setup" do
2
4
  context "within Rails" do
3
5
  before(:each) do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Gravatar::Cache do
4
4
  subject { Gravatar::Cache.new(new_cache, 30.minutes, "gravatar-specs") }
5
-
5
+
6
6
  context "with a nonexistent cache item" do
7
7
  it "should be expired" do
8
8
  subject.expired?(:nothing).should be_true
@@ -28,6 +28,13 @@ describe Gravatar::Cache do
28
28
  it "should not be expired" do
29
29
  subject.expired?(:nothing).should be_false
30
30
  end
31
+
32
+ context "after clearing the cache" do
33
+ before { subject.clear! }
34
+ it "should be nil" do
35
+ subject.call(:nothing) { 2 }.should == 2
36
+ end
37
+ end
31
38
 
32
39
  it "should not fire the block" do
33
40
  subject.call(:nothing) { @fired = 1 }
@@ -80,6 +87,10 @@ describe Gravatar::Cache do
80
87
  proc { subject.call(:nothing) { raise "something bad happened" } }.should raise_error(RuntimeError)
81
88
  end
82
89
  end
90
+
91
+ it "should provide access to the cached copy" do
92
+ subject.cached(:nothing).should == 1
93
+ end
83
94
  end
84
95
 
85
96
  it "should return the block value" do
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gravatar::TestCase do
4
+ before { auth_with :password => '123' }
5
+
6
+ it "should have default email address" do
7
+ self.class.default_email.should_not be_nil
8
+ end
9
+
10
+ it "should raise errors instead of logging them" do
11
+ grav.rescue_errors.should be_false
12
+ end
13
+
14
+ it "should use mock responses" do
15
+ mock_response 'grav.test'
16
+ test(:greeting => 'hello').should have_key(:response)
17
+ end
18
+
19
+ it "should nil out mock responses after use" do
20
+ mock_response 'grav.test'
21
+ test(:greeting => 'hello').should have_key(:response)
22
+ mock_response.should be_nil
23
+ end
24
+
25
+ it "should remove mock responses from FakeWeb after use" do
26
+ mock_response 'grav.test'
27
+ test(:greeting => 'hello').should have_key(:response)
28
+ FakeWeb.should_not be_registered_uri(:post, grav.url)
29
+ end
30
+
31
+ it "should not generate grav more than once" do
32
+ grav.should be grav
33
+ end
34
+
35
+ it "should replace old mock responses with nil" do
36
+ mock_response 'grav.test'
37
+ mock_response nil
38
+ mock_response.should be_nil
39
+ end
40
+ end
@@ -1,12 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gravatar do
4
- it "should have a valid version number" do
5
- Gravatar.version.should =~ /^\d+\.\d+\.\d+$/
6
- end
7
-
4
+ default_email $credentials[:primary_email]
5
+ before { grav.auth_with(:password => $credentials[:password]) }
6
+ before { mock_response nil }
7
+
8
8
  it "should allow setting cache duration by instance" do
9
- grav = Gravatar.new($credentials[:primary_email])
10
9
  grav.cache_duration = 10.minutes
11
10
  grav.cache_duration.should == 10.minutes
12
11
  end
@@ -18,124 +17,161 @@ describe Gravatar do
18
17
  end
19
18
 
20
19
  it "should require :email" do
21
- proc { subject }.should raise_error(ArgumentError)
20
+ proc { Gravatar.new(nil, :rescue_errors => false) }.should raise_error(ArgumentError)
22
21
  end
23
22
 
24
23
  context "given :email and :key" do
25
- subject { Gravatar.new($credentials[:primary_email], $credentials)}
24
+ before { grav $credentials[:primary_email], $credentials }
26
25
 
27
26
  context "varying image ratings" do
28
27
  [:g, :pg, :r, :x].each do |rating|
29
28
  it "should save #{rating}-rated URLs and delete them" do
30
- subject.save_url!(rating, "http://jigsaw.w3.org/css-validator/images/vcss").should ==
31
- "2df7db511c46303983f0092556a1e47c"
32
- subject.delete_user_image!("2df7db511c46303983f0092556a1e47c").should == true
29
+ mock_response "grav.saveUrl"
30
+ save_url!(rating, "https://github.com/sinisterchipmunk/gravatar/raw/master/spec/fixtures/image.jpg").should ==
31
+ "fed25d74d58274248095ca6b2fe2beff"
32
+
33
+ mock_response "grav.deleteUserimage"
34
+ delete_user_image!("fed25d74d58274248095ca6b2fe2beff").should == true
33
35
  end
34
36
  end
35
37
 
36
38
  it "should raise an ArgumentError given an invalid rating" do
37
- proc { subject.save_url!(:invalid_rating, "http://jigsaw.w3.org/css-validator/images/vcss") }.should \
39
+ proc { save_url!(:invalid_rating, "https://github.com/sinisterchipmunk/gravatar/raw/master/spec/fixtures/image.jpg") }.should \
38
40
  raise_error(ArgumentError)
39
41
  end
40
42
  end
41
43
 
42
44
  it "should return addresses" do
43
- subject.addresses.should_not be_empty
45
+ mock_response 'grav.addresses'
46
+ addresses.should_not be_empty
44
47
  end
45
48
 
46
49
  it "should test successfully" do
47
- subject.test(:greeting => 'hello').should have_key(:response)
50
+ mock_response 'grav.test'
51
+ test(:greeting => 'hello').should have_key(:response)
48
52
  end
49
53
 
50
54
  it "should save URLs and delete them" do
51
- subject.save_url!(:g, "http://jigsaw.w3.org/css-validator/images/vcss").should == "2df7db511c46303983f0092556a1e47c"
52
- subject.delete_user_image!("2df7db511c46303983f0092556a1e47c").should == true
53
- end
54
-
55
- # Not really the ideal approach but it's a valid test, at least
56
- it "should save and delete images and associate/unassociate them with accounts" do
57
- begin
58
- subject.save_data!(:g, image_data).should == "23f086a793459fa25aab280054fec1b2"
59
- subject.use_user_image!("23f086a793459fa25aab280054fec1b2", $credentials[:email]).should ==
60
- { $credentials[:email] => false }
61
- # See rdoc for #remove_image! for why we're not checking this.
62
- subject.remove_image!($credentials[:email])#.should == { $credentials[:email] => true }
63
- subject.delete_user_image!("23f086a793459fa25aab280054fec1b2").should == true
64
- ensure
65
- subject.remove_image!($credentials[:email])
66
- begin
67
- subject.delete_user_image!("23f086a793459fa25aab280054fec1b2")
68
- rescue XMLRPC::FaultException
69
- end
55
+ mock_response 'grav.saveUrl'
56
+ save_url!(:g, "https://github.com/sinisterchipmunk/gravatar/raw/master/spec/fixtures/image.jpg").should == "fed25d74d58274248095ca6b2fe2beff"
57
+
58
+ mock_response 'grav.deleteUserimage'
59
+ delete_user_image!("fed25d74d58274248095ca6b2fe2beff").should == true
60
+ end
61
+
62
+ context "with a user image attached" do
63
+ before do
64
+ mock_response 'grav.saveData'
65
+ @image_hash = save_data!(:g, mock_image_data)
66
+
67
+ mock_response 'grav.useUserimage'
68
+ use_user_image!(@image_hash, $credentials[:email])
69
+
70
+ @image_hash = 'fed25d74d58274248095ca6b2fe2beff'
70
71
  end
71
- end
72
72
 
73
- it "should return user images" do
74
- subject.user_images.should include({"fe9dee44a1df19967db30a04083722d5"=>
75
- [:g, "http://en.gravatar.com/userimage/14612723/fe9dee44a1df19967db30a04083722d5.jpg"]})
76
- end
73
+ it "should save and delete images and associate/unassociate them with accounts" do
74
+ mock_response 'grav.removeImage'
75
+ remove_image!($credentials[:email]).should == { $credentials[:email] => true }
76
+
77
+ mock_response 'grav.deleteUserimage'
78
+ delete_user_image!('image_hash').should == true
79
+ end
80
+
81
+ it "should return user images" do
82
+ mock_response 'grav.userimages'
83
+ user_images.should include({@image_hash=>
84
+ [:g, "http://en.gravatar.com/userimage/30721149/#{@image_hash}.jpg"]})
85
+ end
77
86
 
78
- it "should determine that the user exists" do
79
- subject.exists?.should be_true
87
+ it "should determine that the email has an avatar" do
88
+ mock_response 'grav.exists'
89
+ exists?.should be_true
90
+ end
80
91
  end
81
92
 
82
- it "should determine that a fake user does not exist" do
83
- subject.exists?("not-even-a-valid-email").should be_false
93
+ it "should determine that a fake email does not have an avatar" do
94
+ mock_response 'grav.exists.invalid'
95
+ exists?("not-even-a-valid-email").should be_false
84
96
  end
85
97
 
86
- it "should determine that multiple fake users do not exist" do
87
- subject.exists?("invalid-1", "invalid-2").should == { "invalid-1" => false, "invalid-2" => false }
98
+ it "should determine that multiple fake emails do not have avatars" do
99
+ mock_response 'grav.exists.multiple_invalid'
100
+ exists?("invalid-1", "invalid-2").should == { "invalid-1" => false, "invalid-2" => false }
88
101
  end
89
102
  end
90
103
 
91
104
  context "given :email" do
92
- subject { Gravatar.new("sinisterchipmunk@gmail.com") }
93
-
105
+ before { grav $credentials[:email] }
106
+
94
107
  it "should not raise an error" do
95
- proc { subject }.should_not raise_error(ArgumentError)
108
+ proc { grav }.should_not raise_error(ArgumentError)
96
109
  end
97
110
 
98
111
  it "should return email_hash" do
99
- subject.email_hash.should == "5d8c7a8d951a28e10bd7407f33df6d63"
112
+ email_hash.should == "ef23bdc1f1fb9e3f46843a00e5832d98"
100
113
  end
101
114
 
102
115
  it "should return gravatar image_url" do
103
- subject.image_url.should == "http://www.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63"
116
+ image_url.should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98"
104
117
  end
105
118
 
106
- it "should return gravitar image data" do
107
- subject.image_data.should == image_data
119
+ context "with a user image attached" do
120
+ before do
121
+ grav $credentials[:email], $credentials
122
+
123
+ mock_response 'grav.saveData'
124
+ @image_hash = save_data!(:g, mock_image_data)
125
+
126
+ mock_response 'grav.useUserimage'
127
+ use_user_image!(@image_hash, $credentials[:email])
128
+ end
129
+
130
+ it "should return gravitar image data" do
131
+ Digest::MD5.hexdigest(grav.image_data).should == Digest::MD5.hexdigest(mock_image_data)
132
+ end
108
133
  end
109
134
 
110
135
  it "should return gravatar image_url with SSL" do
111
- subject.image_url(:ssl => true).should == "https://secure.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63"
136
+ image_url(:ssl => true).should == "https://secure.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98"
112
137
  end
113
138
 
114
139
  it "should return gravatar image_url with size" do
115
- subject.image_url(:size => 512).should == "http://www.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?size=512"
140
+ image_url(:s => 512).should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?s=512"
141
+ image_url(:size => 512).should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?size=512"
116
142
  end
117
143
 
118
144
  it "should return gravatar image_url with rating" do
119
- subject.image_url(:rating => 'pg').should == "http://www.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?rating=pg"
145
+ image_url(:r => 'pg').should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?r=pg"
146
+ image_url(:rating => 'pg').should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?rating=pg"
120
147
  end
121
148
 
122
149
  it "should return gravatar image_url with file type" do
123
- subject.image_url(:filetype => 'png').should == "http://www.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63.png"
150
+ image_url(:filetype => 'png').should == "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98.png"
124
151
  end
125
152
 
126
153
  it "should return gravatar image_url with default image" do
127
- subject.image_url(:default => "http://example.com/images/example.jpg").should ==
128
- "http://www.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?default=http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg"
154
+ image_url(:d => "http://example.com/images/example.jpg").should ==
155
+ "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?d=http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg"
156
+ image_url(:default => "http://example.com/images/example.jpg").should ==
157
+ "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?default=http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg"
158
+ end
159
+
160
+ it "should return gravatar image_url with forcedefault" do
161
+ image_url(:f => :identicon).should ==
162
+ "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?f=identicon"
163
+ image_url(:forcedefault => :identicon).should ==
164
+ "http://www.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?forcedefault=identicon"
129
165
  end
130
166
 
131
167
  it "should return gravatar image_url with SSL and default and size and rating" do
132
168
  combinations = %w(
133
- https://secure.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?default=identicon&size=80&rating=g
134
- https://secure.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?size=80&rating=g&default=identicon
135
- https://secure.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?size=80&default=identicon&rating=g
136
- https://secure.gravatar.com/avatar/5d8c7a8d951a28e10bd7407f33df6d63?rating=g&size=80&default=identicon
169
+ https://secure.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?default=identicon&size=80&rating=g
170
+ https://secure.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?size=80&rating=g&default=identicon
171
+ https://secure.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?size=80&default=identicon&rating=g
172
+ https://secure.gravatar.com/avatar/ef23bdc1f1fb9e3f46843a00e5832d98?rating=g&size=80&default=identicon
137
173
  )
138
- combinations.should include(subject.image_url(:ssl => true, :default => "identicon", :size => 80, :rating => :g))
174
+ combinations.should include(image_url(:ssl => true, :default => "identicon", :size => 80, :rating => :g))
139
175
  end
140
176
  end
141
177
  end