Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixing https://github.com/ctagg/flickr/issues#issue/1 #3

Merged
1 commit merged into from over 3 years ago

1 participant

Stephen Tiberius Schor
Stephen Tiberius Schor

Hi.

Please consider pulling from my repo to address https://github.com/ctagg/flickr/issues#issue/1.
I've also fixed a test that was breaking because parameters were out of order.

-Stephen

nodanaonlyzuul * Setting HOST_URL to http://api.flickr.com to fix issue https://gith…
…ub.com/ctagg/flickr/issues#issue/1

* Fixing test that was breaking because parameters were out of order
139d64b
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 26, 2010
nodanaonlyzuul * Setting HOST_URL to http://api.flickr.com to fix issue https://gith…
…ub.com/ctagg/flickr/issues#issue/1

* Fixing test that was breaking because parameters were out of order
139d64b
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 311 additions and 311 deletions. Show diff stats Hide diff stats

  1. +85 85 lib/flickr.rb
  2. +226 226 test/test_flickr.rb
170 lib/flickr.rb
... ... @@ -1,6 +1,6 @@
1 1 # = Flickr
2 2 # An insanely easy interface to the Flickr photo-sharing service. By Scott Raymond.
3   -#
  3 +#
4 4 # Author:: Scott Raymond <sco@redgreenblu.com>
5 5 # Copyright:: Copyright (c) 2005 Scott Raymond <sco@redgreenblu.com>. Additional content by Patrick Plattes and Chris Taggart (http://pushrod.wordpress.com)
6 6 # License:: MIT <http://www.opensource.org/licenses/mit-license.php>
@@ -42,21 +42,21 @@
42 42 class Flickr
43 43 attr_reader :api_key, :auth_token
44 44 attr_accessor :user
45   -
46   - HOST_URL = 'http://flickr.com'
  45 +
  46 + HOST_URL = 'http://api.flickr.com'
47 47 API_PATH = '/services/rest'
48 48
49   - # Flickr, annoyingly, uses a number of representations to specify the size
  49 + # Flickr, annoyingly, uses a number of representations to specify the size
50 50 # of a photo, depending on the context. It gives a label such a "Small" or
51   - # "Medium" to a size of photo, when returning all possible sizes. However,
  51 + # "Medium" to a size of photo, when returning all possible sizes. However,
52 52 # when generating the uri for the page that features that size of photo, or
53   - # the source url for the image itself it uses a single letter. Bizarrely,
  53 + # the source url for the image itself it uses a single letter. Bizarrely,
54 54 # these letters are different depending on whether you want the Flickr page
55 55 # for the photo or the source uri -- e.g. a "Small" photo (240 pixels on its
56   - # longest side) may be viewed at
  56 + # longest side) may be viewed at
57 57 # "http://www.flickr.com/photos/sco/2397458775/sizes/s/"
58   - # but its source is at
59   - # "http://farm4.static.flickr.com/3118/2397458775_2ec2ddc324_m.jpg".
  58 + # but its source is at
  59 + # "http://farm4.static.flickr.com/3118/2397458775_2ec2ddc324_m.jpg".
60 60 # The VALID_SIZES hash associates the correct letter with a label
61 61 VALID_SIZES = { "Square" => ["s", "sq"],
62 62 "Thumbnail" => ["t", "t"],
@@ -65,14 +65,14 @@ class Flickr
65 65 "Large" => ["b", "l"]
66 66 }
67 67
68   - # To use the Flickr API you need an api key
69   - # (see http://www.flickr.com/services/api/misc.api_keys.html), and the flickr
  68 + # To use the Flickr API you need an api key
  69 + # (see http://www.flickr.com/services/api/misc.api_keys.html), and the flickr
70 70 # client object shuld be initialized with this. You'll also need a shared
71 71 # secret code if you want to use authentication (e.g. to get a user's
72 72 # private photos)
73 73 # There are two ways to initialize the Flickr client. The preferred way is with
74   - # a hash of params, e.g. 'api_key' => 'your_api_key', 'shared_secret' =>
75   - # 'shared_secret_code'. The older (deprecated) way is to pass an ordered series of
  74 + # a hash of params, e.g. 'api_key' => 'your_api_key', 'shared_secret' =>
  75 + # 'shared_secret_code'. The older (deprecated) way is to pass an ordered series of
76 76 # arguments. This is provided for continuity only, as several of the arguments
77 77 # are no longer usable ('email', 'password')
78 78 def initialize(api_key_or_params=nil, email=nil, password=nil, shared_secret=nil)
@@ -95,13 +95,13 @@ def initialize(api_key_or_params=nil, email=nil, password=nil, shared_secret=nil
95 95 def get_token_from(frob)
96 96 auth_response = request("auth.getToken", :frob => frob)['auth']
97 97 @auth_token = auth_response['token']
98   - @user = User.new( 'id' => auth_response['user']['nsid'],
  98 + @user = User.new( 'id' => auth_response['user']['nsid'],
99 99 'username' => auth_response['user']['username'],
100 100 'name' => auth_response['user']['fullname'],
101 101 'client' => self)
102 102 @auth_token
103 103 end
104   -
  104 +
105 105 # Stores authentication credentials to use on all subsequent calls.
106 106 # If authentication succeeds, returns a User object.
107 107 # NB This call is no longer in API and will result in an error if called
@@ -111,7 +111,7 @@ def login(email='', password='')
111 111 user = request('test.login')['user'] rescue fail
112 112 @user = User.new(user['id'], nil, nil, nil, @api_key)
113 113 end
114   -
  114 +
115 115 # Implements flickr.urls.lookupGroup and flickr.urls.lookupUser
116 116 def find_by_url(url)
117 117 response = urls_lookupUser('url'=>url) rescue urls_lookupGroup('url'=>url) rescue nil
@@ -128,18 +128,18 @@ def photos(*criteria)
128 128 def recent
129 129 photos_request('photos.getRecent')
130 130 end
131   -
  131 +
132 132 def photos_search(params={})
133 133 photos_request('photos.search', params)
134 134 end
135 135 alias_method :search, :photos_search
136   -
  136 +
137 137 # Gets public photos with a given tag
138 138 def tag(tag)
139 139 photos('tags'=>tag)
140 140 end
141   -
142   - # Implements flickr.people.findByEmail and flickr.people.findByUsername.
  141 +
  142 + # Implements flickr.people.findByEmail and flickr.people.findByUsername.
143 143 def users(lookup=nil)
144 144 user = people_findByEmail('find_email'=>lookup)['user'] rescue people_findByUsername('username'=>lookup)['user']
145 145 return User.new("id" => user["nsid"], "username" => user["username"], "client" => self)
@@ -149,35 +149,35 @@ def users(lookup=nil)
149 149 def groups(group_name, options={})
150 150 collection = groups_search({"text" => group_name}.merge(options))['groups']['group']
151 151 collection = [collection] if collection.is_a? Hash
152   -
153   - collection.collect { |group| Group.new( "id" => group['nsid'],
154   - "name" => group['name'],
  152 +
  153 + collection.collect { |group| Group.new( "id" => group['nsid'],
  154 + "name" => group['name'],
155 155 "eighteenplus" => group['eighteenplus'],
156 156 "client" => self) }
157 157 end
158   -
  158 +
159 159 def photoset(photoset_id)
160 160 Photoset.new(photoset_id, @api_key)
161 161 end
162   -
  162 +
163 163 # Implements flickr.tags.getRelated
164 164 def related_tags(tag)
165 165 tags_getRelated('tag'=>tag)['tags']['tag']
166 166 end
167   -
  167 +
168 168 # Implements flickr.photos.licenses.getInfo
169 169 def licenses
170 170 photos_licenses_getInfo['licenses']['license']
171 171 end
172   -
  172 +
173 173 # Returns url for user to login in to Flickr to authenticate app for a user
174 174 def login_url(perms)
175 175 "http://flickr.com/services/auth/?api_key=#{@api_key}&perms=#{perms}&api_sig=#{signature_from('api_key'=>@api_key, 'perms' => perms)}"
176 176 end
177   -
  177 +
178 178 # Implements everything else.
179 179 # Any method not defined explicitly will be passed on to the Flickr API,
180   - # and return an XmlSimple document. For example, Flickr#test_echo is not
  180 + # and return an XmlSimple document. For example, Flickr#test_echo is not
181 181 # defined, so it will pass the call to the flickr.test.echo method.
182 182 def method_missing(method_id, params={})
183 183 request(method_id.id2name.gsub(/_/, '.'), params)
@@ -201,45 +201,45 @@ def photos_request(method, params={})
201 201 photos = request(method, params)
202 202 PhotoCollection.new(photos, @api_key)
203 203 end
204   -
205   - # Builds url for Flickr API REST request from given the flickr method name
  204 +
  205 + # Builds url for Flickr API REST request from given the flickr method name
206 206 # (exclusing the 'flickr.' that begins each method call) and params (where
207 207 # applicable) which should be supplied as a Hash (e.g 'user_id' => "foo123")
208 208 def request_url(method, params={})
209 209 method = 'flickr.' + method
210 210 url = "#{@host}#{@api}/?api_key=#{@api_key}&method=#{method}"
211 211 params.merge!('api_key' => @api_key, 'method' => method, 'auth_token' => @auth_token)
212   - signature = signature_from(params)
213   -
  212 + signature = signature_from(params)
  213 +
214 214 url = "#{@host}#{@api}/?" + params.merge('api_sig' => signature).collect { |k,v| "#{k}=" + CGI::escape(v.to_s) unless v.nil? }.compact.join("&")
215 215 end
216   -
  216 +
217 217 def signature_from(params={})
218 218 return unless @shared_secret # don't both getting signature if no shared_secret
219 219 request_str = params.reject {|k,v| v.nil?}.collect {|p| "#{p[0].to_s}#{p[1]}"}.sort.join # build key value pairs, sort in alpha order then join them, ignoring those with nil value
220 220 return Digest::MD5.hexdigest("#{@shared_secret}#{request_str}")
221 221 end
222   -
  222 +
223 223 # A collection of photos is returned as a PhotoCollection, a subclass of Array.
224 224 # This allows us to retain the pagination info returned by Flickr and make it
225 225 # accessible in a friendly way
226 226 class PhotoCollection < Array
227 227 attr_reader :page, :pages, :perpage, :total
228   -
229   - # builds a PhotoCollection from given params, such as those returned from
230   - # photos.search API call. Note all the info is contained in the value of
231   - # the first (and only) key-value pair of the response. The key will vary
  228 +
  229 + # builds a PhotoCollection from given params, such as those returned from
  230 + # photos.search API call. Note all the info is contained in the value of
  231 + # the first (and only) key-value pair of the response. The key will vary
232 232 # depending on the original object the photos are related to (e.g 'photos',
233 233 # 'photoset', etc)
234 234 def initialize(photos_api_response={}, api_key=nil)
235   - photos = photos_api_response.values.first
236   - [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos[i])}
  235 + photos = photos_api_response.values.first
  236 + [ "page", "pages", "perpage", "total" ].each { |i| instance_variable_set("@#{i}", photos[i])}
237 237 collection = photos['photo'] || []
238 238 collection = [collection] if collection.is_a? Hash
239 239 collection.each { |photo| self << Photo.new(photo.delete('id'), api_key, photo) }
240 240 end
241 241 end
242   -
  242 +
243 243 # Todo:
244 244 # logged_in?
245 245 # if logged in:
@@ -255,20 +255,20 @@ def initialize(photos_api_response={}, api_key=nil)
255 255 # flickr.test.login
256 256 # uploading
257 257 class User
258   -
  258 +
259 259 attr_reader :client, :id, :name, :location, :photos_url, :url, :count, :firstdate, :firstdatetaken
260 260
261   - # A Flickr::User can be instantiated in two ways. The old (deprecated)
262   - # method is with an ordered series of values. The new method is with a
263   - # params Hash, which is easier when a variable number of params are
  261 + # A Flickr::User can be instantiated in two ways. The old (deprecated)
  262 + # method is with an ordered series of values. The new method is with a
  263 + # params Hash, which is easier when a variable number of params are
264 264 # supplied, which is the case here, and also avoids having to constantly
265 265 # supply nil values for the email and password, which are now irrelevant
266   - # as authentication is no longer done this way.
267   - # An associated flickr client will also be generated if an api key is
  266 + # as authentication is no longer done this way.
  267 + # An associated flickr client will also be generated if an api key is
268 268 # passed among the arguments or in the params hash. Alternatively, and
269   - # most likely, an existing client object may be passed in the params hash
  269 + # most likely, an existing client object may be passed in the params hash
270 270 # (e.g. 'client' => some_existing_flickr_client_object), and this is
271   - # what happends when users are initlialized as the result of a method
  271 + # what happends when users are initlialized as the result of a method
272 272 # called on the flickr client (e.g. flickr.users)
273 273 def initialize(id_or_params_hash=nil, username=nil, email=nil, password=nil, api_key=nil)
274 274 if id_or_params_hash.is_a?(Hash)
@@ -302,35 +302,35 @@ def firstdate
302 302 def firstdatetaken
303 303 @firstdatetaken.nil? ? getInfo.firstdatetaken : @firstdatetaken
304 304 end
305   -
306   - # Builds url for user's photos page as per
  305 +
  306 + # Builds url for user's photos page as per
307 307 # http://www.flickr.com/services/api/misc.urls.html
308 308 def photos_url
309 309 "http://www.flickr.com/photos/#{id}/"
310 310 end
311   -
312   - # Builds url for user's profile page as per
  311 +
  312 + # Builds url for user's profile page as per
313 313 # http://www.flickr.com/services/api/misc.urls.html
314 314 def url
315 315 "http://www.flickr.com/people/#{id}/"
316 316 end
317   -
  317 +
318 318 def pretty_url
319 319 @pretty_url ||= @client.urls_getUserProfile('user_id'=>@id)['user']['url']
320 320 end
321   -
  321 +
322 322 # Implements flickr.people.getPublicGroups
323 323 def groups
324 324 collection = @client.people_getPublicGroups('user_id'=>@id)['groups']['group']
325 325 collection = [collection] if collection.is_a? Hash
326   - collection.collect { |group| Group.new( "id" => group['nsid'],
  326 + collection.collect { |group| Group.new( "id" => group['nsid'],
327 327 "name" => group['name'],
328 328 "eighteenplus" => group['eighteenplus'],
329 329 "client" => @client) }
330 330 end
331   -
  331 +
332 332 # Implements flickr.people.getPublicPhotos. Options hash allows you to add
333   - # extra restrictions as per flickr.people.getPublicPhotos docs, e.g.
  333 + # extra restrictions as per flickr.people.getPublicPhotos docs, e.g.
334 334 # user.photos('per_page' => '25', 'extras' => 'date_taken')
335 335 def photos(options={})
336 336 @client.photos_request('people.getPublicPhotos', {'user_id' => @id}.merge(options))
@@ -347,12 +347,12 @@ def contacts
347 347 @client.contacts_getPublicList('user_id'=>@id)['contacts']['contact'].collect { |contact| User.new(contact['nsid'], contact['username'], nil, nil, @api_key) }
348 348 #or
349 349 end
350   -
  350 +
351 351 # Implements flickr.favorites.getPublicList
352 352 def favorites
353 353 @client.photos_request('favorites.getPublicList', 'user_id' => @id)
354 354 end
355   -
  355 +
356 356 # Implements flickr.photosets.getList
357 357 def photosets
358 358 @client.photosets_getList('user_id'=>@id)['photosets']['photoset'].collect { |photoset| Photoset.new(photoset['id'], @api_key) }
@@ -372,7 +372,7 @@ def popular_tags(count = 10)
372 372 def contactsPhotos
373 373 @client.photos_request('photos.getContactsPublicPhotos', 'user_id' => @id)
374 374 end
375   -
  375 +
376 376 def to_s
377 377 @name
378 378 end
@@ -403,22 +403,22 @@ def initialize(id=nil, api_key=nil, extra_params={})
403 403 extra_params.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
404 404 @client = Flickr.new @api_key
405 405 end
406   -
407   - # Allows access to all photos instance variables through hash like
408   - # interface, e.g. photo["datetaken"] returns @datetaken instance
  406 +
  407 + # Allows access to all photos instance variables through hash like
  408 + # interface, e.g. photo["datetaken"] returns @datetaken instance
409 409 # variable. Useful for accessing any weird and wonderful parameter
410 410 # that may have been returned by Flickr when finding the photo,
411   - # e.g. those returned by the extras argument in
  411 + # e.g. those returned by the extras argument in
412 412 # flickr.people.getPublicPhotos
413 413 def [](param_name)
414 414 instance_variable_get("@#{param_name}")
415 415 end
416   -
  416 +
417 417 def title
418 418 @title.nil? ? getInfo("title") : @title
419 419 end
420   -
421   - # Returns the owner of the photo as a Flickr::User. If we have no info
  420 +
  421 + # Returns the owner of the photo as a Flickr::User. If we have no info
422 422 # about the owner, we make an API call to get it. If we already have
423 423 # the owner's id, create a user based on that. Either way, we cache the
424 424 # result so we don't need to check again
@@ -540,7 +540,7 @@ def tags
540 540 # Implements flickr.photos.notes.add
541 541 def add_note(note)
542 542 end
543   -
  543 +
544 544 # Implements flickr.photos.setDates
545 545 def dates=(dates)
546 546 end
@@ -548,11 +548,11 @@ def dates=(dates)
548 548 # Implements flickr.photos.setPerms
549 549 def perms=(perms)
550 550 end
551   -
  551 +
552 552 # Implements flickr.photos.setTags
553 553 def tags=(tags)
554 554 end
555   -
  555 +
556 556 # Implements flickr.photos.setMeta
557 557 def title=(title)
558 558 end
@@ -562,7 +562,7 @@ def description=(title)
562 562 # Implements flickr.photos.addTags
563 563 def add_tag(tag)
564 564 end
565   -
  565 +
566 566 # Implements flickr.photos.removeTag
567 567 def remove_tag(tag)
568 568 end
@@ -583,12 +583,12 @@ def deleteNote(note_id)
583 583 # Implements flickr.photos.notes.edit
584 584 def editNote(note_id)
585 585 end
586   -
  586 +
587 587 # Converts the Photo to a string by returning its title
588 588 def to_s
589 589 title
590 590 end
591   -
  591 +
592 592 private
593 593
594 594 # Implements flickr.photos.getInfo
@@ -603,10 +603,10 @@ def getInfo(attrib="")
603 603 @url = info['urls']['url']['content'] # assumes only one url
604 604 instance_variable_get("@#{attrib}")
605 605 end
606   -
607   - # Builds source uri of image from params (often returned from other
608   - # methods, e.g. User#photos). As specified at:
609   - # http://www.flickr.com/services/api/misc.urls.html. If size is given
  606 +
  607 + # Builds source uri of image from params (often returned from other
  608 + # methods, e.g. User#photos). As specified at:
  609 + # http://www.flickr.com/services/api/misc.urls.html. If size is given
610 610 # should be one the keys in the VALID_SIZES hash, i.e.
611 611 # "Square", "Thumbnail", "Medium", "Large", "Original", "Small" (These
612 612 # are the values returned by flickr.photos.getSizes).
@@ -623,8 +623,8 @@ def image_source_uri_from_self(size=nil)
623 623 "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_#{@secret}_#{s_size}.jpg"
624 624 end
625 625 end
626   -
627   - # Builds uri of Flickr page for photo. By default returns the main
  626 +
  627 + # Builds uri of Flickr page for photo. By default returns the main
628 628 # page for the photo, but if passed a size will return the simplified
629 629 # flickr page featuring the given size of the photo
630 630 # TODO: Handle "Original" size
@@ -645,13 +645,13 @@ def uri_for_photo_from_self(size=nil)
645 645 # flickr.groups.pools.remove
646 646 class Group
647 647 attr_reader :id, :client, :description, :name, :eighteenplus, :members, :online, :privacy, :url#, :chatid, :chatcount
648   -
  648 +
649 649 def initialize(id_or_params_hash=nil, api_key=nil)
650 650 if id_or_params_hash.is_a?(Hash)
651 651 id_or_params_hash.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
652 652 else
653 653 @id = id_or_params_hash
654   - @api_key = api_key
  654 + @api_key = api_key
655 655 @client = Flickr.new @api_key
656 656 end
657 657 end
@@ -701,11 +701,11 @@ def getInfo
701 701 @url = "http://www.flickr.com/photos/#{@owner.getInfo.username}/sets/#{@id}/"
702 702 self
703 703 end
704   -
  704 +
705 705 def getPhotos
706 706 photosetPhotos = @client.photos_request('photosets.getPhotos', {'photoset_id' => @id})
707 707 end
708 708
709 709 end
710   -
  710 +
711 711 end
452 test/test_flickr.rb
@@ -6,61 +6,61 @@
6 6 class TestFlickr < Test::Unit::TestCase
7 7
8 8 # Flickr client tests
9   - #
  9 + #
10 10 # instantiation tests
11 11 def test_should_instantiate_new_flickr_client
12 12 Flickr.any_instance.stubs(:login)
13 13 flickr = Flickr.new('some_api_key', 'email@test.com', 'some_password', 'some_shared_secret')
14   -
  14 +
15 15 assert_equal 'some_api_key', flickr.api_key
16 16 assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
17 17 end
18   -
  18 +
19 19 def test_should_try_to_login_using_old_api_if_email_and_password_passed
20 20 Flickr.any_instance.expects(:login).with('email@test.com', 'some_password') # checks email and password have been set
21 21 flickr = Flickr.new('some_api_key', 'email@test.com', 'some_password', 'some_shared_secret')
22 22 end
23   -
  23 +
24 24 def test_should_instantiate_new_flickr_client_on_new_api
25 25 flickr = Flickr.new('api_key' => 'some_api_key', 'email' => 'email@test.com', 'password' => 'some_password', 'shared_secret' => 'some_shared_secret', 'foo' => 'bar')
26   -
  26 +
27 27 assert_equal 'some_api_key', flickr.api_key
28 28 assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
29 29 assert_nil flickr.instance_variable_get(:@foo) # should ignore other params
30 30 end
31   -
  31 +
32 32 def test_should_not_try_to_login_using_old_api_when_instantiate_new_flickr_client_on_new_api
33 33 Flickr.any_instance.expects(:login).never # doesn't bother trying to login with new api -- it'll fail in any case
34 34 flickr = Flickr.new('api_key' => 'some_api_key', 'email' => 'email@test.com', 'password' => 'some_password', 'shared_secret' => 'some_shared_secret', 'foo' => 'bar')
35 35 end
36   -
  36 +
37 37 # signature_from method tests
38 38 def test_should_return_signature_from_given_params
39   - assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
  39 + assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
40 40 authenticated_flickr_client.send(:signature_from, {:b_param => '5678y', 'c_param' => '97531t', :a_param => '1234x', :d_param => nil})
41 41 end
42   -
  42 +
43 43 def test_should_return_nil_for_signature_when_no_shared_secret
44 44 assert_nil flickr_client.send(:signature_from, {:b_param => '5678y', :c_param => '97531t', :a_param => '1234x'})
45 45 end
46   -
  46 +
47 47 # request_url method tests
48 48 def test_should_get_signature_for_params_when_building_url
49 49 f = authenticated_flickr_client
50   - f.expects(:signature_from).with( 'method' => 'flickr.someMethod',
51   - 'api_key' => 'some_api_key',
52   - 'foo' => 'value which/needs&escaping',
  50 + f.expects(:signature_from).with( 'method' => 'flickr.someMethod',
  51 + 'api_key' => 'some_api_key',
  52 + 'foo' => 'value which/needs&escaping',
53 53 'auth_token' => 'some_auth_token').returns("foo123bar456")
54   -
  54 +
55 55 url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
56 56 end
57 57
58 58 def test_should_build_url_from_params_with_signature
59 59 f = authenticated_flickr_client
60 60 f.stubs(:signature_from).returns("foo123bar456")
61   -
  61 +
62 62 url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
63   - [ "#{Flickr::HOST_URL}#{Flickr::API_PATH}",
  63 + [ "#{Flickr::HOST_URL}#{Flickr::API_PATH}",
64 64 'api_key=some_api_key',
65 65 'method=flickr.someMethod',
66 66 'foo=value+which%2Fneeds%26escaping',
@@ -73,58 +73,58 @@ def test_should_build_url_from_params_with_signature
73 73 def test_should_build_url_from_params_when_signature_returns_nil
74 74 flickr = flickr_client
75 75 flickr.stubs(:signature_from)
76   - assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?api_key=some_api_key&method=flickr.someMethod", flickr.send(:request_url, 'someMethod')
77   - assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?api_key=some_api_key&method=flickr.someMethod&foo=bar", flickr.send(:request_url, 'someMethod', 'foo' => 'bar', 'foobar' => nil)
78   - assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?api_key=some_api_key&method=flickr.someMethod&foo=101", flickr.send(:request_url, 'someMethod', 'foo' => 101)
79   - assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?api_key=some_api_key&method=flickr.someMethod&foo=value+which%2Fneeds%26escaping", flickr.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
  76 + assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key", flickr.send(:request_url, 'someMethod')
  77 + assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=bar", flickr.send(:request_url, 'someMethod', 'foo' => 'bar', 'foobar' => nil)
  78 + assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=101", flickr.send(:request_url, 'someMethod', 'foo' => 101)
  79 + assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=value+which%2Fneeds%26escaping", flickr.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
80 80 end
81   -
  81 +
82 82 # method_missing tests
83 83 def test_should_generate_flickr_method_from_unkown_method_on_flickr_client
84   - f = flickr_client
  84 + f = flickr_client
85 85 f.expects(:request).with('some.unknown.methodForFlickr', {})
86 86 f.some_unknown_methodForFlickr
87 87 end
88   -
  88 +
89 89 # request method tests
90 90 def test_should_make_successful_request
91   - f = flickr_client
  91 + f = flickr_client
92 92 f.expects(:http_get).with('some.url').returns(successful_xml_response)
93 93 f.expects(:request_url).with('some_method', 'foo' => 'bar').returns("some.url")
94   -
  94 +
95 95 f.send(:request, 'some_method', 'foo' => 'bar') # request is protected
96 96 end
97   -
  97 +
98 98 def test_should_raise_exception_on_unsuccessful_request
99   - f = flickr_client
  99 + f = flickr_client
100 100 f.expects(:http_get).returns(unsuccessful_xml_response)
101   -
  101 +
102 102 assert_raise(RuntimeError) { f.send(:request, 'some_method', 'foo' => 'bar') }
103 103 end
104   -
  104 +
105 105 def test_should_parse_returned_xml_in_successful_request
106 106 f = flickr_client
107 107 f.stubs(:http_get).returns(successful_xml_response)
108   - expected_response = { "contacts" => { "perpage" => "1000",
109   - "contact" => [{ "nsid"=>"12037949629@N01",
110   - "username"=>"Eric",
111   - "ignored"=>"1",
112   - "family"=>"0",
113   - "friend"=>"1",
114   - "realname"=>"Eric Costello",
115   - "iconserver"=>"1"},
116   - { "nsid"=>"12037949631@N01",
117   - "username"=>"neb",
118   - "ignored"=>"0",
119   - "family"=>"0",
120   - "friend"=>"0",
121   - "realname"=>"Ben Cerveny",
122   - "iconserver"=>"1"}],
123   - "total" => "2",
124   - "pages"=> "1",
125   - "page"=>"1" },
  108 + expected_response = { "contacts" => { "perpage" => "1000",
  109 + "contact" => [{ "nsid"=>"12037949629@N01",
  110 + "username"=>"Eric",
  111 + "ignored"=>"1",
  112 + "family"=>"0",
  113 + "friend"=>"1",
  114 + "realname"=>"Eric Costello",
  115 + "iconserver"=>"1"},
  116 + { "nsid"=>"12037949631@N01",
  117 + "username"=>"neb",
  118 + "ignored"=>"0",
  119 + "family"=>"0",
  120 + "friend"=>"0",
  121 + "realname"=>"Ben Cerveny",
  122 + "iconserver"=>"1"}],
  123 + "total" => "2",
  124 + "pages"=> "1",
  125 + "page"=>"1" },
126 126 "stat"=>"ok" }
127   -
  127 +
128 128 assert_equal expected_response, f.send(:request, 'some_method', 'foo' => 'bar')
129 129 end
130 130
@@ -145,24 +145,24 @@ def test_should_instantiate_recent_photos_with_id_and_all_params_returned_by_fli
145 145 "some_api_key", { "key3" => "value3"})
146 146 photos = f.photos_request('some_method')
147 147 end
148   -
  148 +
149 149 def test_should_parse_photos_response_into_flickr_photo_collection
150 150 f = flickr_client
151 151 f.expects(:request).returns(dummy_photos_response)
152 152 assert_kind_of Flickr::PhotoCollection, f.photos_request('some_method')
153 153 end
154   -
  154 +
155 155 def test_should_store_pagination_info_in_photo_collection
156 156 f = flickr_client
157 157 f.expects(:request).returns(dummy_photos_response)
158 158 photos = f.photos_request('some_method')
159   -
  159 +
160 160 assert_equal "3", photos.page
161 161 assert_equal "5", photos.pages
162 162 assert_equal "10", photos.perpage
163 163 assert_equal "42", photos.total
164 164 end
165   -
  165 +
166 166 def test_should_return_collection_of_photos
167 167 f = flickr_client
168 168 f.expects(:request).returns(dummy_photos_response)
@@ -193,26 +193,26 @@ def test_should_generate_login_url
193 193 f.expects(:signature_from).with('api_key' => 'some_api_key', 'perms' => 'write').returns('validsignature')
194 194 assert_equal 'http://flickr.com/services/auth/?api_key=some_api_key&perms=write&api_sig=validsignature', f.login_url('write')
195 195 end
196   -
  196 +
197 197 def test_should_get_token_from_frob
198 198 f = flickr_client
199 199 f.expects(:request).with('auth.getToken',:frob => 'some_frob').returns({'auth' => {'token' => 'some_auth_token', 'user' => {}}})
200   -
  200 +
201 201 auth_token = f.get_token_from('some_frob')
202 202 assert_equal 'some_auth_token', auth_token
203 203 end
204   -
  204 +
205 205 def test_should_store_auth_token_in_client
206 206 f = flickr_client
207 207 f.expects(:request).returns({'auth' => {'token' => 'some_auth_token','user' => {}}})
208 208 f.get_token_from('some_frob')
209 209 assert_equal 'some_auth_token', f.auth_token
210 210 end
211   -
  211 +
212 212 def test_should_store_authenticated_user_details_in_client
213 213 f = flickr_client
214   - f.expects(:request).returns({ 'auth' => { 'token' => 'some_auth_token',
215   - 'user' => { 'nsid' => 'foo123',
  214 + f.expects(:request).returns({ 'auth' => { 'token' => 'some_auth_token',
  215 + 'user' => { 'nsid' => 'foo123',
216 216 'username' => 'some_user', 'fullname' => 'Some User'}}})
217 217 f.get_token_from('some_frob')
218 218 assert_kind_of Flickr::User, user = f.user
@@ -221,14 +221,14 @@ def test_should_store_authenticated_user_details_in_client
221 221 assert_equal 'Some User', user.name
222 222 assert_equal f, user.client
223 223 end
224   -
  224 +
225 225 # photos method tests
226 226 def test_should_get_recent_photos_if_no_params_for_photos
227 227 f = flickr_client
228 228 f.expects(:photos_search)
229 229 f.photos
230 230 end
231   -
  231 +
232 232 # photos_search method tests
233 233 def test_should_search_photos
234 234 f = authenticated_flickr_client
@@ -236,7 +236,7 @@ def test_should_search_photos
236 236 photos = f.photos_search
237 237 assert_kind_of Flickr::Photo, photos.first
238 238 end
239   -
  239 +
240 240 # users method tests
241 241 def test_should_find_user_from_email
242 242 f = flickr_client
@@ -245,34 +245,34 @@ def test_should_find_user_from_email
245 245 assert_equal "12037949632@N01", user.id
246 246 assert_equal "Stewart", user.username
247 247 end
248   -
  248 +
249 249 def test_should_find_user_from_username_if_fails_to_get_from_email
250 250 f = flickr_client
251 251 f.expects(:request).with('people.findByEmail', anything).raises
252 252 f.expects(:request).with('people.findByUsername', anything).returns(dummy_user_response)
253 253 assert_kind_of Flickr::User, f.users("email@test.com")
254 254 end
255   -
  255 +
256 256 def test_should_pass_on_flickr_client_when_finding_user
257 257 f = flickr_client
258 258 f.stubs(:request).returns(dummy_user_response)
259 259 user = f.users("email@test.com")
260 260 assert_equal f, user.client
261 261 end
262   -
  262 +
263 263 # groups method tests
264 264 def test_should_search_for_given_group
265 265 f = flickr_client
266 266 f.expects(:request).with("groups.search", {"text" => "foo"}).returns(dummy_groups_response)
267 267 f.groups("foo")
268 268 end
269   -
  269 +
270 270 def test_should_search_for_given_group_with_additional_params
271 271 f = flickr_client
272 272 f.expects(:request).with("groups.search", {"text" => "foo", "per_page" => "1"}).returns(dummy_groups_response)
273 273 f.groups("foo", "per_page" => "1")
274 274 end
275   -
  275 +
276 276 def test_should_instantiate_groups_from_search_response
277 277 f = flickr_client
278 278 f.stubs(:request).returns(dummy_groups_response)
@@ -283,7 +283,7 @@ def test_should_instantiate_groups_from_search_response
283 283 assert_equal "0", group.eighteenplus
284 284 assert_equal f, group.client
285 285 end
286   -
  286 +
287 287 def test_should_instantiate_groups_from_search_response_with_single_group_returned
288 288 f = flickr_client
289 289 f.stubs(:request).returns(dummy_single_group_response)
@@ -291,51 +291,51 @@ def test_should_instantiate_groups_from_search_response_with_single_group_return
291 291 assert_equal 1, groups.size
292 292 assert_equal "group1", groups.first.id
293 293 end
294   -
  294 +
295 295 # ##### DIRECT MODE
296   - #
  296 + #
297 297 # def test_test_echo
298 298 # assert_equal @f.test_echo['stat'], 'ok'
299 299 # end
300 300 # def test_test_login
301 301 # assert_equal @f.test_login['stat'], 'ok'
302 302 # end
303   - #
304   - #
  303 + #
  304 + #
305 305 # ##### BASICS
306   - #
  306 + #
307 307 # def test_login
308 308 # assert_equal @username, @f.user.getInfo.username
309 309 # end
310   - #
  310 + #
311 311 # def test_find_by_url
312 312 # assert_equal @group_id, @f.find_by_url(@group_url).getInfo.id # find group by URL
313 313 # assert_equal @user_id, @f.find_by_url(@user_url).getInfo.id # find user by URL
314 314 # end
315   - #
  315 + #
316 316 # def test_licenses
317 317 # assert_kind_of Array, @f.licenses # find all licenses
318 318 # end
319   - #
320   -
321   - #
  319 + #
  320 +
  321 + #
322 322 # Flickr#photos tests
323   - #
324   -
325   -
  323 + #
  324 +
  325 +
326 326 # ##### Flickr::User tests
327   - #
  327 + #
328 328 def test_should_instantiate_user
329 329 user = new_user
330 330 assert_equal 'foo123', user.id
331 331 assert_equal 'some_user', user.username
332 332 assert_equal 'bar', user.instance_variable_get(:@foo) # should collect all other params up and store as instance variables
333 333 end
334   -
  334 +
335 335 def test_should_instantiate_new_user_with_old_api
336 336 Flickr.any_instance.stubs(:login) # stub logging in
337   - user = Flickr::User.new('foo123',
338   - 'some_user',
  337 + user = Flickr::User.new('foo123',
  338 + 'some_user',
339 339 'email@test.com', # email irrelevant since Flickr API no longer supports authentication in this way
340 340 'password', # password irrelevant since Flickr API no longer supports authentication in this way
341 341 'bar456')
@@ -345,59 +345,59 @@ def test_should_instantiate_new_user_with_old_api
345 345 assert_equal 'password', user.instance_variable_get(:@password)
346 346 assert_equal 'bar456', user.client.api_key
347 347 end
348   -
  348 +
349 349 def test_should_instantiate_new_client_when_instantiating_user_if_no_client_passed_in_params
350 350 f = flickr_client
351 351 Flickr.expects(:new).returns(f)
352 352 user = new_user( 'api_key' => 'an_api_key' )
353 353 assert_equal f, user.client
354 354 end
355   -
  355 +
356 356 def test_should_not_instantiate_new_client_when_instantiating_user_if_client_passed_in_params
357 357 f = flickr_client
358 358 Flickr.expects(:new).never
359 359 user = new_user( 'client' => f )
360 360 assert_equal f, user.client
361 361 end
362   -
  362 +
363 363 def test_should_not_instantiate_client_if_no_api_key_passed
364 364 Flickr.expects(:new).never
365 365 user = new_user
366 366 assert_nil user.client
367 367 end
368   -
  368 +
369 369 def test_should_build_url_for_users_profile_page_using_user_id
370 370 Flickr.any_instance.expects(:http_get).never
371 371 assert_equal "http://www.flickr.com/people/foo123/", new_user.url
372 372 end
373   -
  373 +
374 374 def test_should_build_url_for_users_photos_page_using_user_id
375 375 Flickr.any_instance.expects(:http_get).never
376 376 assert_equal "http://www.flickr.com/photos/foo123/", new_user.photos_url
377 377 end
378   -
  378 +
379 379 def test_should_get_pretty_url_for_users_profile_page
380 380 f = flickr_client
381 381 f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}})
382   -
  382 +
383 383 assert_equal "http://www.flickr.com/people/killer_bob/", new_user( 'client' => f ).pretty_url
384 384 end
385   -
  385 +
386 386 def test_should_cache_pretty_url_for_users_profile_page
387 387 f = flickr_client
388 388 user = new_user( 'client' => f )
389 389 f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}}) # expects only one call
390   -
  390 +
391 391 user.pretty_url
392 392 user.pretty_url
393 393 end
394   -
  394 +
395 395 def test_should_get_users_public_groups
396 396 f = flickr_client
397 397 f.expects(:request).with("people.getPublicGroups", anything).returns(dummy_groups_response)
398 398 new_user( 'client' => f ).groups
399 399 end
400   -
  400 +
401 401 def test_should_instantiate_users_public_groups
402 402 f = flickr_client
403 403 f.stubs(:request).returns(dummy_groups_response)
@@ -411,7 +411,7 @@ def test_should_instantiate_users_public_groups
411 411 assert_equal "0", group.eighteenplus
412 412 assert_equal f, group.client
413 413 end
414   -
  414 +
415 415 def test_should_instantiate_users_public_groups_when_only_one_returned
416 416 f = flickr_client
417 417 f.stubs(:request).returns(dummy_single_group_response)
@@ -437,35 +437,35 @@ def test_should_get_users_popular_tags
437 437 assert_kind_of Array, pop_tags
438 438 assert_equal pop_tags, [{"tag"=>"design", "count"=>"94"}, {"tag"=>"offf08", "count"=>"94"}, {"tag"=>"ruby", "count"=>"3"}, {"tag"=>"rubyonrails", "count"=>"3"}, {"tag"=>"wbs", "count"=>"3"}, {"tag"=>"webreakstuff", "count"=>"97"}]
439 439 end
440   -
  440 +
441 441 # def test_getInfo
442 442 # @u.getInfo
443 443 # assert_equal @username, @u.username
444 444 # end
445   - #
  445 + #
446 446 # def test_groups
447 447 # assert_kind_of Flickr::Group, @u.groups.first # public groups
448 448 # end
449   - #
450   - #
  449 + #
  450 + #
451 451 # def test_contacts
452 452 # assert_kind_of Flickr::User, @u.contacts.first # public contacts
453 453 # end
454   - #
  454 + #
455 455 # def test_favorites
456 456 # assert_kind_of Flickr::Photo, @u.favorites.first # public favorites
457 457 # end
458   - #
  458 + #
459 459 # def test_photosets
460 460 # assert_kind_of Flickr::Photoset, @u.photosets.first # public photosets
461 461 # end
462   - #
  462 + #
463 463 # def test_contactsPhotos
464 464 # assert_kind_of Flickr::Photo, @u.contactsPhotos.first # contacts' favorites
465 465 # end
466   -
  466 +
467 467 # User#photos tests
468   -
  468 +
469 469 def test_should_get_users_public_photos
470 470 client = mock
471 471 client.expects(:photos_request).with('people.getPublicPhotos', {'user_id' => 'some_id'}).returns([new_photo, new_photo])
@@ -485,7 +485,7 @@ def test_should_instantiate_favorite_photos_with_id_and_all_params_returned_by_q
485 485 user = Flickr::User.new("some_id", "some_user", nil, nil, "some_api_key")
486 486 user.favorites
487 487 end
488   -
  488 +
489 489 def test_should_instantiate_contacts_photos_with_id_and_all_params_returned_by_query
490 490 client = mock
491 491 client.expects(:photos_request).with('photos.getContactsPublicPhotos', {'user_id' => 'some_id'})
@@ -493,7 +493,7 @@ def test_should_instantiate_contacts_photos_with_id_and_all_params_returned_by_q
493 493 user = Flickr::User.new('some_id', "some_user", nil, nil, "some_api_key")
494 494 user.contactsPhotos
495 495 end
496   -
  496 +
497 497 # ##### Flickr::Photo tests
498 498
499 499 def test_should_initialize_photo_from_id
@@ -506,7 +506,7 @@ def test_should_save_extra_params_as_instance_variables
506 506 assert_equal 'value1', photo.instance_variable_get(:@key1)
507 507 assert_equal 'value2', photo.instance_variable_get(:@key2)
508 508 end
509   -
  509 +
510 510 def test_should_be_able_to_access_instance_variables_through_hash_like_interface
511 511 photo = Flickr::Photo.new
512 512 photo.instance_variable_set(:@key1, 'value1')
@@ -515,13 +515,13 @@ def test_should_be_able_to_access_instance_variables_through_hash_like_interface
515 515 assert_nil photo[:key2]
516 516 assert_nil photo['key2']
517 517 end
518   -
  518 +
519 519 def test_should_get_and_store_other_info_for_photo
520 520 Flickr.any_instance.stubs(:http_get).returns(photo_info_xml_response)
521 521 photo = Flickr::Photo.new('foo123', 'some_api_key')
522   -
  522 +
523 523 assert_equal "1964 120 amazon estate", photo.title # calling #title method triggers getting of info
524   - assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
  524 + assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
525 525 assert_equal "3142", photo.instance_variable_get(:@server)
526 526 assert_equal "ae75bd3111", photo.instance_variable_get(:@secret)
527 527 assert_equal "4", photo.instance_variable_get(:@farm)
@@ -547,11 +547,11 @@ def test_should_get_and_store_other_info_for_photo
547 547 assert_kind_of Flickr::User, owner = photo.instance_variable_get(:@owner)
548 548 assert_equal "Rootes_arrow_1725", owner.username
549 549 end
550   -
  550 +
551 551 def test_should_get_and_other_info_for_photo_when_some_attributes_missing
552 552 Flickr.any_instance.stubs(:http_get).returns(sparse_photo_info_xml_response)
553 553 photo = Flickr::Photo.new('foo123', 'some_api_key')
554   -
  554 +
555 555 assert_equal "1964 120 amazon estate", photo.title # calling #title method triggers getting of info
556 556 assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
557 557 assert_equal( {}, photo.instance_variable_get(:@description))
@@ -559,17 +559,17 @@ def test_should_get_and_other_info_for_photo_when_some_attributes_missing
559 559 assert_nil photo.instance_variable_get(:@tags)
560 560 assert_equal "1", photo.instance_variable_get(:@comments)
561 561 end
562   -
  562 +
563 563 def test_should_not_get_info_more_than_once
564 564 Flickr.any_instance.expects(:http_get).returns(photo_info_xml_response) # expects only one call
565 565 photo = Flickr::Photo.new('foo123', 'some_api_key')
566   -
  566 +
567 567 photo.description # calling #description method triggers getting of info
568 568 photo.instance_variable_set(:@description, nil) # set description to nil
569 569 photo.description # call #description method again
570 570 end
571   -
572   - #
  571 +
  572 + #
573 573 # owner tests
574 574 def test_should_return_owner_when_flickr_user
575 575 user = Flickr::User.new
@@ -577,65 +577,65 @@ def test_should_return_owner_when_flickr_user
577 577
578 578 assert_equal user, photo.owner
579 579 end
580   -
  580 +
581 581 def test_should_get_info_on_owner_if_not_known
582 582 photo = new_photo("owner" => nil)
583 583 # stubbing private methods causes problems so we mock client method, which is what Photo#getInfo users to make API call
584   - Flickr.any_instance.expects(:photos_getInfo).returns('photo' => { 'owner'=>{'nsid'=>'abc123', 'username'=>'SomeUserName', 'realname'=>"", 'location'=>''},
585   - 'notes' => {}, 'tags' => {}, 'urls' => {'url' => {'content' => 'http://prettyurl'}}})
  584 + Flickr.any_instance.expects(:photos_getInfo).returns('photo' => { 'owner'=>{'nsid'=>'abc123', 'username'=>'SomeUserName', 'realname'=>"", 'location'=>''},
  585 + 'notes' => {}, 'tags' => {}, 'urls' => {'url' => {'content' => 'http://prettyurl'}}})
586 586
587 587 owner = photo.owner
588 588 assert_kind_of Flickr::User, owner
589 589 assert_equal 'abc123', owner.id
590 590 assert_equal 'SomeUserName', owner.username
591 591 end
592   -
  592 +
593 593 def test_should_instantiate_flickr_user_from_owner_id_if_we_have_it
594 594 photo = Flickr::Photo.new
595 595 photo.instance_variable_set(:@owner, "some_user_id")
596 596 Flickr.any_instance.expects(:photos_getInfo).never
597   -
  597 +
598 598 user = photo.owner
599 599 assert_kind_of Flickr::User, user
600 600 assert_equal "some_user_id", user.id
601 601 end
602   -
  602 +
603 603 def test_should_cache_owner_when_instantiated
604 604 user = Flickr::User.new
605 605 photo = Flickr::Photo.new
606 606 photo.instance_variable_set(:@owner, "some_user_id")
607 607 Flickr::User.expects(:new).returns(user)
608   -
  608 +
609 609 photo.owner
610 610 photo.owner # call twice but mock expects only one call
611 611 end
612   -
613   - #
  612 +
  613 + #
614 614 # image_source_uri_from_self tests
615 615 def test_should_build_image_source_uri_from_self
616 616 assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
617 617 new_photo.send(:image_source_uri_from_self) # no size specified
618 618 end
619   -
  619 +
620 620 def test_should_build_image_source_uri_from_self_for_given_size
621 621 assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg",
622 622 new_photo.send(:image_source_uri_from_self, "Small") # size specified
623 623 end
624   -
  624 +
625 625 def test_should_build_image_source_uri_from_self_for_default_size_when_explicitly_asked_for
626 626 assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
627 627 new_photo.send(:image_source_uri_from_self, "Medium") # medium size specified -- the default
628 628 end
629   -
  629 +
630 630 def test_should_build_image_source_uri_from_self_for_default_size_when_unknown_size_asked_for
631 631 assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
632 632 new_photo.send(:image_source_uri_from_self, "Dummy") # bad size specified
633 633 end
634   -
  634 +
635 635 def test_should_return_nil_for_image_source_uri_if_no_attributes
636   - assert_nil Flickr::Photo.new.send(:image_source_uri_from_self)
  636 + assert_nil Flickr::Photo.new.send(:image_source_uri_from_self)
637 637 end
638   -
  638 +
639 639 def test_should_return_nil_for_image_source_uri_if_missing_required_attributes
640 640 assert_nil Flickr::Photo.new("1418878", nil, "farm" => "1").send(:image_source_uri_from_self)
641 641 end
@@ -651,42 +651,42 @@ def test_uri_for_photo_from_self_should_normalize_size
651 651 assert_equal photo.send(:uri_for_photo_from_self, 'Large'),
652 652 photo.send(:uri_for_photo_from_self, :large)
653 653 end
654   -
  654 +
655 655 def test_should_get_source_uri_by_building_from_self_if_possible
656 656 photo = Flickr::Photo.new
657 657 photo.expects(:image_source_uri_from_self).with('Medium').returns(true) # return any non-false-evaluating value so that sizes method isn't called
658 658 photo.source
659 659 end
660   -
  660 +
661 661 def test_should_get_source_uri_by_building_from_self_if_possible_requesting_source_for_given_size
662 662 photo = Flickr::Photo.new
663 663 photo.expects(:image_source_uri_from_self).with('Large').returns(true) # return any non-false-evaluating value so that sizes method isn't called
664 664 photo.source('Large')
665 665 end
666   -
  666 +
667 667 def test_should_get_source_uri_by_calling_sizes_method_if_no_luck_building_uri
668 668 photo = Flickr::Photo.new
669 669 photo.stubs(:image_source_uri_from_self) # ...and hence returns nil
670 670 photo.expects(:sizes).with('Medium').returns({})
671 671 photo.source
672 672 end
673   -
  673 +
674 674 def test_should_build_uri_for_photo_from_self
675   - assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self)
  675 + assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self)
676 676 end
677   -
  677 +
678 678 def test_should_build_uri_for_photo_from_self_when_owner_is_a_string
679   - assert_equal "http://www.flickr.com/photos/789user321/1418878", new_photo('owner' => "789user321").send(:uri_for_photo_from_self)
  679 + assert_equal "http://www.flickr.com/photos/789user321/1418878", new_photo('owner' => "789user321").send(:uri_for_photo_from_self)
680 680 end
681   -
  681 +
682 682 def test_should_build_uri_for_photo_from_self_for_given_size
683 683 assert_equal "http://www.flickr.com/photos/abc123/1418878/sizes/s/", new_photo.send(:uri_for_photo_from_self, "Small")
684 684 end
685   -
  685 +
686 686 def test_should_build_uri_for_photo_from_self_with_unknown_size
687 687 assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self, "Dummy")
688 688 end
689   -
  689 +
690 690 def test_should_return_nil_for_uri_for_photo_when_no_user_id
691 691 assert_nil Flickr::Photo.new("1418878", nil).send(:uri_for_photo_from_self)
692 692 end
@@ -694,7 +694,7 @@ def test_should_return_nil_for_uri_for_photo_when_no_user_id
694 694 def test_should_return_nil_for_uri_for_photo_when_no_photo_id
695