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/README.rdoc +6 -1
- data/Rakefile +1 -1
- data/lib/fleakr.rb +2 -1
- data/lib/fleakr/api/option.rb +6 -6
- data/lib/fleakr/version.rb +2 -2
- 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
@@ -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
|
|
@@ -8,7 +8,7 @@ module Fleakr::Objects
|
|
8
8
|
should_autoload_when_accessing :posted, :taken, :updated, :comment_count, :with => :load_info
|
9
9
|
should_autoload_when_accessing :url, :description, :with => :load_info
|
10
10
|
|
11
|
-
|
11
|
+
context "The Photo class" do
|
12
12
|
|
13
13
|
should_find_all :photos, :by => :user_id, :call => 'people.getPublicPhotos', :path => 'rsp/photos/photo'
|
14
14
|
should_find_all :photos, :by => :set_id, :using => :photoset_id, :call => 'photosets.getPhotos', :path => 'rsp/photoset/photo'
|
@@ -17,13 +17,12 @@ module Fleakr::Objects
|
|
17
17
|
should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo'
|
18
18
|
|
19
19
|
# TODO: refactor these 2 tests
|
20
|
-
|
20
|
+
should "be able to upload a photo and return the new photo information" do
|
21
21
|
filename = '/path/to/mugshot.jpg'
|
22
22
|
photo = stub()
|
23
23
|
|
24
|
-
response = stub
|
25
|
-
|
26
|
-
end
|
24
|
+
response = stub()
|
25
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
27
26
|
|
28
27
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
|
29
28
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
@@ -31,13 +30,12 @@ module Fleakr::Objects
|
|
31
30
|
Photo.upload(filename).should == photo
|
32
31
|
end
|
33
32
|
|
34
|
-
|
33
|
+
should "be able to pass additional options when uploading a new file" do
|
35
34
|
filename = '/path/to/mugshot.jpg'
|
36
35
|
photo = stub()
|
37
36
|
|
38
|
-
response = stub
|
39
|
-
|
40
|
-
end
|
37
|
+
response = stub()
|
38
|
+
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
41
39
|
|
42
40
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
|
43
41
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
@@ -47,9 +45,9 @@ module Fleakr::Objects
|
|
47
45
|
|
48
46
|
end
|
49
47
|
|
50
|
-
|
48
|
+
context "An instance of the Photo class" do
|
51
49
|
|
52
|
-
|
50
|
+
should "be able to replace the associated photo data" do
|
53
51
|
filename = '/path/to/file.jpg'
|
54
52
|
response = stub(:body => 'body')
|
55
53
|
|
@@ -65,7 +63,7 @@ module Fleakr::Objects
|
|
65
63
|
end
|
66
64
|
|
67
65
|
context "when populating from the people_getPublicPhotos XML data" do
|
68
|
-
|
66
|
+
setup do
|
69
67
|
@object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
|
70
68
|
end
|
71
69
|
|
@@ -79,7 +77,7 @@ module Fleakr::Objects
|
|
79
77
|
end
|
80
78
|
|
81
79
|
context "when populating from the photo upload XML data" do
|
82
|
-
|
80
|
+
setup do
|
83
81
|
@object = Photo.new(Hpricot.XML('<photoid>123</photoid>'))
|
84
82
|
end
|
85
83
|
|
@@ -87,7 +85,7 @@ module Fleakr::Objects
|
|
87
85
|
end
|
88
86
|
|
89
87
|
context "when populating from the photos_getInfo XML data" do
|
90
|
-
|
88
|
+
setup do
|
91
89
|
@object = Photo.new(Hpricot.XML(read_fixture('photos.getInfo')))
|
92
90
|
|
93
91
|
end
|
@@ -109,12 +107,12 @@ module Fleakr::Objects
|
|
109
107
|
|
110
108
|
context "in general" do
|
111
109
|
|
112
|
-
|
110
|
+
setup do
|
113
111
|
@photo = Photo.new
|
114
112
|
@time = Time.parse('2009-08-01 00:00:00')
|
115
113
|
end
|
116
114
|
|
117
|
-
|
115
|
+
should "be able to retrieve additional information about the current user" do
|
118
116
|
photo_id = '1'
|
119
117
|
photo = Photo.new
|
120
118
|
photo.expects(:id).with().returns(photo_id)
|
@@ -125,22 +123,22 @@ module Fleakr::Objects
|
|
125
123
|
photo.load_info
|
126
124
|
end
|
127
125
|
|
128
|
-
|
126
|
+
should "have a value for :posted_at" do
|
129
127
|
@photo.expects(:posted).with().returns("#{@time.to_i}")
|
130
128
|
@photo.posted_at.to_s.should == @time.to_s
|
131
129
|
end
|
132
130
|
|
133
|
-
|
131
|
+
should "have a value for :taken_at" do
|
134
132
|
@photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
|
135
133
|
@photo.taken_at.to_s.should == @time.to_s
|
136
134
|
end
|
137
135
|
|
138
|
-
|
136
|
+
should "have a value for :updated_at" do
|
139
137
|
@photo.expects(:updated).with().returns("#{@time.to_i}")
|
140
138
|
@photo.updated_at.to_s.should == @time.to_s
|
141
139
|
end
|
142
140
|
|
143
|
-
|
141
|
+
should "have a collection of images by size" do
|
144
142
|
photo = Photo.new
|
145
143
|
|
146
144
|
small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
|
@@ -160,7 +158,7 @@ module Fleakr::Objects
|
|
160
158
|
end
|
161
159
|
|
162
160
|
[:square, :thumbnail, :small, :medium, :large, :original].each do |method|
|
163
|
-
|
161
|
+
should "have a reader for the :#{method} image" do
|
164
162
|
photo = Photo.new
|
165
163
|
image = stub()
|
166
164
|
|
@@ -169,7 +167,7 @@ module Fleakr::Objects
|
|
169
167
|
end
|
170
168
|
end
|
171
169
|
|
172
|
-
|
170
|
+
should "be able to retrieve the context for this photo" do
|
173
171
|
id = '1'
|
174
172
|
|
175
173
|
context = stub()
|
@@ -183,7 +181,7 @@ module Fleakr::Objects
|
|
183
181
|
photo.context.should == context
|
184
182
|
end
|
185
183
|
|
186
|
-
|
184
|
+
should "memoize the context data" do
|
187
185
|
id = '1'
|
188
186
|
|
189
187
|
context = stub()
|
@@ -197,25 +195,30 @@ module Fleakr::Objects
|
|
197
195
|
2.times { photo.context }
|
198
196
|
end
|
199
197
|
|
200
|
-
|
198
|
+
should "be able to retrieve the next photo" do
|
201
199
|
next_photo = stub()
|
200
|
+
context = mock()
|
201
|
+
context.expects(:next).with().returns(next_photo)
|
202
202
|
|
203
203
|
photo = Photo.new
|
204
|
-
|
204
|
+
|
205
|
+
photo.expects(:context).with().returns(context)
|
205
206
|
|
206
207
|
photo.next.should == next_photo
|
207
208
|
end
|
208
209
|
|
209
|
-
|
210
|
+
should "be able to retrieve the previous photo" do
|
210
211
|
previous_photo = stub()
|
212
|
+
context = mock()
|
213
|
+
context.expects(:previous).with().returns(previous_photo)
|
211
214
|
|
212
215
|
photo = Photo.new
|
213
|
-
photo.expects(:context).with().returns(
|
216
|
+
photo.expects(:context).with().returns(context)
|
214
217
|
|
215
218
|
photo.previous.should == previous_photo
|
216
219
|
end
|
217
220
|
|
218
|
-
|
221
|
+
should "be able to find the owner of the photo" do
|
219
222
|
owner = stub()
|
220
223
|
|
221
224
|
photo = Photo.new
|
@@ -226,7 +229,7 @@ module Fleakr::Objects
|
|
226
229
|
photo.owner.should == owner
|
227
230
|
end
|
228
231
|
|
229
|
-
|
232
|
+
should "memoize the owner information" do
|
230
233
|
photo = Photo.new
|
231
234
|
photo.stubs(:owner_id).with().returns('1')
|
232
235
|
|
@@ -3,45 +3,45 @@ require File.dirname(__FILE__) + '/../../../test_helper'
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class SearchTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
6
|
+
context "An instance of the Search class" do
|
7
7
|
|
8
|
-
|
8
|
+
should "be able to generate a list of tags from a single-valued parameter" do
|
9
9
|
search = Search.new(:tags => 'foo')
|
10
10
|
search.send(:tag_list).should == 'foo'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
should "be able to generate a list of tags from multi-valued parameters" do
|
14
14
|
search = Search.new(:tags => %w(foo bar))
|
15
15
|
search.send(:tag_list).should == 'foo,bar'
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
should "be able to create parameters for the search" do
|
19
19
|
search = Search.new(:tags => %w(foo bar))
|
20
20
|
search.send(:parameters).should == {:tags => 'foo,bar'}
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
should "preserve the original :tags parameter if it is a comma-separated string" do
|
24
24
|
search = Search.new(:tags => 'one,two')
|
25
25
|
search.send(:parameters).should == {:tags => 'one,two'}
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
should "not have any :tags parameters if none are supplied" do
|
29
29
|
search = Search.new({})
|
30
30
|
search.send(:parameters).should == {}
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
should "convert the search term into the appropriate parameter" do
|
34
34
|
search = Search.new(:text => 'foo')
|
35
35
|
search.send(:parameters).should == {:text => 'foo'}
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
should "be able to search photos based on text" do
|
39
39
|
response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
|
40
40
|
search = Search.new(:text => 'foo')
|
41
41
|
search.results
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
should "be able to search photos based on tags" do
|
45
45
|
response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
|
46
46
|
|
47
47
|
photo_1, photo_2 = [stub(), stub()]
|
@@ -5,16 +5,16 @@ module Fleakr::Objects
|
|
5
5
|
|
6
6
|
should_have_many :photos, :comments
|
7
7
|
|
8
|
-
|
8
|
+
context "The Set class" do
|
9
9
|
|
10
10
|
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
|
11
11
|
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
context "An instance of the Set class" do
|
15
15
|
|
16
16
|
context "when populating from an XML document" do
|
17
|
-
|
17
|
+
setup do
|
18
18
|
@object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
|
19
19
|
end
|
20
20
|
|
@@ -26,7 +26,7 @@ module Fleakr::Objects
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "when saving the set" do
|
29
|
-
|
29
|
+
setup do
|
30
30
|
@tmp_dir = create_temp_directory
|
31
31
|
@set_title = 'set'
|
32
32
|
|
@@ -34,9 +34,9 @@ module Fleakr::Objects
|
|
34
34
|
@set.stubs(:title).with().returns(@set_title)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
teardown { FileUtils.rm_rf(@tmp_dir) }
|
38
38
|
|
39
|
-
|
39
|
+
should "know the prefix string based on the number of photos in the set" do
|
40
40
|
set = Set.new
|
41
41
|
set.stubs(:count).with().returns('5')
|
42
42
|
set.file_prefix(0).should == '1_'
|
@@ -45,7 +45,7 @@ module Fleakr::Objects
|
|
45
45
|
set.file_prefix(0).should == '01_'
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
should "save all files of the specified size to the specified directory" do
|
49
49
|
image = mock()
|
50
50
|
image.expects(:save_to).with("#{@tmp_dir}/set", '1_')
|
51
51
|
|
@@ -59,7 +59,7 @@ module Fleakr::Objects
|
|
59
59
|
@set.save_to(@tmp_dir, :small)
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
should "not create the directory if it already exists" do
|
63
63
|
FileUtils.mkdir("#{@tmp_dir}/set")
|
64
64
|
|
65
65
|
@set.stubs(:photos).with().returns([])
|
@@ -69,7 +69,7 @@ module Fleakr::Objects
|
|
69
69
|
@set.save_to(@tmp_dir, :small)
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
should "not raise errors when saving an image size that doesn't exist" do
|
73
73
|
@set.stubs(:photos).with().returns([stub(:large => nil)])
|
74
74
|
lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
|
75
75
|
end
|