Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #29 from VadimPushtaev/master

Tests are outdated + Force Default feature
  • Loading branch information...
commit bfe15aa77cf9fa4c05cc20f7059955ac90a4e205 2 parents 2b2252c + 70a2b2f
@chrislloyd authored
Showing with 40 additions and 13 deletions.
  1. +22 −5 lib/gravtastic.rb
  2. +18 −8 spec/gravtastic_spec.rb
View
27 lib/gravtastic.rb
@@ -26,9 +26,9 @@ def self.configure(model, *args, &blk)
options = args.last.is_a?(Hash) ? args.pop : {}
model.gravatar_defaults = {
- :rating => 'PG',
- :secure => true,
- :filetype => :png
+ :rating => 'PG',
+ :secure => true,
+ :filetype => :png,
}.merge(options)
# The method where Gravtastic get the users' email from defaults to `#email`.
@@ -64,7 +64,8 @@ module ClassMethods
def gravatar_abbreviations
{ :size => 's',
:default => 'd',
- :rating => 'r'
+ :rating => 'r',
+ :forcedefault => 'f'
}
end
end
@@ -83,7 +84,7 @@ def gravatar_url(options={})
options = self.class.gravatar_defaults.merge(options)
gravatar_hostname(options.delete(:secure)) +
gravatar_filename(options.delete(:filetype)) +
- url_params_from_hash(options)
+ url_params_from_hash(process_options(options))
end
private
@@ -106,6 +107,22 @@ def gravatar_hostname(secure)
def gravatar_filename(filetype)
"#{gravatar_id}.#{filetype}"
end
+
+ # Some options need to be processed before becoming URL params
+ def process_options(options)
+ processed_options = {}
+ options.each do |key, val|
+ case key
+ when :forcedefault
+ if val
+ processed_options[key] = 'y'
+ end
+ else
+ processed_options[key] = val
+ end
+ end
+ processed_options
+ end
end
end
View
26 spec/gravtastic_spec.rb
@@ -1,3 +1,5 @@
+require "helper.rb"
+
describe Gravtastic do
before(:each) do
@@ -17,8 +19,12 @@
describe 'default' do
- it "options are {:rating => 'PG', :secure => false, :filetype => :png}" do
- @g.gravatar_defaults.should == {:rating => 'PG', :secure => false, :filetype => :png}
+ it "options are {:rating => 'PG', :secure => true, :filetype => :png}" do
+ @g.gravatar_defaults.should == {
+ :rating => 'PG',
+ :secure => true,
+ :filetype => :png,
+ }
end
it "source is :email" do
@@ -47,23 +53,27 @@
end
it "makes a pretty URL" do
- @user.gravatar_url.should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
+ @user.gravatar_url(:secure => false).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
end
it "makes a secure URL" do
- @user.gravatar_url(:secure => true).should == 'https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
+ @user.gravatar_url.should == 'https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=PG'
end
it "makes a jpeggy URL" do
- @user.gravatar_url(:filetype => :jpg).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?r=PG'
+ @user.gravatar_url(:secure => false, :filetype => :jpg).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.jpg?r=PG'
end
it "makes a saucy URL" do
- @user.gravatar_url(:rating => 'R').should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R'
+ @user.gravatar_url(:secure => false, :rating => 'R').should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R'
+ end
+
+ it "makes a forcedefault URL" do
+ @user.gravatar_url(:secure => false, :forcedefault => true).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?f=y&r=PG'
end
it "abides to some new fancy feature" do
- @user.gravatar_url(:extreme => true).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?extreme=true&r=PG'
+ @user.gravatar_url(:secure => false, :extreme => true).should == 'http://gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?extreme=true&r=PG'
end
it "makes a URL from the defaults" do
@@ -73,4 +83,4 @@
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.