1+ # encoding: utf-8
2+ require 'spec_helper'
3+ require_dependency 'avatar_detector'
4+
5+ describe AvatarDetector do
6+
7+ describe "construction" do
8+
9+ it "raises an error without a user" do
10+ -> { AvatarDetector . new ( nil ) } . should raise_error
11+ end
12+
13+ it "raises an error on a non-user object" do
14+ -> { AvatarDetector . new ( Array . new ) } . should raise_error
15+ end
16+
17+ end
18+
19+ describe "has_custom_avatar?" do
20+
21+ describe "with a user" do
22+ let ( :user ) { User . new ( use_uploaded_avatar : true ) }
23+ let ( :avatar_detector ) { AvatarDetector . new ( user ) }
24+
25+ describe "when the user doesn't have an uploaded_avatar_path" do
26+
27+ before do
28+ user . stubs ( :uploaded_avatar_path )
29+ end
30+
31+ it "returns true if they have a custom gravatar" do
32+ avatar_detector . expects ( :has_custom_gravatar? ) . returns ( true )
33+ avatar_detector . has_custom_avatar? . should be_true
34+ end
35+
36+ it "returns false if they don't have a custom gravatar" do
37+ avatar_detector . expects ( :has_custom_gravatar? ) . returns ( false )
38+ avatar_detector . has_custom_avatar? . should be_false
39+ end
40+ end
41+
42+
43+ context "when the user doesn't have an uploaded_avatar_path" do
44+ let ( :user ) { User . new ( use_uploaded_avatar : true ) }
45+ let ( :avatar_detector ) { AvatarDetector . new ( user ) }
46+
47+ describe "when the user has an uploaded avatar" do
48+ before do
49+ user . expects ( :uploaded_avatar_path ) . returns ( "/some/uploaded/file.png" )
50+ end
51+
52+ it "returns true" do
53+ avatar_detector . has_custom_avatar? . should be_true
54+ end
55+
56+ it "doesn't call has_custom_gravatar" do
57+ avatar_detector . expects ( :has_custom_gravatar? ) . never
58+ avatar_detector . has_custom_avatar?
59+ end
60+
61+ end
62+ end
63+
64+ end
65+ end
66+
67+ end
0 commit comments