chrislloyd / gravtastic

Add Gravatars to your Rubies/Rails!

This URL has Read+Write access

chrislloyd (author)
Mon Jun 15 04:13:31 -0700 2009
commit  b0c0f85bfb514958601d9e199f579b68c04f6efc
tree    8da9500025c27f638ec06bc3dc00b5f7b8938f38
parent  04cc688d321da26dab4c9b083674e1cae26b6fec
gravtastic / spec / gravtastic_spec.rb
100644 79 lines (57 sloc) 2.178 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + '/../lib/gravtastic'
 
describe Gravtastic do
 
  before(:each) do
    @g = Class.new do |c|
      c.send(:include, Gravtastic)
      c.is_gravtastic
    end
  end
 
  describe ".is_gravtastic" do
 
    it "includes the methods" do
      @g.included_modules.should include(Gravtastic::InstanceMethods)
    end
 
  end
 
  describe 'default' do
 
    it "options are {:rating => 'PG', :secure => false, :filetype => :png}" do
      @g.gravatar_defaults.should == {:rating => 'PG', :secure => false, :filetype => :png}
    end
 
    it "source is :email" do
      @g.gravatar_source.should == :email
    end
 
  end
 
  describe "#gravatar_id" do
 
    it "downcases email" do
      a = @g.new
      stub(a).email{ 'USER@EXAMPLE.COM' }
      b = @g.new
      stub(b).email{ 'user@example.com' }
      a.gravatar_id.should == b.gravatar_id
    end
 
  end
 
  describe "#gravatar_url" do
 
    before(:each) do
      @user = @g.new
      stub(@user).email{ 'user@example.com' }
    end
 
    it "makes a pretty URL" do
      @user.gravatar_url.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'
    end
 
    it "makes a jpeggy URL" do
      @user.gravatar_url(: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'
    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'
    end
 
    it "makes a URL from the defaults" do
      stub(@user.class).gravatar_defaults{ {:size => 20, :rating => 'R18', :secure => true, :filetype => :png} }
      @user.gravatar_url.should == 'https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af.png?r=R18&s=20'
    end
 
  end
 
end