slaskis-fleakr 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/README.rdoc +350 -0
- data/Rakefile +41 -0
- data/lib/fleakr.rb +164 -0
- data/lib/fleakr/api.rb +8 -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/core_ext.rb +3 -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/objects.rb +13 -0
- data/lib/fleakr/objects/authentication_token.rb +60 -0
- data/lib/fleakr/objects/comment.rb +49 -0
- data/lib/fleakr/objects/contact.rb +31 -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 +147 -0
- data/lib/fleakr/objects/photo_context.rb +49 -0
- data/lib/fleakr/objects/search.rb +30 -0
- data/lib/fleakr/objects/set.rb +51 -0
- data/lib/fleakr/objects/tag.rb +56 -0
- data/lib/fleakr/objects/user.rb +95 -0
- data/lib/fleakr/support.rb +2 -0
- data/lib/fleakr/support/attribute.rb +46 -0
- data/lib/fleakr/support/object.rb +112 -0
- data/lib/fleakr/version.rb +13 -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 +61 -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 +246 -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,61 @@
|
|
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
|
+
should "return a list of users for a specified user's contacts" do
|
9
|
+
# user_1, user_2 = [stub(), stub()]
|
10
|
+
user_1 = stub()
|
11
|
+
user_2 = stub()
|
12
|
+
|
13
|
+
contact_1, contact_2 = [stub(:to_user => user_1), stub(:to_user => user_2)]
|
14
|
+
|
15
|
+
response = mock_request_cycle :for => 'contacts.getPublicList', :with => {:user_id => '1'}
|
16
|
+
|
17
|
+
contact_1_doc, contact_2_doc = (response.body/'rsp/contacts/contact').to_a
|
18
|
+
|
19
|
+
Contact.stubs(:new).with(contact_1_doc).returns(contact_1)
|
20
|
+
Contact.stubs(:new).with(contact_2_doc).returns(contact_2)
|
21
|
+
|
22
|
+
Contact.find_all_by_user_id('1').should == [user_1, user_2]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "An instance of the Contact class" do
|
28
|
+
context "when populating from an XML document" do
|
29
|
+
setup do
|
30
|
+
@object = Contact.new(Hpricot.XML(read_fixture('contacts.getPublicList')).at('contacts/contact'))
|
31
|
+
end
|
32
|
+
|
33
|
+
should_have_a_value_for :id => '9302864@N42'
|
34
|
+
should_have_a_value_for :username => 'blinky'
|
35
|
+
should_have_a_value_for :icon_server => '2263'
|
36
|
+
should_have_a_value_for :icon_farm => '3'
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "in general" do
|
41
|
+
|
42
|
+
should "be able to convert to a user" do
|
43
|
+
contact = Contact.new
|
44
|
+
user = mock()
|
45
|
+
|
46
|
+
User.stubs(:new).returns(user)
|
47
|
+
|
48
|
+
[:id, :username, :icon_server, :icon_farm].each do |method|
|
49
|
+
contact.stubs(method).with().returns(method.to_s)
|
50
|
+
user.expects("#{method}=".to_sym).with(method.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
contact.to_user.should == user
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
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
|
@@ -0,0 +1,246 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
+
|
3
|
+
module Fleakr::Objects
|
4
|
+
class PhotoTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should_have_many :images, :tags, :comments
|
7
|
+
|
8
|
+
should_autoload_when_accessing :posted, :taken, :updated, :comment_count, :with => :load_info
|
9
|
+
should_autoload_when_accessing :url, :description, :with => :load_info
|
10
|
+
|
11
|
+
context "The Photo class" do
|
12
|
+
|
13
|
+
should_find_all :photos, :by => :user_id, :call => 'people.getPublicPhotos', :path => 'rsp/photos/photo'
|
14
|
+
should_find_all :photos, :by => :set_id, :using => :photoset_id, :call => 'photosets.getPhotos', :path => 'rsp/photoset/photo'
|
15
|
+
should_find_all :photos, :by => :group_id, :call => 'groups.pools.getPhotos', :path => 'rsp/photos/photo'
|
16
|
+
|
17
|
+
should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo'
|
18
|
+
|
19
|
+
# TODO: refactor these 2 tests
|
20
|
+
should "be able to upload a photo and return the new photo information" do
|
21
|
+
filename = '/path/to/mugshot.jpg'
|
22
|
+
photo = stub()
|
23
|
+
|
24
|
+
response = stub()
|
25
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
26
|
+
|
27
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
|
28
|
+
Photo.expects(:find_by_id).with('123').returns(photo)
|
29
|
+
|
30
|
+
Photo.upload(filename).should == photo
|
31
|
+
end
|
32
|
+
|
33
|
+
should "be able to pass additional options when uploading a new file" do
|
34
|
+
filename = '/path/to/mugshot.jpg'
|
35
|
+
photo = stub()
|
36
|
+
|
37
|
+
response = stub()
|
38
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
39
|
+
|
40
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
|
41
|
+
Photo.expects(:find_by_id).with('123').returns(photo)
|
42
|
+
|
43
|
+
Photo.upload(filename, :title => 'foo').should == photo
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "An instance of the Photo class" do
|
49
|
+
|
50
|
+
should "be able to replace the associated photo data" do
|
51
|
+
filename = '/path/to/file.jpg'
|
52
|
+
response = stub(:body => 'body')
|
53
|
+
|
54
|
+
params = {:photo_id => '1'}
|
55
|
+
|
56
|
+
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :update, params).returns(response)
|
57
|
+
|
58
|
+
photo = Photo.new
|
59
|
+
photo.stubs(:id).returns('1')
|
60
|
+
photo.expects(:populate_from).with('body')
|
61
|
+
|
62
|
+
photo.replace_with(filename).should == photo
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when populating from the people_getPublicPhotos XML data" do
|
66
|
+
setup do
|
67
|
+
@object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
|
68
|
+
end
|
69
|
+
|
70
|
+
should_have_a_value_for :id => '2924549350'
|
71
|
+
should_have_a_value_for :title => 'Photo #1'
|
72
|
+
should_have_a_value_for :farm_id => '4'
|
73
|
+
should_have_a_value_for :server_id => '3250'
|
74
|
+
should_have_a_value_for :secret => 'cbc1804258'
|
75
|
+
should_have_a_value_for :owner_id => '21775151@N06'
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when populating from the photo upload XML data" do
|
80
|
+
setup do
|
81
|
+
@object = Photo.new(Hpricot.XML('<photoid>123</photoid>'))
|
82
|
+
end
|
83
|
+
|
84
|
+
should_have_a_value_for :id => '123'
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when populating from the photos_getInfo XML data" do
|
88
|
+
setup do
|
89
|
+
@object = Photo.new(Hpricot.XML(read_fixture('photos.getInfo')))
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
should_have_a_value_for :id => '1'
|
94
|
+
should_have_a_value_for :title => 'Tree'
|
95
|
+
should_have_a_value_for :description => 'A Tree'
|
96
|
+
should_have_a_value_for :farm_id => '4'
|
97
|
+
should_have_a_value_for :server_id => '3085'
|
98
|
+
should_have_a_value_for :owner_id => '31066442@N69'
|
99
|
+
should_have_a_value_for :secret => 'secret'
|
100
|
+
should_have_a_value_for :posted => '1230274722'
|
101
|
+
should_have_a_value_for :taken => '2008-12-25 18:26:55'
|
102
|
+
should_have_a_value_for :updated => '1230276652'
|
103
|
+
should_have_a_value_for :comment_count => '0'
|
104
|
+
should_have_a_value_for :url => 'http://www.flickr.com/photos/yes/1'
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
context "in general" do
|
109
|
+
|
110
|
+
setup do
|
111
|
+
@photo = Photo.new
|
112
|
+
@time = Time.parse('2009-08-01 00:00:00')
|
113
|
+
end
|
114
|
+
|
115
|
+
should "be able to retrieve additional information about the current user" do
|
116
|
+
photo_id = '1'
|
117
|
+
photo = Photo.new
|
118
|
+
photo.expects(:id).with().returns(photo_id)
|
119
|
+
response = mock_request_cycle :for => 'photos.getInfo', :with => {:photo_id => photo_id}
|
120
|
+
|
121
|
+
photo.expects(:populate_from).with(response.body)
|
122
|
+
|
123
|
+
photo.load_info
|
124
|
+
end
|
125
|
+
|
126
|
+
should "have a value for :posted_at" do
|
127
|
+
@photo.expects(:posted).with().returns("#{@time.to_i}")
|
128
|
+
@photo.posted_at.to_s.should == @time.to_s
|
129
|
+
end
|
130
|
+
|
131
|
+
should "have a value for :taken_at" do
|
132
|
+
@photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
|
133
|
+
@photo.taken_at.to_s.should == @time.to_s
|
134
|
+
end
|
135
|
+
|
136
|
+
should "have a value for :updated_at" do
|
137
|
+
@photo.expects(:updated).with().returns("#{@time.to_i}")
|
138
|
+
@photo.updated_at.to_s.should == @time.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
should "have a collection of images by size" do
|
142
|
+
photo = Photo.new
|
143
|
+
|
144
|
+
small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
|
145
|
+
|
146
|
+
photo.stubs(:images).returns([small_image, large_image])
|
147
|
+
|
148
|
+
expected = {
|
149
|
+
:square => nil,
|
150
|
+
:thumbnail => nil,
|
151
|
+
:small => small_image,
|
152
|
+
:medium => nil,
|
153
|
+
:large => large_image,
|
154
|
+
:original => nil
|
155
|
+
}
|
156
|
+
|
157
|
+
photo.send(:images_by_size).should == expected
|
158
|
+
end
|
159
|
+
|
160
|
+
[:square, :thumbnail, :small, :medium, :large, :original].each do |method|
|
161
|
+
should "have a reader for the :#{method} image" do
|
162
|
+
photo = Photo.new
|
163
|
+
image = stub()
|
164
|
+
|
165
|
+
photo.stubs(:images_by_size).returns(method => image)
|
166
|
+
photo.send(method).should == image
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
should "be able to retrieve the context for this photo" do
|
171
|
+
id = '1'
|
172
|
+
|
173
|
+
context = stub()
|
174
|
+
|
175
|
+
photo = Photo.new
|
176
|
+
photo.stubs(:id).with().returns(id)
|
177
|
+
|
178
|
+
response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
|
179
|
+
PhotoContext.expects(:new).with(response.body).returns(context)
|
180
|
+
|
181
|
+
photo.context.should == context
|
182
|
+
end
|
183
|
+
|
184
|
+
should "memoize the context data" do
|
185
|
+
id = '1'
|
186
|
+
|
187
|
+
context = stub()
|
188
|
+
|
189
|
+
photo = Photo.new
|
190
|
+
photo.stubs(:id).with().returns(id)
|
191
|
+
|
192
|
+
response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
|
193
|
+
PhotoContext.expects(:new).once.returns(context)
|
194
|
+
|
195
|
+
2.times { photo.context }
|
196
|
+
end
|
197
|
+
|
198
|
+
should "be able to retrieve the next photo" do
|
199
|
+
next_photo = stub()
|
200
|
+
context = mock()
|
201
|
+
context.expects(:next).with().returns(next_photo)
|
202
|
+
|
203
|
+
photo = Photo.new
|
204
|
+
|
205
|
+
photo.expects(:context).with().returns(context)
|
206
|
+
|
207
|
+
photo.next.should == next_photo
|
208
|
+
end
|
209
|
+
|
210
|
+
should "be able to retrieve the previous photo" do
|
211
|
+
previous_photo = stub()
|
212
|
+
context = mock()
|
213
|
+
context.expects(:previous).with().returns(previous_photo)
|
214
|
+
|
215
|
+
photo = Photo.new
|
216
|
+
photo.expects(:context).with().returns(context)
|
217
|
+
|
218
|
+
photo.previous.should == previous_photo
|
219
|
+
end
|
220
|
+
|
221
|
+
should "be able to find the owner of the photo" do
|
222
|
+
owner = stub()
|
223
|
+
|
224
|
+
photo = Photo.new
|
225
|
+
photo.stubs(:owner_id).with().returns('1')
|
226
|
+
|
227
|
+
User.expects(:find_by_id).with('1').returns(owner)
|
228
|
+
|
229
|
+
photo.owner.should == owner
|
230
|
+
end
|
231
|
+
|
232
|
+
should "memoize the owner information" do
|
233
|
+
photo = Photo.new
|
234
|
+
photo.stubs(:owner_id).with().returns('1')
|
235
|
+
|
236
|
+
User.expects(:find_by_id).with('1').once.returns(stub())
|
237
|
+
|
238
|
+
2.times { photo.owner }
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|