fleakr 0.6.3 → 0.7.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 +88 -57
- data/Rakefile +28 -9
- data/lib/fleakr.rb +25 -31
- data/lib/fleakr/api/option.rb +34 -34
- data/lib/fleakr/api/parameter_list.rb +23 -23
- data/lib/fleakr/objects.rb +4 -1
- data/lib/fleakr/objects/metadata.rb +35 -0
- data/lib/fleakr/objects/metadata_collection.rb +36 -0
- data/lib/fleakr/objects/photo.rb +15 -11
- data/lib/fleakr/objects/set.rb +17 -13
- data/lib/fleakr/objects/url.rb +83 -0
- data/lib/fleakr/objects/user.rb +8 -0
- data/lib/fleakr/support.rb +3 -1
- data/lib/fleakr/support/attribute.rb +2 -2
- data/lib/fleakr/support/object.rb +44 -29
- data/lib/fleakr/support/url_expander.rb +37 -0
- data/lib/fleakr/support/utility.rb +66 -0
- data/lib/fleakr/version.rb +5 -5
- data/test/fixtures/photos.getExif.xml +362 -0
- data/test/test_helper.rb +44 -47
- data/test/unit/fleakr/api/authentication_request_test.rb +12 -12
- data/test/unit/fleakr/api/file_parameter_test.rb +15 -15
- data/test/unit/fleakr/api/method_request_test.rb +1 -1
- data/test/unit/fleakr/api/option_test.rb +44 -44
- data/test/unit/fleakr/api/parameter_list_test.rb +40 -40
- data/test/unit/fleakr/api/response_test.rb +10 -10
- data/test/unit/fleakr/api/upload_request_test.rb +28 -28
- data/test/unit/fleakr/api/value_parameter_test.rb +10 -10
- data/test/unit/fleakr/core_ext/false_class_test.rb +5 -5
- data/test/unit/fleakr/core_ext/hash_test.rb +9 -9
- data/test/unit/fleakr/core_ext/true_class_test.rb +5 -5
- data/test/unit/fleakr/objects/authentication_token_test.rb +23 -23
- data/test/unit/fleakr/objects/collection_test.rb +23 -23
- data/test/unit/fleakr/objects/comment_test.rb +15 -15
- data/test/unit/fleakr/objects/contact_test.rb +11 -11
- data/test/unit/fleakr/objects/error_test.rb +8 -8
- data/test/unit/fleakr/objects/group_test.rb +13 -13
- data/test/unit/fleakr/objects/image_test.rb +4 -4
- data/test/unit/fleakr/objects/metadata_collection_test.rb +55 -0
- data/test/unit/fleakr/objects/metadata_test.rb +27 -0
- data/test/unit/fleakr/objects/photo_context_test.rb +23 -23
- data/test/unit/fleakr/objects/photo_test.rb +71 -64
- data/test/unit/fleakr/objects/search_test.rb +22 -22
- data/test/unit/fleakr/objects/set_test.rb +62 -40
- data/test/unit/fleakr/objects/tag_test.rb +32 -31
- data/test/unit/fleakr/objects/url_test.rb +185 -0
- data/test/unit/fleakr/objects/user_test.rb +43 -16
- data/test/unit/fleakr/support/attribute_test.rb +15 -15
- data/test/unit/fleakr/support/object_test.rb +77 -33
- data/test/unit/fleakr/support/request_test.rb +12 -12
- data/test/unit/fleakr/support/url_expander_test.rb +44 -0
- data/test/unit/fleakr/support/utility_test.rb +70 -0
- data/test/unit/fleakr_test.rb +48 -41
- metadata +43 -23
@@ -1,56 +1,58 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class PhotoTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
should_have_many :images, :
|
6
|
+
should_have_many :images, :class => Image
|
7
|
+
should_have_many :tags, :class => Tag
|
8
|
+
should_have_many :comments, :class => Comment
|
7
9
|
|
8
10
|
should_autoload_when_accessing :posted, :taken, :updated, :comment_count, :with => :load_info
|
9
11
|
should_autoload_when_accessing :url, :description, :with => :load_info
|
10
12
|
|
11
13
|
context "The Photo class" do
|
12
14
|
|
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'
|
15
|
+
should_find_all :photos, :by => :user_id, :call => 'people.getPublicPhotos', :path => 'rsp/photos/photo', :class => Photo
|
16
|
+
should_find_all :photos, :by => :set_id, :using => :photoset_id, :call => 'photosets.getPhotos', :path => 'rsp/photoset/photo', :class => Photo
|
17
|
+
should_find_all :photos, :by => :group_id, :call => 'groups.pools.getPhotos', :path => 'rsp/photos/photo', :class => Photo
|
18
|
+
|
19
|
+
should_find_one :photo, :by => :id, :with => :photo_id, :call => 'photos.getInfo', :class => Photo
|
18
20
|
|
19
21
|
# TODO: refactor these 2 tests
|
20
22
|
should "be able to upload a photo and return the new photo information" do
|
21
23
|
filename = '/path/to/mugshot.jpg'
|
22
24
|
photo = stub()
|
23
|
-
|
25
|
+
|
24
26
|
response = stub()
|
25
27
|
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
26
|
-
|
28
|
+
|
27
29
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {}).returns(response)
|
28
30
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
29
|
-
|
31
|
+
|
30
32
|
Photo.upload(filename).should == photo
|
31
33
|
end
|
32
|
-
|
34
|
+
|
33
35
|
should "be able to pass additional options when uploading a new file" do
|
34
36
|
filename = '/path/to/mugshot.jpg'
|
35
37
|
photo = stub()
|
36
|
-
|
38
|
+
|
37
39
|
response = stub()
|
38
40
|
response.stubs(:body).with().returns(Hpricot.XML('<photoid>123</photoid>'))
|
39
|
-
|
41
|
+
|
40
42
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :create, {:title => 'foo'}).returns(response)
|
41
43
|
Photo.expects(:find_by_id).with('123').returns(photo)
|
42
|
-
|
44
|
+
|
43
45
|
Photo.upload(filename, :title => 'foo').should == photo
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
47
49
|
|
48
50
|
context "An instance of the Photo class" do
|
49
|
-
|
51
|
+
|
50
52
|
should "be able to replace the associated photo data" do
|
51
53
|
filename = '/path/to/file.jpg'
|
52
54
|
response = stub(:body => 'body')
|
53
|
-
|
55
|
+
|
54
56
|
params = {:photo_id => '1'}
|
55
57
|
|
56
58
|
Fleakr::Api::UploadRequest.expects(:with_response!).with(filename, :update, params).returns(response)
|
@@ -58,10 +60,10 @@ module Fleakr::Objects
|
|
58
60
|
photo = Photo.new
|
59
61
|
photo.stubs(:id).returns('1')
|
60
62
|
photo.expects(:populate_from).with('body')
|
61
|
-
|
63
|
+
|
62
64
|
photo.replace_with(filename).should == photo
|
63
65
|
end
|
64
|
-
|
66
|
+
|
65
67
|
context "when populating from the people_getPublicPhotos XML data" do
|
66
68
|
setup do
|
67
69
|
@object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
|
@@ -73,23 +75,23 @@ module Fleakr::Objects
|
|
73
75
|
should_have_a_value_for :server_id => '3250'
|
74
76
|
should_have_a_value_for :secret => 'cbc1804258'
|
75
77
|
should_have_a_value_for :owner_id => '21775151@N06'
|
76
|
-
|
78
|
+
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
context "when populating from the photo upload XML data" do
|
80
82
|
setup do
|
81
83
|
@object = Photo.new(Hpricot.XML('<photoid>123</photoid>'))
|
82
84
|
end
|
83
|
-
|
85
|
+
|
84
86
|
should_have_a_value_for :id => '123'
|
85
87
|
end
|
86
|
-
|
88
|
+
|
87
89
|
context "when populating from the photos_getInfo XML data" do
|
88
90
|
setup do
|
89
91
|
@object = Photo.new(Hpricot.XML(read_fixture('photos.getInfo')))
|
90
|
-
|
92
|
+
|
91
93
|
end
|
92
|
-
|
94
|
+
|
93
95
|
should_have_a_value_for :id => '1'
|
94
96
|
should_have_a_value_for :title => 'Tree'
|
95
97
|
should_have_a_value_for :description => 'A Tree'
|
@@ -103,111 +105,116 @@ module Fleakr::Objects
|
|
103
105
|
should_have_a_value_for :updated => '1230276652'
|
104
106
|
should_have_a_value_for :comment_count => '0'
|
105
107
|
should_have_a_value_for :url => 'http://www.flickr.com/photos/yes/1'
|
106
|
-
|
108
|
+
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
context "in general" do
|
110
|
-
|
112
|
+
|
111
113
|
setup do
|
112
114
|
@photo = Photo.new
|
113
|
-
@time
|
115
|
+
@time = Time.parse('2009-08-01 00:00:00')
|
114
116
|
end
|
115
|
-
|
117
|
+
|
116
118
|
should "be able to retrieve additional information about the current user" do
|
117
119
|
photo_id = '1'
|
118
120
|
photo = Photo.new
|
119
121
|
photo.expects(:id).with().returns(photo_id)
|
120
122
|
response = mock_request_cycle :for => 'photos.getInfo', :with => {:photo_id => photo_id}
|
121
|
-
|
123
|
+
|
122
124
|
photo.expects(:populate_from).with(response.body)
|
123
125
|
|
124
126
|
photo.load_info
|
125
127
|
end
|
126
|
-
|
128
|
+
|
127
129
|
should "have a value for :posted_at" do
|
128
130
|
@photo.expects(:posted).with().returns("#{@time.to_i}")
|
129
131
|
@photo.posted_at.to_s.should == @time.to_s
|
130
132
|
end
|
131
|
-
|
133
|
+
|
132
134
|
should "have a value for :taken_at" do
|
133
135
|
@photo.expects(:taken).with().returns(@time.strftime('%Y-%m-%d %H:%M:%S'))
|
134
136
|
@photo.taken_at.to_s.should == @time.to_s
|
135
137
|
end
|
136
|
-
|
138
|
+
|
137
139
|
should "have a value for :updated_at" do
|
138
140
|
@photo.expects(:updated).with().returns("#{@time.to_i}")
|
139
141
|
@photo.updated_at.to_s.should == @time.to_s
|
140
142
|
end
|
141
|
-
|
143
|
+
|
144
|
+
should "be able to retrieve the metadata" do
|
145
|
+
MetadataCollection.expects(:new).with(@photo).returns('metadata')
|
146
|
+
@photo.metadata.should == 'metadata'
|
147
|
+
end
|
148
|
+
|
142
149
|
should "have a collection of images by size" do
|
143
150
|
photo = Photo.new
|
144
|
-
|
151
|
+
|
145
152
|
small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
|
146
|
-
|
153
|
+
|
147
154
|
photo.stubs(:images).returns([small_image, large_image])
|
148
|
-
|
155
|
+
|
149
156
|
expected = {
|
150
157
|
:square => nil,
|
151
158
|
:thumbnail => nil,
|
152
|
-
:small => small_image,
|
159
|
+
:small => small_image,
|
153
160
|
:medium => nil,
|
154
161
|
:large => large_image,
|
155
162
|
:original => nil
|
156
163
|
}
|
157
|
-
|
164
|
+
|
158
165
|
photo.send(:images_by_size).should == expected
|
159
166
|
end
|
160
|
-
|
167
|
+
|
161
168
|
[:square, :thumbnail, :small, :medium, :large, :original].each do |method|
|
162
169
|
should "have a reader for the :#{method} image" do
|
163
170
|
photo = Photo.new
|
164
171
|
image = stub()
|
165
|
-
|
172
|
+
|
166
173
|
photo.stubs(:images_by_size).returns(method => image)
|
167
174
|
photo.send(method).should == image
|
168
175
|
end
|
169
176
|
end
|
170
|
-
|
177
|
+
|
171
178
|
should "be able to retrieve the context for this photo" do
|
172
179
|
id = '1'
|
173
|
-
|
180
|
+
|
174
181
|
context = stub()
|
175
|
-
|
182
|
+
|
176
183
|
photo = Photo.new
|
177
184
|
photo.stubs(:id).with().returns(id)
|
178
|
-
|
185
|
+
|
179
186
|
response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
|
180
187
|
PhotoContext.expects(:new).with(response.body).returns(context)
|
181
|
-
|
188
|
+
|
182
189
|
photo.context.should == context
|
183
190
|
end
|
184
|
-
|
191
|
+
|
185
192
|
should "memoize the context data" do
|
186
193
|
id = '1'
|
187
|
-
|
194
|
+
|
188
195
|
context = stub()
|
189
|
-
|
196
|
+
|
190
197
|
photo = Photo.new
|
191
198
|
photo.stubs(:id).with().returns(id)
|
192
|
-
|
199
|
+
|
193
200
|
response = mock_request_cycle :for => 'photos.getContext', :with => {:photo_id => id}
|
194
201
|
PhotoContext.expects(:new).once.returns(context)
|
195
|
-
|
202
|
+
|
196
203
|
2.times { photo.context }
|
197
204
|
end
|
198
|
-
|
205
|
+
|
199
206
|
should "be able to retrieve the next photo" do
|
200
207
|
next_photo = stub()
|
201
208
|
context = mock()
|
202
209
|
context.expects(:next).with().returns(next_photo)
|
203
|
-
|
210
|
+
|
204
211
|
photo = Photo.new
|
205
|
-
|
212
|
+
|
206
213
|
photo.expects(:context).with().returns(context)
|
207
|
-
|
214
|
+
|
208
215
|
photo.next.should == next_photo
|
209
216
|
end
|
210
|
-
|
217
|
+
|
211
218
|
should "be able to retrieve the previous photo" do
|
212
219
|
previous_photo = stub()
|
213
220
|
context = mock()
|
@@ -218,27 +225,27 @@ module Fleakr::Objects
|
|
218
225
|
|
219
226
|
photo.previous.should == previous_photo
|
220
227
|
end
|
221
|
-
|
228
|
+
|
222
229
|
should "be able to find the owner of the photo" do
|
223
230
|
owner = stub()
|
224
|
-
|
231
|
+
|
225
232
|
photo = Photo.new
|
226
233
|
photo.stubs(:owner_id).with().returns('1')
|
227
|
-
|
234
|
+
|
228
235
|
User.expects(:find_by_id).with('1').returns(owner)
|
229
|
-
|
236
|
+
|
230
237
|
photo.owner.should == owner
|
231
238
|
end
|
232
|
-
|
239
|
+
|
233
240
|
should "memoize the owner information" do
|
234
241
|
photo = Photo.new
|
235
242
|
photo.stubs(:owner_id).with().returns('1')
|
236
|
-
|
243
|
+
|
237
244
|
User.expects(:find_by_id).with('1').once.returns(stub())
|
238
|
-
|
245
|
+
|
239
246
|
2.times { photo.owner }
|
240
247
|
end
|
241
|
-
|
248
|
+
|
242
249
|
end
|
243
250
|
end
|
244
251
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
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 "have a list of tags" do
|
9
9
|
search = Search.new(:tags => %w(a b c))
|
10
10
|
search.tags.should == %w(a b c)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
should "have convert tags into an array" do
|
14
14
|
search = Search.new(:tags => 'a')
|
15
15
|
search.tags.should == ['a']
|
@@ -19,76 +19,76 @@ module Fleakr::Objects
|
|
19
19
|
search = Search.new(:tags => 'foo')
|
20
20
|
search.send(:tag_list).should == 'foo'
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
should "be able to generate a list of tags from multi-valued parameters" do
|
24
24
|
search = Search.new(:tags => %w(foo bar))
|
25
25
|
search.send(:tag_list).should == 'foo,bar'
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
should "be able to create parameters for the search" do
|
29
29
|
search = Search.new(:tags => %w(foo bar))
|
30
30
|
search.send(:parameters).should == {:tags => 'foo,bar'}
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
should "preserve the original :tags parameter if it is a comma-separated string" do
|
34
34
|
search = Search.new(:tags => 'one,two')
|
35
35
|
search.send(:parameters).should == {:tags => 'one,two'}
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
should "not have any :tags parameters if none are supplied" do
|
39
39
|
search = Search.new({})
|
40
40
|
search.send(:parameters).should == {}
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
should "convert the search term into the appropriate parameter" do
|
44
44
|
search = Search.new(:text => 'foo')
|
45
45
|
search.send(:parameters).should == {:text => 'foo'}
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
should "convert a single string parameter into a text search" do
|
49
49
|
search = Search.new('term')
|
50
50
|
search.send(:parameters).should == {:text => 'term'}
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
should "be able to handle a combination of text and options" do
|
54
54
|
search = Search.new('term', :tags => %w(a b))
|
55
55
|
search.send(:parameters).should == {:text => 'term', :tags => 'a,b'}
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
should "be able to search photos based on text" do
|
59
59
|
response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
|
60
60
|
search = Search.new(:text => 'foo')
|
61
61
|
search.results
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
should "be able to search photos based on tags" do
|
65
65
|
response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
|
66
|
-
|
66
|
+
|
67
67
|
photo_1, photo_2 = [stub(), stub()]
|
68
68
|
photo_1_doc, photo_2_doc = (response.body/'rsp/photos/photo').map {|doc| doc }
|
69
|
-
|
69
|
+
|
70
70
|
Photo.expects(:new).with(photo_1_doc).returns(photo_1)
|
71
71
|
Photo.expects(:new).with(photo_2_doc).returns(photo_2)
|
72
|
-
|
72
|
+
|
73
73
|
search = Search.new(:tags => %w(one two))
|
74
74
|
search.results.should == [photo_1, photo_2]
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
should "memoize the search results" do
|
78
78
|
response = stub(:body => Hpricot.XML(read_fixture('photos.search')))
|
79
79
|
Fleakr::Api::MethodRequest.expects(:with_response!).with(kind_of(String), kind_of(Hash)).once.returns(response)
|
80
|
-
|
80
|
+
|
81
81
|
(response.body/'rsp/photos/photo').each do |doc|
|
82
82
|
Photo.expects(:new).with(doc).once
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
search = Search.new(:tags => %w(foo))
|
86
|
-
|
86
|
+
|
87
87
|
2.times { search.results }
|
88
88
|
end
|
89
|
-
|
90
|
-
|
89
|
+
|
90
|
+
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
end
|
94
94
|
end
|
@@ -1,133 +1,155 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Fleakr::Objects
|
4
4
|
class SetTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
should_have_many :photos, :
|
7
|
-
|
6
|
+
should_have_many :photos, :class => Photo
|
7
|
+
should_have_many :comments, :class => Comment
|
8
|
+
|
8
9
|
should_autoload_when_accessing :user_id, :with => :load_info
|
9
10
|
|
10
11
|
context "The Set class" do
|
11
|
-
|
12
|
-
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
|
13
|
-
should_find_one :set, :by => :id, :with => :photoset_id, :call => 'photosets.getInfo', :path => 'rsp/photoset'
|
14
|
-
|
12
|
+
|
13
|
+
should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset', :class => Set
|
14
|
+
should_find_one :set, :by => :id, :with => :photoset_id, :call => 'photosets.getInfo', :path => 'rsp/photoset', :class => Set
|
15
|
+
|
15
16
|
end
|
16
17
|
|
17
18
|
context "An instance of the Set class" do
|
18
|
-
|
19
|
+
|
19
20
|
context "when populating from photosets.getList" do
|
20
21
|
setup do
|
21
22
|
@object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
should_have_a_value_for :id => '72157609490909659'
|
25
26
|
should_have_a_value_for :title => 'Second Set'
|
26
27
|
should_have_a_value_for :description => 'This is the second set.'
|
27
28
|
should_have_a_value_for :count => '138'
|
28
29
|
should_have_a_value_for :primary_photo_id => '3044180117'
|
29
|
-
|
30
|
+
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
context "when populating from photosets.getInfo" do
|
33
34
|
setup do
|
34
35
|
@object = Set.new
|
35
36
|
@object.populate_from(Hpricot.XML(read_fixture('photosets.getInfo')))
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
should_have_a_value_for :user_id => '43955217@N05'
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
should "know the URL for the photoset" do
|
42
43
|
s = Set.new
|
43
44
|
s.stubs(:user_id).with().returns('123')
|
44
45
|
s.stubs(:id).with().returns('456')
|
45
|
-
|
46
|
+
|
46
47
|
s.url.should == "http://www.flickr.com/photos/123/sets/456/"
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
should "be able to retrieve the user for the set" do
|
50
51
|
s = Set.new
|
51
52
|
s.stubs(:user_id).with().returns('1')
|
52
|
-
|
53
|
+
|
53
54
|
User.expects(:find_by_id).with('1').returns('user')
|
54
|
-
|
55
|
+
|
55
56
|
s.user.should == 'user'
|
56
57
|
end
|
57
|
-
|
58
|
+
|
58
59
|
should "know the primary photo in the set" do
|
59
60
|
id = '1'
|
60
61
|
photo = stub()
|
61
|
-
|
62
|
+
|
62
63
|
Photo.expects(:find_by_id).with(id).returns(photo)
|
63
|
-
|
64
|
+
|
64
65
|
set = Set.new
|
65
66
|
set.stubs(:primary_photo_id).with().returns(id)
|
66
|
-
|
67
|
+
|
67
68
|
set.primary_photo.should == photo
|
68
69
|
end
|
69
|
-
|
70
|
+
|
70
71
|
should "memoize the primary photo" do
|
71
72
|
id = '1'
|
72
73
|
photo = stub()
|
73
|
-
|
74
|
+
|
74
75
|
Photo.expects(:find_by_id).with(id).once.returns(photo)
|
75
|
-
|
76
|
+
|
76
77
|
set = Set.new
|
77
78
|
set.stubs(:primary_photo_id).with().returns(id)
|
78
|
-
|
79
|
+
|
79
80
|
2.times { set.primary_photo }
|
80
81
|
end
|
81
|
-
|
82
|
+
|
83
|
+
should "know the folder name" do
|
84
|
+
set = Set.new
|
85
|
+
set.stubs(:title).with().returns('Title')
|
86
|
+
|
87
|
+
set.folder_name.should == 'Title'
|
88
|
+
end
|
89
|
+
|
90
|
+
should "remove forward slashes from the folder name" do
|
91
|
+
set = Set.new
|
92
|
+
set.stubs(:title).with().returns("This/That")
|
93
|
+
|
94
|
+
set.folder_name.should == 'This That'
|
95
|
+
end
|
96
|
+
|
97
|
+
should "collapse spaces when generating the folder name" do
|
98
|
+
set = Set.new
|
99
|
+
set.stubs(:title).with().returns('This / That')
|
100
|
+
|
101
|
+
set.folder_name.should == 'This That'
|
102
|
+
end
|
103
|
+
|
82
104
|
context "when saving the set" do
|
83
105
|
setup do
|
84
106
|
@tmp_dir = create_temp_directory
|
85
|
-
@
|
86
|
-
|
107
|
+
@set_folder_name = 'set'
|
108
|
+
|
87
109
|
@set = Set.new
|
88
|
-
@set.stubs(:
|
110
|
+
@set.stubs(:folder_name).with().returns(@set_folder_name)
|
89
111
|
end
|
90
|
-
|
112
|
+
|
91
113
|
teardown { FileUtils.rm_rf(@tmp_dir) }
|
92
114
|
|
93
115
|
should "know the prefix string based on the number of photos in the set" do
|
94
116
|
set = Set.new
|
95
117
|
set.stubs(:count).with().returns('5')
|
96
118
|
set.file_prefix(0).should == '1_'
|
97
|
-
|
119
|
+
|
98
120
|
set.stubs(:count).with().returns('99')
|
99
121
|
set.file_prefix(0).should == '01_'
|
100
122
|
end
|
101
|
-
|
123
|
+
|
102
124
|
should "save all files of the specified size to the specified directory" do
|
103
125
|
image = mock()
|
104
126
|
image.expects(:save_to).with("#{@tmp_dir}/set", '1_')
|
105
|
-
|
127
|
+
|
106
128
|
photo = stub(:small => image)
|
107
129
|
|
108
130
|
@set.stubs(:photos).with().returns([photo])
|
109
131
|
@set.stubs(:file_prefix).with(0).returns('1_')
|
110
|
-
|
132
|
+
|
111
133
|
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set")
|
112
|
-
|
134
|
+
|
113
135
|
@set.save_to(@tmp_dir, :small)
|
114
136
|
end
|
115
|
-
|
137
|
+
|
116
138
|
should "not create the directory if it already exists" do
|
117
139
|
FileUtils.mkdir("#{@tmp_dir}/set")
|
118
140
|
|
119
141
|
@set.stubs(:photos).with().returns([])
|
120
|
-
|
142
|
+
|
121
143
|
FileUtils.expects(:mkdir).with("#{@tmp_dir}/set").never
|
122
|
-
|
144
|
+
|
123
145
|
@set.save_to(@tmp_dir, :small)
|
124
146
|
end
|
125
|
-
|
147
|
+
|
126
148
|
should "not raise errors when saving an image size that doesn't exist" do
|
127
149
|
@set.stubs(:photos).with().returns([stub(:large => nil)])
|
128
150
|
lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
|
129
151
|
end
|
130
|
-
|
152
|
+
|
131
153
|
end
|
132
154
|
|
133
155
|
end
|