reagent-fleakr 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/fleakr/api/option.rb +6 -6
- data/lib/fleakr/version.rb +2 -2
- data/lib/fleakr.rb +2 -1
- data/test/test_helper.rb +9 -8
- data/test/unit/fleakr/api/file_parameter_test.rb +8 -8
- data/test/unit/fleakr/api/method_request_test.rb +11 -10
- data/test/unit/fleakr/api/option_test.rb +29 -29
- data/test/unit/fleakr/api/parameter_list_test.rb +22 -22
- data/test/unit/fleakr/api/parameter_test.rb +5 -5
- data/test/unit/fleakr/api/response_test.rb +6 -6
- data/test/unit/fleakr/api/upload_request_test.rb +28 -24
- data/test/unit/fleakr/api/value_parameter_test.rb +6 -6
- data/test/unit/fleakr/core_ext/false_class_test.rb +2 -2
- data/test/unit/fleakr/core_ext/hash_test.rb +6 -6
- data/test/unit/fleakr/core_ext/true_class_test.rb +2 -2
- data/test/unit/fleakr/objects/authentication_token_test.rb +6 -6
- data/test/unit/fleakr/objects/comment_test.rb +8 -8
- data/test/unit/fleakr/objects/contact_test.rb +8 -5
- data/test/unit/fleakr/objects/error_test.rb +2 -2
- data/test/unit/fleakr/objects/group_test.rb +5 -5
- data/test/unit/fleakr/objects/image_test.rb +6 -6
- data/test/unit/fleakr/objects/photo_context_test.rb +11 -11
- data/test/unit/fleakr/objects/photo_test.rb +32 -29
- data/test/unit/fleakr/objects/search_test.rb +9 -9
- data/test/unit/fleakr/objects/set_test.rb +9 -9
- data/test/unit/fleakr/objects/tag_test.rb +12 -12
- data/test/unit/fleakr/objects/user_test.rb +10 -10
- data/test/unit/fleakr/support/attribute_test.rb +21 -21
- data/test/unit/fleakr/support/object_test.rb +17 -17
- data/test/unit/fleakr_test.rb +24 -24
- metadata +3 -3
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Api
|
4
4
|
class ResponseTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of Response" do
|
7
7
|
|
8
|
-
|
8
|
+
should "provide the response body as an Hpricot element" do
|
9
9
|
response_xml = '<xml>'
|
10
10
|
hpricot_stub = stub()
|
11
11
|
|
@@ -15,7 +15,7 @@ module Fleakr::Api
|
|
15
15
|
response.body.should == hpricot_stub
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
should "memoize the Hpricot document" do
|
19
19
|
response = Response.new('<xml>')
|
20
20
|
|
21
21
|
Hpricot.expects(:XML).with(kind_of(String)).once.returns(stub())
|
@@ -23,19 +23,19 @@ module Fleakr::Api
|
|
23
23
|
2.times { response.body }
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
should "know if there are errors in the response" do
|
27
27
|
response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
|
28
28
|
response = Response.new(response_xml)
|
29
29
|
|
30
30
|
response.error?.should be(true)
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
should "not have an error if there are no errors in the XML" do
|
34
34
|
response = Response.new(read_fixture('people.findByUsername'))
|
35
35
|
response.error.should be(nil)
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
should "have an error if there is an error in the response" do
|
39
39
|
response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
|
40
40
|
response = Response.new(response_xml)
|
41
41
|
|
@@ -3,14 +3,14 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Api
|
4
4
|
class UploadRequestTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the UploadRequest class" do
|
7
7
|
|
8
|
-
|
8
|
+
setup do
|
9
9
|
@secret = 'sekrit'
|
10
10
|
Fleakr.stubs(:shared_secret).with().returns(@secret)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
should "have a collection of upload_options" do
|
14
14
|
request = UploadRequest.new('foo', :create, {:title => 'foo', :tags => %w(a b)})
|
15
15
|
|
16
16
|
option_1, option_2 = [stub(:to_hash => {:one => 'value_1'}), stub(:to_hash => {:two => 'value_2'})]
|
@@ -21,20 +21,24 @@ module Fleakr::Api
|
|
21
21
|
request.upload_options.should == {:one => 'value_1', :two => 'value_2'}
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
should "create a file parameter on initialization" do
|
25
25
|
filename = '/path/to/image.jpg'
|
26
26
|
|
27
27
|
parameter = stub()
|
28
28
|
FileParameter.expects(:new).with('photo', filename).returns(parameter)
|
29
29
|
|
30
|
-
parameter_list = mock()
|
30
|
+
parameter_list = mock()
|
31
|
+
parameter_list.expects(:<<).with(parameter)
|
32
|
+
|
31
33
|
ParameterList.expects(:new).with({}).returns(parameter_list)
|
32
34
|
|
33
35
|
UploadRequest.new(filename)
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
option = stub
|
38
|
+
should "allow setting options on initialization" do
|
39
|
+
option = stub()
|
40
|
+
option.stubs(:to_hash).with().returns({:title => 'foo'})
|
41
|
+
|
38
42
|
Option.expects(:for).with(:title, 'foo').returns(option)
|
39
43
|
|
40
44
|
ParameterList.expects(:new).with({:title => 'foo'}).returns(stub(:<<))
|
@@ -44,36 +48,36 @@ module Fleakr::Api
|
|
44
48
|
|
45
49
|
context "after initialization" do
|
46
50
|
|
47
|
-
|
51
|
+
setup { ParameterList.stubs(:new).returns(stub(:<< => nil)) }
|
48
52
|
|
49
|
-
|
53
|
+
should "default the type to :create" do
|
50
54
|
request = UploadRequest.new('file')
|
51
55
|
request.type.should == :create
|
52
56
|
end
|
53
57
|
|
54
|
-
|
58
|
+
should "allow setting the type to :update" do
|
55
59
|
request = UploadRequest.new('file', :update)
|
56
60
|
request.type.should == :update
|
57
61
|
end
|
58
62
|
|
59
|
-
|
63
|
+
should "know the endpoint_uri" do
|
60
64
|
request = UploadRequest.new('filename')
|
61
65
|
request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/upload/')
|
62
66
|
end
|
63
67
|
|
64
|
-
|
68
|
+
should "know the endpoint_uri for an :update request" do
|
65
69
|
request = UploadRequest.new('filename', :update)
|
66
70
|
request.__send__(:endpoint_uri).should == URI.parse('http://api.flickr.com/services/replace/')
|
67
71
|
end
|
68
72
|
|
69
|
-
|
73
|
+
should "only parse the endpoint URI once" do
|
70
74
|
request = UploadRequest.new('filename')
|
71
75
|
URI.expects(:parse).with(kind_of(String)).once.returns('uri')
|
72
76
|
|
73
77
|
2.times { request.__send__(:endpoint_uri) }
|
74
78
|
end
|
75
79
|
|
76
|
-
|
80
|
+
should "have a collection of required headers" do
|
77
81
|
form_data = 'data'
|
78
82
|
|
79
83
|
request = UploadRequest.new('filename')
|
@@ -87,28 +91,28 @@ module Fleakr::Api
|
|
87
91
|
request.headers.should == expected
|
88
92
|
end
|
89
93
|
|
90
|
-
|
94
|
+
should "be able to send a POST request to the API service" do
|
91
95
|
request = UploadRequest.new('filename')
|
92
96
|
|
93
|
-
uri = stub
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
97
|
+
uri = stub()
|
98
|
+
uri.stubs(:host).with().returns('host')
|
99
|
+
uri.stubs(:path).with().returns('path')
|
100
|
+
uri.stubs(:port).with().returns(80)
|
98
101
|
|
99
102
|
request.stubs(:endpoint_uri).with().returns(uri)
|
100
103
|
|
101
104
|
request.stubs(:headers).with().returns('header' => 'value')
|
102
105
|
request.parameters.stubs(:to_form).with().returns('form')
|
103
106
|
|
104
|
-
http = mock
|
107
|
+
http = mock()
|
108
|
+
http.expects(:post).with('path', 'form', {'header' => 'value'})
|
105
109
|
|
106
110
|
Net::HTTP.expects(:start).with('host', 80).yields(http).returns(stub(:body))
|
107
111
|
|
108
112
|
request.send
|
109
113
|
end
|
110
114
|
|
111
|
-
|
115
|
+
should "get back a response from a POST operation" do
|
112
116
|
response = stub()
|
113
117
|
|
114
118
|
Net::HTTP.expects(:start).with(kind_of(String), kind_of(Fixnum)).returns(stub(:body => '<xml>'))
|
@@ -118,7 +122,7 @@ module Fleakr::Api
|
|
118
122
|
request.send.should == response
|
119
123
|
end
|
120
124
|
|
121
|
-
|
125
|
+
should "be able to make a full request and response cycle" do
|
122
126
|
filename = 'filename'
|
123
127
|
response = stub(:error? => false)
|
124
128
|
|
@@ -126,7 +130,7 @@ module Fleakr::Api
|
|
126
130
|
UploadRequest.with_response!(filename).should == response
|
127
131
|
end
|
128
132
|
|
129
|
-
|
133
|
+
should "raise an exception when the full request / response cycle has errors" do
|
130
134
|
filename = 'filename'
|
131
135
|
response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
|
132
136
|
|
@@ -3,29 +3,29 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Api
|
4
4
|
class ValueParameterTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the ValueParameter class" do
|
7
7
|
|
8
|
-
|
8
|
+
should "have a value" do
|
9
9
|
parameter = ValueParameter.new('foo', 'bar')
|
10
10
|
parameter.value.should == 'bar'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
should "know how to generate the query representation of itself" do
|
14
14
|
parameter = ValueParameter.new('foo', 'bar')
|
15
15
|
parameter.to_query.should == 'foo=bar'
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
should "escape the value when generating the query representation" do
|
19
19
|
parameter = ValueParameter.new('foo', 'Mr. Crystal?')
|
20
20
|
parameter.to_query.should == 'foo=Mr.+Crystal%3F'
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
should "use an empty string when generating a query if the parameter value is nil" do
|
24
24
|
parameter = ValueParameter.new('foo', nil)
|
25
25
|
parameter.to_query.should == 'foo='
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
should "know how to generate the form representation of itself" do
|
29
29
|
parameter = ValueParameter.new('foo', 'bar')
|
30
30
|
expected =
|
31
31
|
'Content-Disposition: form-data; name="foo"' + "\r\n" +
|
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
2
2
|
|
3
3
|
class FalseClassTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
context "An instance of the FalseClass class" do
|
6
6
|
|
7
|
-
|
7
|
+
should "have 0 as its integer value" do
|
8
8
|
false.to_i.should == 0
|
9
9
|
end
|
10
10
|
|
@@ -2,27 +2,27 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
2
2
|
|
3
3
|
class HashTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
context "An instance of Hash" do
|
6
6
|
context "when extracting key/value pairs" do
|
7
7
|
|
8
|
-
|
8
|
+
setup do
|
9
9
|
@hash = {:one => 'two', :three => 'four'}
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
should "return a hash with the matching key/value pairs" do
|
13
13
|
@hash.extract!(:one).should == {:one => 'two'}
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
should "return an empty hash if the key isn't found" do
|
17
17
|
@hash.extract!(:foo).should == {}
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
should "alter the original hash when a value is extracted" do
|
21
21
|
@hash.extract!(:one)
|
22
22
|
@hash.should == {:three => 'four'}
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
should "be able to extract multiple keys" do
|
26
26
|
@hash.extract!(:one, :three, :missing).should == {:one => 'two', :three => 'four'}
|
27
27
|
end
|
28
28
|
|
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
2
2
|
|
3
3
|
class TrueClassTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
context "An instance of the TrueClass class" do
|
6
6
|
|
7
|
-
|
7
|
+
should "have 1 as its integer value" do
|
8
8
|
true.to_i.should == 1
|
9
9
|
end
|
10
10
|
|
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class AuthenticationTokenTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "The AuthenticationToken class" do
|
7
7
|
|
8
|
-
|
8
|
+
should "be able to create an instance from a mini_token" do
|
9
9
|
token = '123-123-123'
|
10
10
|
auth_token = stub()
|
11
11
|
|
@@ -16,7 +16,7 @@ module Fleakr::Objects
|
|
16
16
|
AuthenticationToken.from_mini_token(token).should == auth_token
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
should "be able to create an instance from an auth_token" do
|
20
20
|
token = 'abc123'
|
21
21
|
auth_token = stub()
|
22
22
|
|
@@ -27,7 +27,7 @@ module Fleakr::Objects
|
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
|
-
|
30
|
+
should "be able to create an instance from a frob" do
|
31
31
|
frob = '12345678901234567-abcde89012fg3456-7890123'
|
32
32
|
auth_token = stub()
|
33
33
|
|
@@ -39,11 +39,11 @@ module Fleakr::Objects
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
context "An instance of the AuthenticationToken class" do
|
43
43
|
|
44
44
|
context "when populating from an XML document" do
|
45
45
|
|
46
|
-
|
46
|
+
setup do
|
47
47
|
@object = AuthenticationToken.new(Hpricot.XML(read_fixture('auth.getFullToken')))
|
48
48
|
end
|
49
49
|
|
@@ -3,17 +3,17 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class CommentTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "The Comment class" do
|
7
7
|
|
8
8
|
should_find_all :comments, :by => :photo_id, :call => 'photos.comments.getList', :path => 'rsp/comments/comment'
|
9
9
|
should_find_all :comments, :by => :set_id, :using => :photoset_id, :call => 'photosets.comments.getList', :path => 'rsp/comments/comment'
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
context "An instance of the Comment class" do
|
14
14
|
|
15
15
|
context "when populating from the photos_comments_getList XML data" do
|
16
|
-
|
16
|
+
setup do
|
17
17
|
@object = Comment.new(Hpricot.XML(read_fixture('photos.comments.getList')).at('rsp/comments/comment'))
|
18
18
|
end
|
19
19
|
|
@@ -27,21 +27,21 @@ module Fleakr::Objects
|
|
27
27
|
|
28
28
|
context "in general" do
|
29
29
|
|
30
|
-
|
30
|
+
setup { @comment = Comment.new }
|
31
31
|
|
32
|
-
|
32
|
+
should "have a value for :created_at" do
|
33
33
|
@comment.expects(:created).with().returns('1239217523')
|
34
34
|
Time.expects(:at).with(1239217523).returns('time')
|
35
35
|
|
36
36
|
@comment.created_at.should == 'time'
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
should "use the body as the string representation" do
|
40
40
|
@comment.expects(:body).with().returns('bod')
|
41
41
|
@comment.to_s.should == 'bod'
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
should "be able to find the author of the comment" do
|
45
45
|
author = stub()
|
46
46
|
|
47
47
|
|
@@ -51,7 +51,7 @@ module Fleakr::Objects
|
|
51
51
|
@comment.author.should == author
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
should "memoize the owner information" do
|
55
55
|
@comment.stubs(:author_id).with().returns('1')
|
56
56
|
|
57
57
|
User.expects(:find_by_id).with('1').once.returns(stub())
|
@@ -3,15 +3,18 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ContactTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "The Contact class" do
|
7
7
|
|
8
8
|
should "return a list of users for a specified user's contacts" do
|
9
|
-
user_1, user_2 = [stub(), stub()]
|
9
|
+
# user_1, user_2 = [stub(), stub()]
|
10
|
+
user_1 = stub()
|
11
|
+
user_2 = stub()
|
12
|
+
|
10
13
|
contact_1, contact_2 = [stub(:to_user => user_1), stub(:to_user => user_2)]
|
11
14
|
|
12
15
|
response = mock_request_cycle :for => 'contacts.getPublicList', :with => {:user_id => '1'}
|
13
16
|
|
14
|
-
contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').
|
17
|
+
contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').to_a
|
15
18
|
|
16
19
|
Contact.stubs(:new).with(contact_1_doc).returns(contact_1)
|
17
20
|
Contact.stubs(:new).with(contact_2_doc).returns(contact_2)
|
@@ -21,9 +24,9 @@ module Fleakr::Objects
|
|
21
24
|
|
22
25
|
end
|
23
26
|
|
24
|
-
|
27
|
+
context "An instance of the Contact class" do
|
25
28
|
context "when populating from an XML document" do
|
26
|
-
|
29
|
+
setup do
|
27
30
|
@object = Contact.new(Hpricot.XML(read_fixture('contacts.getPublicList')).at('contacts/contact'))
|
28
31
|
end
|
29
32
|
|
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ErrorTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the Error class" do
|
7
7
|
|
8
|
-
|
8
|
+
should "have a code and a message" do
|
9
9
|
response_xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rsp stat=\"fail\">\n\t<err code=\"1\" msg=\"User not found\" />\n</rsp>\n"
|
10
10
|
|
11
11
|
error = Error.new(Hpricot.XML(response_xml))
|
@@ -7,16 +7,16 @@ module Fleakr::Objects
|
|
7
7
|
|
8
8
|
should_search_by :group_id
|
9
9
|
|
10
|
-
|
10
|
+
context "The Group class" do
|
11
11
|
|
12
12
|
should_find_all :groups, :by => :user_id, :call => 'people.getPublicGroups', :path => 'rsp/groups/group'
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
context "An instance of the Group class" do
|
17
17
|
context "when initializing from an Hpricot document" do
|
18
18
|
|
19
|
-
|
19
|
+
setup do
|
20
20
|
doc = Hpricot.XML(read_fixture('people.getPublicGroups')).at('rsp/groups/group')
|
21
21
|
@object = Group.new(doc)
|
22
22
|
end
|
@@ -27,13 +27,13 @@ module Fleakr::Objects
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
should "know that the group is adult-only" do
|
31
31
|
group = Group.new
|
32
32
|
group.stubs(:adult_flag).with().returns('1')
|
33
33
|
group.adult?.should be(true)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
should "know that the group is not adult-only" do
|
37
37
|
group = Group.new
|
38
38
|
group.stubs(:adult_flag).with().returns('0')
|
39
39
|
group.adult?.should be(false)
|
@@ -3,17 +3,17 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class ImageTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "The Image class" do
|
7
7
|
|
8
8
|
should_find_all :images, :by => :photo_id, :call => 'photos.getSizes', :path => 'sizes/size'
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
context "An instance of the Image class" do
|
13
13
|
|
14
14
|
context "when populating the object from an XML document" do
|
15
15
|
|
16
|
-
|
16
|
+
setup do
|
17
17
|
@object = Image.new(Hpricot.XML(read_fixture('photos.getSizes')).at('sizes/size'))
|
18
18
|
end
|
19
19
|
|
@@ -27,7 +27,7 @@ module Fleakr::Objects
|
|
27
27
|
|
28
28
|
context "in general" do
|
29
29
|
|
30
|
-
|
30
|
+
should "know its filename" do
|
31
31
|
image = Image.new
|
32
32
|
image.stubs(:url).with().returns('http://flickr.com/photos/foobar.jpg')
|
33
33
|
|
@@ -36,7 +36,7 @@ module Fleakr::Objects
|
|
36
36
|
|
37
37
|
context "when saving the file" do
|
38
38
|
|
39
|
-
|
39
|
+
setup do
|
40
40
|
@tmp_dir = create_temp_directory
|
41
41
|
|
42
42
|
@url = 'http://host.com/image.jpg'
|
@@ -50,7 +50,7 @@ module Fleakr::Objects
|
|
50
50
|
Net::HTTP.expects(:get).with(URI.parse(@url)).returns(@image_data)
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
teardown do
|
54
54
|
FileUtils.rm_rf(@tmp_dir)
|
55
55
|
end
|
56
56
|
|
@@ -3,12 +3,12 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class PhotoContextTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the PhotoContext class" do
|
7
7
|
|
8
|
-
|
8
|
+
setup { @context = PhotoContext.new }
|
9
9
|
|
10
10
|
context "when populating from the photos_getContext XML data" do
|
11
|
-
|
11
|
+
setup do
|
12
12
|
@object = PhotoContext.new(Hpricot.XML(read_fixture('photos.getContext')))
|
13
13
|
end
|
14
14
|
|
@@ -18,27 +18,27 @@ module Fleakr::Objects
|
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
should "know that there is a previous photo" do
|
22
22
|
@context.expects(:previous_id).with().returns('1')
|
23
23
|
@context.previous?.should be(true)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
should "know that there isn't a previous photo" do
|
27
27
|
@context.expects(:previous_id).with().returns('0')
|
28
28
|
@context.previous?.should be(false)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
should "know that there is a next photo" do
|
32
32
|
@context.expects(:next_id).with().returns('1')
|
33
33
|
@context.next?.should be(true)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
should "know that there isn't a next photo" do
|
37
37
|
@context.expects(:next_id).with().returns('0')
|
38
38
|
@context.next?.should be(false)
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
should "find the previous photo" do
|
42
42
|
photo = stub()
|
43
43
|
|
44
44
|
@context.expects(:previous_id).with().returns('1')
|
@@ -49,14 +49,14 @@ module Fleakr::Objects
|
|
49
49
|
@context.previous.should == photo
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
should "not try to find the previous photo if it doesn't exist" do
|
53
53
|
@context.expects(:previous?).with().returns(false)
|
54
54
|
Photo.expects(:find_by_id).never
|
55
55
|
|
56
56
|
@context.previous.should be(nil)
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
should "find the next photo" do
|
60
60
|
photo = stub()
|
61
61
|
@context.expects(:next_id).with().returns('1')
|
62
62
|
@context.expects(:next?).with().returns(true)
|
@@ -66,7 +66,7 @@ module Fleakr::Objects
|
|
66
66
|
@context.next.should == photo
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
should "not try to find the next photo if it doesn't exist" do
|
70
70
|
@context.expects(:next?).with().returns(false)
|
71
71
|
Photo.expects(:find_by_id).never
|
72
72
|
|