Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #29 from VadimPushtaev/master
Browse files Browse the repository at this point in the history
Tests are outdated + Force Default feature
  • Loading branch information
chrislloyd committed Sep 13, 2012
2 parents 2b2252c + 70a2b2f commit bfe15aa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
27 changes: 22 additions & 5 deletions lib/gravtastic.rb
Expand Up @@ -26,9 +26,9 @@ def self.configure(model, *args, &blk)
options = args.last.is_a?(Hash) ? args.pop : {} options = args.last.is_a?(Hash) ? args.pop : {}


model.gravatar_defaults = { model.gravatar_defaults = {
:rating => 'PG', :rating => 'PG',
:secure => true, :secure => true,
:filetype => :png :filetype => :png,
}.merge(options) }.merge(options)


# The method where Gravtastic get the users' email from defaults to `#email`. # The method where Gravtastic get the users' email from defaults to `#email`.
Expand Down Expand Up @@ -64,7 +64,8 @@ module ClassMethods
def gravatar_abbreviations def gravatar_abbreviations
{ :size => 's', { :size => 's',
:default => 'd', :default => 'd',
:rating => 'r' :rating => 'r',
:forcedefault => 'f'
} }
end end
end end
Expand All @@ -83,7 +84,7 @@ def gravatar_url(options={})
options = self.class.gravatar_defaults.merge(options) options = self.class.gravatar_defaults.merge(options)
gravatar_hostname(options.delete(:secure)) + gravatar_hostname(options.delete(:secure)) +
gravatar_filename(options.delete(:filetype)) + gravatar_filename(options.delete(:filetype)) +
url_params_from_hash(options) url_params_from_hash(process_options(options))
end end


private private
Expand All @@ -106,6 +107,22 @@ def gravatar_hostname(secure)
def gravatar_filename(filetype) def gravatar_filename(filetype)
"#{gravatar_id}.#{filetype}" "#{gravatar_id}.#{filetype}"
end 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


end end
26 changes: 18 additions & 8 deletions spec/gravtastic_spec.rb
@@ -1,3 +1,5 @@
require "helper.rb"

describe Gravtastic do describe Gravtastic do


before(:each) do before(:each) do
Expand All @@ -17,8 +19,12 @@


describe 'default' do describe 'default' do


it "options are {:rating => 'PG', :secure => false, :filetype => :png}" do it "options are {:rating => 'PG', :secure => true, :filetype => :png}" do
@g.gravatar_defaults.should == {:rating => 'PG', :secure => false, :filetype => :png} @g.gravatar_defaults.should == {
:rating => 'PG',
:secure => true,
:filetype => :png,
}
end end


it "source is :email" do it "source is :email" do
Expand Down Expand Up @@ -47,23 +53,27 @@
end end


it "makes a pretty URL" do 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 end


it "makes a secure URL" do 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 end


it "makes a jpeggy URL" do 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 end


it "makes a saucy URL" do 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 end


it "abides to some new fancy feature" do 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 end


it "makes a URL from the defaults" do it "makes a URL from the defaults" do
Expand All @@ -73,4 +83,4 @@


end end


end end

0 comments on commit bfe15aa

Please sign in to comment.