latompa-fleakr 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +350 -0
- data/Rakefile +41 -0
- data/lib/fleakr/api/file_parameter.rb +47 -0
- data/lib/fleakr/api/method_request.rb +66 -0
- data/lib/fleakr/api/option.rb +175 -0
- data/lib/fleakr/api/parameter.rb +35 -0
- data/lib/fleakr/api/parameter_list.rb +97 -0
- data/lib/fleakr/api/response.rb +35 -0
- data/lib/fleakr/api/upload_request.rb +75 -0
- data/lib/fleakr/api/value_parameter.rb +36 -0
- data/lib/fleakr/api.rb +8 -0
- data/lib/fleakr/core_ext/false_class.rb +7 -0
- data/lib/fleakr/core_ext/hash.rb +22 -0
- data/lib/fleakr/core_ext/true_class.rb +7 -0
- data/lib/fleakr/core_ext.rb +3 -0
- data/lib/fleakr/objects/authentication_token.rb +60 -0
- data/lib/fleakr/objects/comment.rb +49 -0
- data/lib/fleakr/objects/contact.rb +37 -0
- data/lib/fleakr/objects/error.rb +22 -0
- data/lib/fleakr/objects/group.rb +36 -0
- data/lib/fleakr/objects/image.rb +50 -0
- data/lib/fleakr/objects/photo.rb +148 -0
- data/lib/fleakr/objects/photo_context.rb +49 -0
- data/lib/fleakr/objects/search.rb +30 -0
- data/lib/fleakr/objects/set.rb +50 -0
- data/lib/fleakr/objects/tag.rb +56 -0
- data/lib/fleakr/objects/user.rb +95 -0
- data/lib/fleakr/objects.rb +12 -0
- data/lib/fleakr/support/attribute.rb +46 -0
- data/lib/fleakr/support/object.rb +110 -0
- data/lib/fleakr/support.rb +2 -0
- data/lib/fleakr/version.rb +13 -0
- data/lib/fleakr.rb +171 -0
- data/test/fixtures/auth.checkToken.xml +8 -0
- data/test/fixtures/auth.getFullToken.xml +8 -0
- data/test/fixtures/auth.getToken.xml +8 -0
- data/test/fixtures/contacts.getPublicList.xml +7 -0
- data/test/fixtures/groups.pools.getPhotos.xml +7 -0
- data/test/fixtures/people.findByEmail.xml +6 -0
- data/test/fixtures/people.findByUsername.xml +6 -0
- data/test/fixtures/people.getInfo.xml +18 -0
- data/test/fixtures/people.getPublicGroups.xml +7 -0
- data/test/fixtures/people.getPublicPhotos.xml +7 -0
- data/test/fixtures/photos.comments.getList.xml +7 -0
- data/test/fixtures/photos.getContext.xml +6 -0
- data/test/fixtures/photos.getInfo.xml +20 -0
- data/test/fixtures/photos.getSizes.xml +10 -0
- data/test/fixtures/photos.search.xml +7 -0
- data/test/fixtures/photosets.comments.getList.xml +7 -0
- data/test/fixtures/photosets.getList.xml +13 -0
- data/test/fixtures/photosets.getPhotos.xml +7 -0
- data/test/fixtures/tags.getListPhoto.xml +9 -0
- data/test/fixtures/tags.getListUser.xml +10 -0
- data/test/fixtures/tags.getRelated.xml +9 -0
- data/test/test_helper.rb +141 -0
- data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
- data/test/unit/fleakr/api/method_request_test.rb +94 -0
- data/test/unit/fleakr/api/option_test.rb +179 -0
- data/test/unit/fleakr/api/parameter_list_test.rb +176 -0
- data/test/unit/fleakr/api/parameter_test.rb +34 -0
- data/test/unit/fleakr/api/response_test.rb +49 -0
- data/test/unit/fleakr/api/upload_request_test.rb +149 -0
- data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
- data/test/unit/fleakr/core_ext/false_class_test.rb +13 -0
- data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
- data/test/unit/fleakr/core_ext/true_class_test.rb +13 -0
- data/test/unit/fleakr/objects/authentication_token_test.rb +61 -0
- data/test/unit/fleakr/objects/comment_test.rb +66 -0
- data/test/unit/fleakr/objects/contact_test.rb +70 -0
- data/test/unit/fleakr/objects/error_test.rb +21 -0
- data/test/unit/fleakr/objects/group_test.rb +46 -0
- data/test/unit/fleakr/objects/image_test.rb +81 -0
- data/test/unit/fleakr/objects/photo_context_test.rb +80 -0
- data/test/unit/fleakr/objects/photo_test.rb +247 -0
- data/test/unit/fleakr/objects/search_test.rb +74 -0
- data/test/unit/fleakr/objects/set_test.rb +82 -0
- data/test/unit/fleakr/objects/tag_test.rb +98 -0
- data/test/unit/fleakr/objects/user_test.rb +91 -0
- data/test/unit/fleakr/support/attribute_test.rb +126 -0
- data/test/unit/fleakr/support/object_test.rb +129 -0
- data/test/unit/fleakr_test.rb +171 -0
- metadata +175 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Api
|
4
|
+
class ValueParameterTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the ValueParameter class" do
|
7
|
+
|
8
|
+
should "have a value" do
|
9
|
+
parameter = ValueParameter.new('foo', 'bar')
|
10
|
+
parameter.value.should == 'bar'
|
11
|
+
end
|
12
|
+
|
13
|
+
should "know how to generate the query representation of itself" do
|
14
|
+
parameter = ValueParameter.new('foo', 'bar')
|
15
|
+
parameter.to_query.should == 'foo=bar'
|
16
|
+
end
|
17
|
+
|
18
|
+
should "escape the value when generating the query representation" do
|
19
|
+
parameter = ValueParameter.new('foo', 'Mr. Crystal?')
|
20
|
+
parameter.to_query.should == 'foo=Mr.+Crystal%3F'
|
21
|
+
end
|
22
|
+
|
23
|
+
should "use an empty string when generating a query if the parameter value is nil" do
|
24
|
+
parameter = ValueParameter.new('foo', nil)
|
25
|
+
parameter.to_query.should == 'foo='
|
26
|
+
end
|
27
|
+
|
28
|
+
should "know how to generate the form representation of itself" do
|
29
|
+
parameter = ValueParameter.new('foo', 'bar')
|
30
|
+
expected =
|
31
|
+
'Content-Disposition: form-data; name="foo"' + "\r\n" +
|
32
|
+
"\r\n" +
|
33
|
+
"bar\r\n"
|
34
|
+
|
35
|
+
parameter.to_form.should == expected
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
class HashTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "An instance of Hash" do
|
6
|
+
context "when extracting key/value pairs" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@hash = {:one => 'two', :three => 'four'}
|
10
|
+
end
|
11
|
+
|
12
|
+
should "return a hash with the matching key/value pairs" do
|
13
|
+
@hash.extract!(:one).should == {:one => 'two'}
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return an empty hash if the key isn't found" do
|
17
|
+
@hash.extract!(:foo).should == {}
|
18
|
+
end
|
19
|
+
|
20
|
+
should "alter the original hash when a value is extracted" do
|
21
|
+
@hash.extract!(:one)
|
22
|
+
@hash.should == {:three => 'four'}
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be able to extract multiple keys" do
|
26
|
+
@hash.extract!(:one, :three, :missing).should == {:one => 'two', :three => 'four'}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class AuthenticationTokenTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The AuthenticationToken class" do
|
7
|
+
|
8
|
+
should "be able to create an instance from a mini_token" do
|
9
|
+
token = '123-123-123'
|
10
|
+
auth_token = stub()
|
11
|
+
|
12
|
+
response = mock_request_cycle :for => 'auth.getFullToken', :with => {:mini_token => token, :authenticate? => false}
|
13
|
+
|
14
|
+
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
15
|
+
|
16
|
+
AuthenticationToken.from_mini_token(token).should == auth_token
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to create an instance from an auth_token" do
|
20
|
+
token = 'abc123'
|
21
|
+
auth_token = stub()
|
22
|
+
|
23
|
+
response = mock_request_cycle :for => 'auth.checkToken', :with => {:auth_token => token, :authenticate? => false}
|
24
|
+
|
25
|
+
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
26
|
+
AuthenticationToken.from_auth_token(token).should == auth_token
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
should "be able to create an instance from a frob" do
|
31
|
+
frob = '12345678901234567-abcde89012fg3456-7890123'
|
32
|
+
auth_token = stub()
|
33
|
+
|
34
|
+
response = mock_request_cycle :for => 'auth.getToken', :with => {:frob => frob, :authenticate? => false}
|
35
|
+
|
36
|
+
AuthenticationToken.expects(:new).with(response.body).returns(auth_token)
|
37
|
+
AuthenticationToken.from_frob(frob).should == auth_token
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "An instance of the AuthenticationToken class" do
|
43
|
+
|
44
|
+
context "when populating from an XML document" do
|
45
|
+
|
46
|
+
setup do
|
47
|
+
@object = AuthenticationToken.new(Hpricot.XML(read_fixture('auth.getFullToken')))
|
48
|
+
end
|
49
|
+
|
50
|
+
should_have_a_value_for :value => 'abc-123'
|
51
|
+
should_have_a_value_for :permissions => 'delete'
|
52
|
+
should_have_a_value_for :user_id => '31066442@N69'
|
53
|
+
should_have_a_value_for :full_name => 'Sir Froot Pants'
|
54
|
+
should_have_a_value_for :user_name => 'frootpantz'
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class CommentTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Comment class" do
|
7
|
+
|
8
|
+
should_find_all :comments, :by => :photo_id, :call => 'photos.comments.getList', :path => 'rsp/comments/comment'
|
9
|
+
should_find_all :comments, :by => :set_id, :using => :photoset_id, :call => 'photosets.comments.getList', :path => 'rsp/comments/comment'
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
context "An instance of the Comment class" do
|
14
|
+
|
15
|
+
context "when populating from the photos_comments_getList XML data" do
|
16
|
+
setup do
|
17
|
+
@object = Comment.new(Hpricot.XML(read_fixture('photos.comments.getList')).at('rsp/comments/comment'))
|
18
|
+
end
|
19
|
+
|
20
|
+
should_have_a_value_for :id => '1'
|
21
|
+
should_have_a_value_for :author_id => '10490170@N04'
|
22
|
+
should_have_a_value_for :created => '1239217523'
|
23
|
+
should_have_a_value_for :url => 'http://www.flickr.com/photos/frootpantz/3422268412/#comment72157616515348062'
|
24
|
+
should_have_a_value_for :body => 'comment one'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context "in general" do
|
29
|
+
|
30
|
+
setup { @comment = Comment.new }
|
31
|
+
|
32
|
+
should "have a value for :created_at" do
|
33
|
+
@comment.expects(:created).with().returns('1239217523')
|
34
|
+
Time.expects(:at).with(1239217523).returns('time')
|
35
|
+
|
36
|
+
@comment.created_at.should == 'time'
|
37
|
+
end
|
38
|
+
|
39
|
+
should "use the body as the string representation" do
|
40
|
+
@comment.expects(:body).with().returns('bod')
|
41
|
+
@comment.to_s.should == 'bod'
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be able to find the author of the comment" do
|
45
|
+
author = stub()
|
46
|
+
|
47
|
+
|
48
|
+
@comment.stubs(:author_id).with().returns('1')
|
49
|
+
User.expects(:find_by_id).with('1').returns(author)
|
50
|
+
|
51
|
+
@comment.author.should == author
|
52
|
+
end
|
53
|
+
|
54
|
+
should "memoize the owner information" do
|
55
|
+
@comment.stubs(:author_id).with().returns('1')
|
56
|
+
|
57
|
+
User.expects(:find_by_id).with('1').once.returns(stub())
|
58
|
+
|
59
|
+
2.times { @comment.author }
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class ContactTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Contact class" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@user_1 = stub()
|
10
|
+
@user_2 = stub()
|
11
|
+
@contact_1, @contact_2 = [stub(:to_user => @user_1), stub(:to_user => @user_2)]
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
should "return a list of users for a specified user's contacts" do
|
16
|
+
response = mock_request_cycle :for => 'contacts.getPublicList', :with => {:user_id => '1'}
|
17
|
+
|
18
|
+
contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').to_a
|
19
|
+
|
20
|
+
Contact.stubs(:new).with(contact_1_doc).returns(@contact_1)
|
21
|
+
Contact.stubs(:new).with(contact_2_doc).returns(@contact_2)
|
22
|
+
Contact.find_all_by_user_id('1').should == [@user_1, @user_2]
|
23
|
+
end
|
24
|
+
|
25
|
+
should "return a list of users for an authenticated user" do
|
26
|
+
response = mock_request_cycle :for => 'contacts.getList', :with => {}
|
27
|
+
contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').to_a
|
28
|
+
|
29
|
+
Contact.stubs(:new).with(contact_1_doc).returns(@contact_1)
|
30
|
+
Contact.stubs(:new).with(contact_2_doc).returns(@contact_2)
|
31
|
+
Contact.find_all_contacts().should == [@user_1, @user_2]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
context "An instance of the Contact class" do
|
37
|
+
context "when populating from an XML document" do
|
38
|
+
setup do
|
39
|
+
@object = Contact.new(Hpricot.XML(read_fixture('contacts.getPublicList')).at('contacts/contact'))
|
40
|
+
end
|
41
|
+
|
42
|
+
should_have_a_value_for :id => '9302864@N42'
|
43
|
+
should_have_a_value_for :username => 'blinky'
|
44
|
+
should_have_a_value_for :icon_server => '2263'
|
45
|
+
should_have_a_value_for :icon_farm => '3'
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "in general" do
|
50
|
+
|
51
|
+
should "be able to convert to a user" do
|
52
|
+
contact = Contact.new
|
53
|
+
user = mock()
|
54
|
+
|
55
|
+
User.stubs(:new).returns(user)
|
56
|
+
|
57
|
+
[:id, :username, :icon_server, :icon_farm].each do |method|
|
58
|
+
contact.stubs(method).with().returns(method.to_s)
|
59
|
+
user.expects("#{method}=".to_sym).with(method.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
contact.to_user.should == user
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class ErrorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the Error class" do
|
7
|
+
|
8
|
+
should "have a code and a message" do
|
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
|
+
|
11
|
+
error = Error.new(Hpricot.XML(response_xml))
|
12
|
+
|
13
|
+
error.code.should == '1'
|
14
|
+
error.message.should == 'User not found'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class GroupTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should_have_many :photos
|
7
|
+
|
8
|
+
should_search_by :group_id
|
9
|
+
|
10
|
+
context "The Group class" do
|
11
|
+
|
12
|
+
should_find_all :groups, :by => :user_id, :call => 'people.getPublicGroups', :path => 'rsp/groups/group'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
context "An instance of the Group class" do
|
17
|
+
context "when initializing from an Hpricot document" do
|
18
|
+
|
19
|
+
setup do
|
20
|
+
doc = Hpricot.XML(read_fixture('people.getPublicGroups')).at('rsp/groups/group')
|
21
|
+
@object = Group.new(doc)
|
22
|
+
end
|
23
|
+
|
24
|
+
should_have_a_value_for :id => '13378274@N00'
|
25
|
+
should_have_a_value_for :name => 'Group #1'
|
26
|
+
should_have_a_value_for :adult_flag => '1'
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
should "know that the group is adult-only" do
|
31
|
+
group = Group.new
|
32
|
+
group.stubs(:adult_flag).with().returns('1')
|
33
|
+
group.adult?.should be(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "know that the group is not adult-only" do
|
37
|
+
group = Group.new
|
38
|
+
group.stubs(:adult_flag).with().returns('0')
|
39
|
+
group.adult?.should be(false)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class ImageTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "The Image class" do
|
7
|
+
|
8
|
+
should_find_all :images, :by => :photo_id, :call => 'photos.getSizes', :path => 'sizes/size'
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
context "An instance of the Image class" do
|
13
|
+
|
14
|
+
context "when populating the object from an XML document" do
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@object = Image.new(Hpricot.XML(read_fixture('photos.getSizes')).at('sizes/size'))
|
18
|
+
end
|
19
|
+
|
20
|
+
should_have_a_value_for :size => 'Square'
|
21
|
+
should_have_a_value_for :width => '75'
|
22
|
+
should_have_a_value_for :height => '75'
|
23
|
+
should_have_a_value_for :url => 'http://farm4.static.flickr.com/3093/2409912100_71e14ed08a_s.jpg'
|
24
|
+
should_have_a_value_for :page => 'http://www.flickr.com/photos/the_decapitator/2409912100/sizes/sq/'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context "in general" do
|
29
|
+
|
30
|
+
should "know its filename" do
|
31
|
+
image = Image.new
|
32
|
+
image.stubs(:url).with().returns('http://flickr.com/photos/foobar.jpg')
|
33
|
+
|
34
|
+
image.filename.should == 'foobar.jpg'
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when saving the file" do
|
38
|
+
|
39
|
+
setup do
|
40
|
+
@tmp_dir = create_temp_directory
|
41
|
+
|
42
|
+
@url = 'http://host.com/image.jpg'
|
43
|
+
@image_filename = 'image.jpg'
|
44
|
+
|
45
|
+
@image = Image.new
|
46
|
+
@image.stubs(:url).with().returns(@url)
|
47
|
+
@image.stubs(:filename).with().returns(@image_filename)
|
48
|
+
|
49
|
+
@image_data = 'image_data'
|
50
|
+
Net::HTTP.expects(:get).with(URI.parse(@url)).returns(@image_data)
|
51
|
+
end
|
52
|
+
|
53
|
+
teardown do
|
54
|
+
FileUtils.rm_rf(@tmp_dir)
|
55
|
+
end
|
56
|
+
|
57
|
+
should "be able to save to a directory with the original filename" do
|
58
|
+
@image.save_to(@tmp_dir)
|
59
|
+
File.read("#{@tmp_dir}/image.jpg").should == @image_data
|
60
|
+
end
|
61
|
+
|
62
|
+
should "be able to save to a specified file" do
|
63
|
+
existing_file = "#{@tmp_dir}/existing_file.jpg"
|
64
|
+
|
65
|
+
FileUtils.touch(existing_file)
|
66
|
+
|
67
|
+
@image.save_to(existing_file)
|
68
|
+
File.read(existing_file).should == @image_data
|
69
|
+
end
|
70
|
+
|
71
|
+
should "be able to save the file using a specified prefix" do
|
72
|
+
@image.save_to(@tmp_dir, '001_')
|
73
|
+
File.read("#{@tmp_dir}/001_image.jpg").should == @image_data
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class PhotoContextTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "An instance of the PhotoContext class" do
|
7
|
+
|
8
|
+
setup { @context = PhotoContext.new }
|
9
|
+
|
10
|
+
context "when populating from the photos_getContext XML data" do
|
11
|
+
setup do
|
12
|
+
@object = PhotoContext.new(Hpricot.XML(read_fixture('photos.getContext')))
|
13
|
+
end
|
14
|
+
|
15
|
+
should_have_a_value_for :count => '5584'
|
16
|
+
should_have_a_value_for :next_id => '12343'
|
17
|
+
should_have_a_value_for :previous_id => '12345'
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
should "know that there is a previous photo" do
|
22
|
+
@context.expects(:previous_id).with().returns('1')
|
23
|
+
@context.previous?.should be(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "know that there isn't a previous photo" do
|
27
|
+
@context.expects(:previous_id).with().returns('0')
|
28
|
+
@context.previous?.should be(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "know that there is a next photo" do
|
32
|
+
@context.expects(:next_id).with().returns('1')
|
33
|
+
@context.next?.should be(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "know that there isn't a next photo" do
|
37
|
+
@context.expects(:next_id).with().returns('0')
|
38
|
+
@context.next?.should be(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "find the previous photo" do
|
42
|
+
photo = stub()
|
43
|
+
|
44
|
+
@context.expects(:previous_id).with().returns('1')
|
45
|
+
@context.expects(:previous?).with().returns(true)
|
46
|
+
|
47
|
+
Photo.expects(:find_by_id).with('1').returns(photo)
|
48
|
+
|
49
|
+
@context.previous.should == photo
|
50
|
+
end
|
51
|
+
|
52
|
+
should "not try to find the previous photo if it doesn't exist" do
|
53
|
+
@context.expects(:previous?).with().returns(false)
|
54
|
+
Photo.expects(:find_by_id).never
|
55
|
+
|
56
|
+
@context.previous.should be(nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "find the next photo" do
|
60
|
+
photo = stub()
|
61
|
+
@context.expects(:next_id).with().returns('1')
|
62
|
+
@context.expects(:next?).with().returns(true)
|
63
|
+
|
64
|
+
Photo.expects(:find_by_id).with('1').returns(photo)
|
65
|
+
|
66
|
+
@context.next.should == photo
|
67
|
+
end
|
68
|
+
|
69
|
+
should "not try to find the next photo if it doesn't exist" do
|
70
|
+
@context.expects(:next?).with().returns(false)
|
71
|
+
Photo.expects(:find_by_id).never
|
72
|
+
|
73
|
+
@context.next.should be(nil)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|