problems_helper_spec.rb
2.15 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
require 'spec_helper'
describe ProblemsHelper do
describe '#truncated_problem_message' do
it 'is html safe' do
problem = double('problem', :message => '#<NoMethodError: ...>')
truncated = helper.truncated_problem_message(problem)
truncated.should be_html_safe
truncated.should_not include('<', '>')
end
end
describe "#gravatar_tag" do
let(:email) { "gravatar@example.com" }
let(:email_hash) { Digest::MD5.hexdigest email }
let(:base_url) { "http://www.gravatar.com/avatar/#{email_hash}" }
context "default config" do
before do
Errbit::Config.stub(:use_gravatar).and_return(true)
Errbit::Config.stub(:gravatar_default).and_return('identicon')
end
it "should render image_tag with correct alt and src" do
expected = "<img alt=\"#{email}\" class=\"gravatar\" src=\"#{base_url}?d=identicon&s=48\" />"
helper.gravatar_tag(email, :s => 48).should eq(expected)
end
it "should override :d" do
expected = "<img alt=\"#{email}\" class=\"gravatar\" src=\"#{base_url}?d=retro&s=48\" />"
helper.gravatar_tag(email, :d => 'retro', :s => 48).should eq(expected)
end
end
context "no email" do
it "should not render the tag" do
helper.gravatar_tag(nil).should be_nil
end
end
end
describe "#gravatar_url" do
context "no email" do
let(:email) { nil }
it "should return nil" do
helper.gravatar_url(email).should be_nil
end
end
context "without ssl" do
let(:email) { "gravatar@example.com" }
let(:email_hash) { Digest::MD5.hexdigest email }
it "should return the http url" do
helper.gravatar_url(email).should eq("http://www.gravatar.com/avatar/#{email_hash}?d=identicon")
end
end
context "with ssl" do
let(:email) { "gravatar@example.com" }
let(:email_hash) { Digest::MD5.hexdigest email }
it "should return the http url" do
ActionController::TestRequest.any_instance.stub :ssl? => true
helper.gravatar_url(email).should eq("https://secure.gravatar.com/avatar/#{email_hash}?d=identicon")
end
end
end
end