latompa-fleakr 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/README.rdoc +350 -0
  2. data/Rakefile +41 -0
  3. data/lib/fleakr/api/file_parameter.rb +47 -0
  4. data/lib/fleakr/api/method_request.rb +66 -0
  5. data/lib/fleakr/api/option.rb +175 -0
  6. data/lib/fleakr/api/parameter.rb +35 -0
  7. data/lib/fleakr/api/parameter_list.rb +97 -0
  8. data/lib/fleakr/api/response.rb +35 -0
  9. data/lib/fleakr/api/upload_request.rb +75 -0
  10. data/lib/fleakr/api/value_parameter.rb +36 -0
  11. data/lib/fleakr/api.rb +8 -0
  12. data/lib/fleakr/core_ext/false_class.rb +7 -0
  13. data/lib/fleakr/core_ext/hash.rb +22 -0
  14. data/lib/fleakr/core_ext/true_class.rb +7 -0
  15. data/lib/fleakr/core_ext.rb +3 -0
  16. data/lib/fleakr/objects/authentication_token.rb +60 -0
  17. data/lib/fleakr/objects/comment.rb +49 -0
  18. data/lib/fleakr/objects/contact.rb +37 -0
  19. data/lib/fleakr/objects/error.rb +22 -0
  20. data/lib/fleakr/objects/group.rb +36 -0
  21. data/lib/fleakr/objects/image.rb +50 -0
  22. data/lib/fleakr/objects/photo.rb +148 -0
  23. data/lib/fleakr/objects/photo_context.rb +49 -0
  24. data/lib/fleakr/objects/search.rb +30 -0
  25. data/lib/fleakr/objects/set.rb +50 -0
  26. data/lib/fleakr/objects/tag.rb +56 -0
  27. data/lib/fleakr/objects/user.rb +95 -0
  28. data/lib/fleakr/objects.rb +12 -0
  29. data/lib/fleakr/support/attribute.rb +46 -0
  30. data/lib/fleakr/support/object.rb +110 -0
  31. data/lib/fleakr/support.rb +2 -0
  32. data/lib/fleakr/version.rb +13 -0
  33. data/lib/fleakr.rb +171 -0
  34. data/test/fixtures/auth.checkToken.xml +8 -0
  35. data/test/fixtures/auth.getFullToken.xml +8 -0
  36. data/test/fixtures/auth.getToken.xml +8 -0
  37. data/test/fixtures/contacts.getPublicList.xml +7 -0
  38. data/test/fixtures/groups.pools.getPhotos.xml +7 -0
  39. data/test/fixtures/people.findByEmail.xml +6 -0
  40. data/test/fixtures/people.findByUsername.xml +6 -0
  41. data/test/fixtures/people.getInfo.xml +18 -0
  42. data/test/fixtures/people.getPublicGroups.xml +7 -0
  43. data/test/fixtures/people.getPublicPhotos.xml +7 -0
  44. data/test/fixtures/photos.comments.getList.xml +7 -0
  45. data/test/fixtures/photos.getContext.xml +6 -0
  46. data/test/fixtures/photos.getInfo.xml +20 -0
  47. data/test/fixtures/photos.getSizes.xml +10 -0
  48. data/test/fixtures/photos.search.xml +7 -0
  49. data/test/fixtures/photosets.comments.getList.xml +7 -0
  50. data/test/fixtures/photosets.getList.xml +13 -0
  51. data/test/fixtures/photosets.getPhotos.xml +7 -0
  52. data/test/fixtures/tags.getListPhoto.xml +9 -0
  53. data/test/fixtures/tags.getListUser.xml +10 -0
  54. data/test/fixtures/tags.getRelated.xml +9 -0
  55. data/test/test_helper.rb +141 -0
  56. data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
  57. data/test/unit/fleakr/api/method_request_test.rb +94 -0
  58. data/test/unit/fleakr/api/option_test.rb +179 -0
  59. data/test/unit/fleakr/api/parameter_list_test.rb +176 -0
  60. data/test/unit/fleakr/api/parameter_test.rb +34 -0
  61. data/test/unit/fleakr/api/response_test.rb +49 -0
  62. data/test/unit/fleakr/api/upload_request_test.rb +149 -0
  63. data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
  64. data/test/unit/fleakr/core_ext/false_class_test.rb +13 -0
  65. data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
  66. data/test/unit/fleakr/core_ext/true_class_test.rb +13 -0
  67. data/test/unit/fleakr/objects/authentication_token_test.rb +61 -0
  68. data/test/unit/fleakr/objects/comment_test.rb +66 -0
  69. data/test/unit/fleakr/objects/contact_test.rb +70 -0
  70. data/test/unit/fleakr/objects/error_test.rb +21 -0
  71. data/test/unit/fleakr/objects/group_test.rb +46 -0
  72. data/test/unit/fleakr/objects/image_test.rb +81 -0
  73. data/test/unit/fleakr/objects/photo_context_test.rb +80 -0
  74. data/test/unit/fleakr/objects/photo_test.rb +247 -0
  75. data/test/unit/fleakr/objects/search_test.rb +74 -0
  76. data/test/unit/fleakr/objects/set_test.rb +82 -0
  77. data/test/unit/fleakr/objects/tag_test.rb +98 -0
  78. data/test/unit/fleakr/objects/user_test.rb +91 -0
  79. data/test/unit/fleakr/support/attribute_test.rb +126 -0
  80. data/test/unit/fleakr/support/object_test.rb +129 -0
  81. data/test/unit/fleakr_test.rb +171 -0
  82. metadata +175 -0
@@ -0,0 +1,247 @@
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 :originalsecret => 'sekrit'
101
+ should_have_a_value_for :posted => '1230274722'
102
+ should_have_a_value_for :taken => '2008-12-25 18:26:55'
103
+ should_have_a_value_for :updated => '1230276652'
104
+ should_have_a_value_for :comment_count => '0'
105
+ should_have_a_value_for :url => 'http://www.flickr.com/photos/yes/1'
106
+
107
+ end
108
+
109
+ context "in general" do
110
+
111
+ setup do
112
+ @photo = Photo.new
113
+ @time = Time.parse('2009-08-01 00:00:00')
114
+ end
115
+
116
+ should "be able to retrieve additional information about the current user" do
117
+ photo_id = '1'
118
+ photo = Photo.new
119
+ photo.expects(:id).with().returns(photo_id)
120
+ response = mock_request_cycle :for => 'photos.getInfo', :with => {:photo_id => photo_id}
121
+
122
+ photo.expects(:populate_from).with(response.body)
123
+
124
+ photo.load_info
125
+ end
126
+
127
+ should "have a value for :posted_at" do
128
+ @photo.expects(:posted).with().returns("#{@time.to_i}")
129
+ @photo.posted_at.to_s.should == @time.to_s
130
+ end
131
+
132
+ should "have a value for :taken_at" do
133
+ @photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
134
+ @photo.taken_at.to_s.should == @time.to_s
135
+ end
136
+
137
+ should "have a value for :updated_at" do
138
+ @photo.expects(:updated).with().returns("#{@time.to_i}")
139
+ @photo.updated_at.to_s.should == @time.to_s
140
+ end
141
+
142
+ should "have a collection of images by size" do
143
+ photo = Photo.new
144
+
145
+ small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
146
+
147
+ photo.stubs(:images).returns([small_image, large_image])
148
+
149
+ expected = {
150
+ :square => nil,
151
+ :thumbnail => nil,
152
+ :small => small_image,
153
+ :medium => nil,
154
+ :large => large_image,
155
+ :original => nil
156
+ }
157
+
158
+ photo.send(:images_by_size).should == expected
159
+ end
160
+
161
+ [:square, :thumbnail, :small, :medium, :large, :original].each do |method|
162
+ should "have a reader for the :#{method} image" do
163
+ photo = Photo.new
164
+ image = stub()
165
+
166
+ photo.stubs(:images_by_size).returns(method => image)
167
+ photo.send(method).should == image
168
+ end
169
+ end
170
+
171
+ should "be able to retrieve the context for this photo" do
172
+ id = '1'
173
+
174
+ context = stub()
175
+
176
+ photo = Photo.new
177
+ photo.stubs(:id).with().returns(id)
178
+
179
+ response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
180
+ PhotoContext.expects(:new).with(response.body).returns(context)
181
+
182
+ photo.context.should == context
183
+ end
184
+
185
+ should "memoize the context data" do
186
+ id = '1'
187
+
188
+ context = stub()
189
+
190
+ photo = Photo.new
191
+ photo.stubs(:id).with().returns(id)
192
+
193
+ response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
194
+ PhotoContext.expects(:new).once.returns(context)
195
+
196
+ 2.times { photo.context }
197
+ end
198
+
199
+ should "be able to retrieve the next photo" do
200
+ next_photo = stub()
201
+ context = mock()
202
+ context.expects(:next).with().returns(next_photo)
203
+
204
+ photo = Photo.new
205
+
206
+ photo.expects(:context).with().returns(context)
207
+
208
+ photo.next.should == next_photo
209
+ end
210
+
211
+ should "be able to retrieve the previous photo" do
212
+ previous_photo = stub()
213
+ context = mock()
214
+ context.expects(:previous).with().returns(previous_photo)
215
+
216
+ photo = Photo.new
217
+ photo.expects(:context).with().returns(context)
218
+
219
+ photo.previous.should == previous_photo
220
+ end
221
+
222
+ should "be able to find the owner of the photo" do
223
+ owner = stub()
224
+
225
+ photo = Photo.new
226
+ photo.stubs(:owner_id).with().returns('1')
227
+
228
+ User.expects(:find_by_id).with('1').returns(owner)
229
+
230
+ photo.owner.should == owner
231
+ end
232
+
233
+ should "memoize the owner information" do
234
+ photo = Photo.new
235
+ photo.stubs(:owner_id).with().returns('1')
236
+
237
+ User.expects(:find_by_id).with('1').once.returns(stub())
238
+
239
+ 2.times { photo.owner }
240
+ end
241
+
242
+ end
243
+ end
244
+
245
+ end
246
+
247
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class SearchTest < Test::Unit::TestCase
5
+
6
+ context "An instance of the Search class" do
7
+
8
+ should "be able to generate a list of tags from a single-valued parameter" do
9
+ search = Search.new(:tags => 'foo')
10
+ search.send(:tag_list).should == 'foo'
11
+ end
12
+
13
+ should "be able to generate a list of tags from multi-valued parameters" do
14
+ search = Search.new(:tags => %w(foo bar))
15
+ search.send(:tag_list).should == 'foo,bar'
16
+ end
17
+
18
+ should "be able to create parameters for the search" do
19
+ search = Search.new(:tags => %w(foo bar))
20
+ search.send(:parameters).should == {:tags => 'foo,bar'}
21
+ end
22
+
23
+ should "preserve the original :tags parameter if it is a comma-separated string" do
24
+ search = Search.new(:tags => 'one,two')
25
+ search.send(:parameters).should == {:tags => 'one,two'}
26
+ end
27
+
28
+ should "not have any :tags parameters if none are supplied" do
29
+ search = Search.new({})
30
+ search.send(:parameters).should == {}
31
+ end
32
+
33
+ should "convert the search term into the appropriate parameter" do
34
+ search = Search.new(:text => 'foo')
35
+ search.send(:parameters).should == {:text => 'foo'}
36
+ end
37
+
38
+ should "be able to search photos based on text" do
39
+ response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
40
+ search = Search.new(:text => 'foo')
41
+ search.results
42
+ end
43
+
44
+ should "be able to search photos based on tags" do
45
+ response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
46
+
47
+ photo_1, photo_2 = [stub(), stub()]
48
+ photo_1_doc, photo_2_doc = (response.body/'rsp/photos/photo').map {|doc| doc }
49
+
50
+ Photo.expects(:new).with(photo_1_doc).returns(photo_1)
51
+ Photo.expects(:new).with(photo_2_doc).returns(photo_2)
52
+
53
+ search = Search.new(:tags => %w(one two))
54
+ search.results.should == [photo_1, photo_2]
55
+ end
56
+
57
+ should "memoize the search results" do
58
+ response = stub(:body => Hpricot.XML(read_fixture('photos.search')))
59
+ Fleakr::Api::MethodRequest.expects(:with_response!).with(kind_of(String), kind_of(Hash)).once.returns(response)
60
+
61
+ (response.body/'rsp/photos/photo').each do |doc|
62
+ Photo.expects(:new).with(doc).once
63
+ end
64
+
65
+ search = Search.new(:tags => %w(foo))
66
+
67
+ 2.times { search.results }
68
+ end
69
+
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class SetTest < Test::Unit::TestCase
5
+
6
+ should_have_many :photos, :comments
7
+
8
+ context "The Set class" do
9
+
10
+ should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
11
+
12
+ end
13
+
14
+ context "An instance of the Set class" do
15
+
16
+ context "when populating from an XML document" do
17
+ setup do
18
+ @object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
19
+ end
20
+
21
+ should_have_a_value_for :id => '72157609490909659'
22
+ should_have_a_value_for :title => 'Second Set'
23
+ should_have_a_value_for :description => 'This is the second set.'
24
+ should_have_a_value_for :count => '138'
25
+
26
+ end
27
+
28
+ context "when saving the set" do
29
+ setup do
30
+ @tmp_dir = create_temp_directory
31
+ @set_title = 'set'
32
+
33
+ @set = Set.new
34
+ @set.stubs(:title).with().returns(@set_title)
35
+ end
36
+
37
+ teardown { FileUtils.rm_rf(@tmp_dir) }
38
+
39
+ should "know the prefix string based on the number of photos in the set" do
40
+ set = Set.new
41
+ set.stubs(:count).with().returns('5')
42
+ set.file_prefix(0).should == '1_'
43
+
44
+ set.stubs(:count).with().returns('99')
45
+ set.file_prefix(0).should == '01_'
46
+ end
47
+
48
+ should "save all files of the specified size to the specified directory" do
49
+ image = mock()
50
+ image.expects(:save_to).with("#{@tmp_dir}/set", '1_')
51
+
52
+ photo = stub(:small => image)
53
+
54
+ @set.stubs(:photos).with().returns([photo])
55
+ @set.stubs(:file_prefix).with(0).returns('1_')
56
+
57
+ FileUtils.expects(:mkdir).with("#{@tmp_dir}/set")
58
+
59
+ @set.save_to(@tmp_dir, :small)
60
+ end
61
+
62
+ should "not create the directory if it already exists" do
63
+ FileUtils.mkdir("#{@tmp_dir}/set")
64
+
65
+ @set.stubs(:photos).with().returns([])
66
+
67
+ FileUtils.expects(:mkdir).with("#{@tmp_dir}/set").never
68
+
69
+ @set.save_to(@tmp_dir, :small)
70
+ end
71
+
72
+ should "not raise errors when saving an image size that doesn't exist" do
73
+ @set.stubs(:photos).with().returns([stub(:large => nil)])
74
+ lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,98 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class TagTest < Test::Unit::TestCase
5
+
6
+ context "The Tag class" do
7
+
8
+ should_find_all :tags, :by => :photo_id, :call => 'tags.getListPhoto', :path => 'rsp/photo/tags/tag'
9
+ should_find_all :tags, :by => :user_id, :call => 'tags.getListUser', :path => 'rsp/who/tags/tag'
10
+ end
11
+
12
+ context "An instance of the Tag class" do
13
+
14
+ setup { @tag = Tag.new }
15
+
16
+ context "when populating from the tags_getListPhoto XML data" do
17
+ setup do
18
+ @object = Tag.new(Hpricot.XML(read_fixture('tags.getListPhoto')).at('rsp/photo/tags/tag'))
19
+ end
20
+
21
+ should_have_a_value_for :id => '1'
22
+ should_have_a_value_for :author_id => '15498419@N05'
23
+ should_have_a_value_for :value => 'stu72'
24
+ should_have_a_value_for :raw => 'stu 72'
25
+ should_have_a_value_for :machine_flag => '0'
26
+
27
+ end
28
+
29
+ should "have an author" do
30
+ user = stub()
31
+
32
+ @tag.expects(:author_id).at_least_once.with().returns('1')
33
+
34
+
35
+ User.expects(:find_by_id).with('1').returns(user)
36
+
37
+ @tag.author.should == user
38
+ end
39
+
40
+ should "memoize the author data" do
41
+ @tag.expects(:author_id).at_least_once.with().returns('1')
42
+
43
+ User.expects(:find_by_id).with('1').once.returns(stub())
44
+
45
+ 2.times { @tag.author }
46
+ end
47
+
48
+ should "return nil for author if author_id is not present" do
49
+ @tag.expects(:author_id).with().returns(nil)
50
+
51
+ @tag.author.should be(nil)
52
+ end
53
+
54
+ should "have related tags" do
55
+ @tag.expects(:value).with().returns('foo')
56
+
57
+ response = mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
58
+
59
+ stubs = []
60
+ elements = (response.body/'rsp/tags/tag').map
61
+
62
+ elements.each do |element|
63
+ stub = stub()
64
+ stubs << stub
65
+
66
+ Tag.expects(:new).with(element).returns(stub)
67
+ end
68
+
69
+ @tag.related.should == stubs
70
+ end
71
+
72
+ should "memoize the data for related tags" do
73
+ @tag.expects(:value).with().returns('foo')
74
+
75
+ mock_request_cycle :for => 'tags.getRelated', :with => {:tag => 'foo'}
76
+
77
+ 2.times { @tag.related }
78
+ end
79
+
80
+ should "be able to generate a string representation of itself" do
81
+ @tag.expects(:value).with().returns('foo')
82
+ @tag.to_s.should == 'foo'
83
+ end
84
+
85
+ should "know that it is not a machine tag" do
86
+ @tag.expects(:machine_flag).with().returns('0')
87
+ @tag.machine?.should be(false)
88
+ end
89
+
90
+ should "know that it is a machine tag" do
91
+ @tag.expects(:machine_flag).with().returns('1')
92
+ @tag.machine?.should be(true)
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class UserTest < Test::Unit::TestCase
5
+
6
+ should_search_by :user_id
7
+
8
+ should_have_many :photos, :groups, :sets, :contacts, :tags
9
+
10
+ should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :with => :load_info
11
+ should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info
12
+
13
+ context "The User class" do
14
+
15
+ should_find_one :user, :by => :username, :call => 'people.findByUsername', :path => 'rsp/user'
16
+ should_find_one :user, :by => :email, :with => :find_email, :call => 'people.findByEmail', :path => 'rsp/user'
17
+ should_find_one :user, :by => :id, :with => :user_id, :call => 'people.getInfo', :path => 'rsp/person'
18
+
19
+ end
20
+
21
+ context "An instance of User" do
22
+ context "when populating the object from an XML document" do
23
+ setup do
24
+ @object = User.new(Hpricot.XML(read_fixture('people.findByUsername')))
25
+ @object.populate_from(Hpricot.XML(read_fixture('people.getInfo')))
26
+ end
27
+
28
+ should_have_a_value_for :id => '31066442@N69'
29
+ should_have_a_value_for :username => 'frootpantz'
30
+ should_have_a_value_for :name => 'Sir Froot Pantz'
31
+ should_have_a_value_for :location => 'The Moon'
32
+ should_have_a_value_for :photos_url => 'http://www.flickr.com/photos/frootpantz/'
33
+ should_have_a_value_for :profile_url => 'http://www.flickr.com/people/frootpantz/'
34
+ should_have_a_value_for :photos_count => '3907'
35
+ should_have_a_value_for :icon_server => '30'
36
+ should_have_a_value_for :icon_farm => '1'
37
+ should_have_a_value_for :pro => '1'
38
+ should_have_a_value_for :admin => '0'
39
+
40
+ end
41
+
42
+ context "in general" do
43
+
44
+ setup { @user = User.new }
45
+
46
+ should "be able to retrieve additional information about the current user" do
47
+ response = mock_request_cycle :for => 'people.getInfo', :with => {:user_id => @user.id}
48
+ @user.expects(:populate_from).with(response.body)
49
+
50
+ @user.load_info
51
+ end
52
+
53
+ should "be able to generate an icon URL when the :icon_server value is greater than zero" do
54
+ @user.stubs(:icon_server).with().returns('1')
55
+ @user.stubs(:icon_farm).with().returns('2')
56
+ @user.stubs(:id).with().returns('45')
57
+
58
+ @user.icon_url.should == 'http://farm2.static.flickr.com/1/buddyicons/45.jpg'
59
+ end
60
+
61
+ should "return the default icon URL when the :icon_server value is zero" do
62
+ @user.stubs(:icon_server).with().returns('0')
63
+ @user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
64
+ end
65
+
66
+ should "return the default icon URL when the :icon_server value is nil" do
67
+ @user.stubs(:icon_server).with().returns(nil)
68
+ @user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
69
+ end
70
+
71
+ should "return a boolean value for :pro?" do
72
+ @user.stubs(:pro).with().returns('0')
73
+ @user.pro?.should be(false)
74
+
75
+ @user.stubs(:pro).with().returns('1')
76
+ @user.pro?.should be(true)
77
+ end
78
+
79
+ should "return a boolean value for :admin?" do
80
+ @user.stubs(:admin).with().returns('0')
81
+ @user.admin?.should be(false)
82
+
83
+ @user.stubs(:admin).with().returns('1')
84
+ @user.admin?.should be(true)
85
+ end
86
+
87
+ end
88
+ end
89
+
90
+ end
91
+ end