flickrmocks 0.8.15 → 0.9.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.
Files changed (53) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile.lock +123 -0
  3. data/README.rdoc +104 -30
  4. data/Rakefile +12 -0
  5. data/flickrmocks.gemspec +3 -1
  6. data/lib/flickr_mocks/api/api.rb +80 -27
  7. data/lib/flickr_mocks/api/flickr.rb +69 -23
  8. data/lib/flickr_mocks/api/helpers.rb +25 -12
  9. data/lib/flickr_mocks/api/options.rb +71 -53
  10. data/lib/flickr_mocks/api/sanitize.rb +129 -20
  11. data/lib/flickr_mocks/fixtures.rb +7 -1
  12. data/lib/flickr_mocks/flickraw/custom_clone.rb +3 -1
  13. data/lib/flickr_mocks/flickraw/custom_compare.rb +4 -0
  14. data/lib/flickr_mocks/flickraw/custom_marshal.rb +7 -2
  15. data/lib/flickr_mocks/flickraw/flickraw.rb +6 -0
  16. data/lib/flickr_mocks/helpers.rb +8 -1
  17. data/lib/flickr_mocks/models/commons_institution.rb +45 -34
  18. data/lib/flickr_mocks/models/commons_institutions.rb +85 -75
  19. data/lib/flickr_mocks/models/helpers.rb +13 -6
  20. data/lib/flickr_mocks/models/models.rb +7 -0
  21. data/lib/flickr_mocks/models/photo.rb +76 -75
  22. data/lib/flickr_mocks/models/photo_details.rb +71 -69
  23. data/lib/flickr_mocks/models/photo_dimensions.rb +80 -78
  24. data/lib/flickr_mocks/models/photo_search.rb +115 -88
  25. data/lib/flickr_mocks/models/photo_size.rb +57 -56
  26. data/lib/flickr_mocks/models/photo_sizes.rb +68 -67
  27. data/lib/flickr_mocks/models/photos.rb +104 -99
  28. data/lib/flickr_mocks/stubs.rb +151 -14
  29. data/lib/flickr_mocks/version.rb +7 -1
  30. data/spec/api/api_spec.rb +26 -8
  31. data/spec/api/flickr_spec.rb +19 -19
  32. data/spec/api/helper_spec.rb +20 -20
  33. data/spec/api/options_spec.rb +170 -124
  34. data/spec/api/sanitize_spec.rb +174 -59
  35. data/spec/base/stubs_spec.rb +37 -74
  36. data/spec/base/version_spec.rb +11 -4
  37. data/spec/models/commons_institution_spec.rb +3 -2
  38. data/spec/models/commons_institutions_spec.rb +34 -5
  39. data/spec/models/helpers_spec.rb +7 -6
  40. data/spec/models/photo_details_spec.rb +12 -11
  41. data/spec/models/photo_dimensions_spec.rb +5 -4
  42. data/spec/models/photo_search_spec.rb +50 -8
  43. data/spec/models/photo_size_spec.rb +4 -3
  44. data/spec/models/photo_sizes_spec.rb +6 -5
  45. data/spec/models/photo_spec.rb +6 -4
  46. data/spec/models/photos_spec.rb +9 -7
  47. data/spec/shared_examples/hash_options/date_hash_option.rb +42 -0
  48. data/spec/shared_examples/hash_options/page_hash_option.rb +23 -0
  49. data/spec/shared_examples/hash_options/perpage_hash_option.rb +43 -0
  50. data/spec/shared_examples/hash_options/tag_mode_hash_option.rb +31 -0
  51. data/spec/shared_examples/stub_helpers.rb +140 -0
  52. data/spec/spec_helper.rb +5 -5
  53. metadata +55 -16
@@ -1,93 +1,94 @@
1
1
  module FlickrMocks
2
- class PhotoSizes
3
-
4
- def initialize(object)
5
- self.delegated_to_object= object
6
- end
2
+ module Models
3
+ class PhotoSizes
4
+ def initialize(object)
5
+ self.delegated_to_object= object
6
+ end
7
7
 
8
- def id
9
- @delegated_to_object.first.id
10
- end
8
+ def id
9
+ @delegated_to_object.first.id
10
+ end
11
11
 
12
- def secret
13
- @delegated_to_object.first.secret
14
- end
12
+ def secret
13
+ @delegated_to_object.first.secret
14
+ end
15
15
 
16
- def sizes
17
- @delegated_to_object
18
- end
16
+ def sizes
17
+ @delegated_to_object
18
+ end
19
19
 
20
- def available_sizes
21
- @available_sizes ||= sizes.map do |size|
22
- size.size.to_sym
20
+ def available_sizes
21
+ @available_sizes ||= sizes.map do |size|
22
+ size.size.to_sym
23
+ end
24
+ @available_sizes
23
25
  end
24
- @available_sizes
25
- end
26
26
 
27
- def collection
28
- @collection ||= ::WillPaginate::Collection.create(1, sizes.length, sizes.length) do |obj|
29
- obj.replace(sizes)
27
+ def collection
28
+ @collection ||= ::WillPaginate::Collection.create(1, sizes.length, sizes.length) do |obj|
29
+ obj.replace(sizes)
30
+ end
31
+ @collection
30
32
  end
31
- @collection
32
- end
33
33
 
34
34
 
35
- def to_s
36
- PhotoDimensions.new(@delegated_to_object.map do |size|
37
- "#{size.size}:#{size.width}x#{size.height}"
38
- end.join(',')).to_s
39
- end
35
+ def to_s
36
+ PhotoDimensions.new(@delegated_to_object.map do |size|
37
+ "#{size.size}:#{size.width}x#{size.height}"
38
+ end.join(',')).to_s
39
+ end
40
40
 
41
- def ==(other)
42
- return false unless self.class == other.class
43
- @delegated_to_object == other.instance_eval('@delegated_to_object')
44
- end
41
+ def ==(other)
42
+ return false unless self.class == other.class
43
+ @delegated_to_object == other.instance_eval('@delegated_to_object')
44
+ end
45
45
 
46
- def possible_sizes
47
- Models::Helpers.possible_sizes
48
- end
46
+ def possible_sizes
47
+ Models::Helpers.possible_sizes
48
+ end
49
49
 
50
- # metaprogramming methods
51
- alias :old_methods :methods
52
- def methods
53
- delegated_instance_methods + old_methods
54
- end
50
+ # metaprogramming methods
51
+ alias :old_methods :methods
52
+ def methods
53
+ delegated_instance_methods + old_methods
54
+ end
55
55
 
56
- def method_missing(id,*args,&block)
57
- return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
58
- return nil if possible_sizes.include?(name)
59
- super
60
- end
56
+ def method_missing(id,*args,&block)
57
+ return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
58
+ return nil if possible_sizes.include?(name)
59
+ super
60
+ end
61
61
 
62
- alias :old_respond_to? :respond_to?
63
- def respond_to?(method)
64
- old_respond_to?(method) || delegated_instance_methods.include?(method)
65
- end
62
+ alias :old_respond_to? :respond_to?
63
+ def respond_to?(method)
64
+ old_respond_to?(method) || delegated_instance_methods.include?(method)
65
+ end
66
66
 
67
- def delegated_instance_methods
68
- possible_sizes + FlickrMocks::Models::Helpers.array_accessor_methods
69
- end
67
+ def delegated_instance_methods
68
+ possible_sizes + FlickrMocks::Models::Helpers.array_accessor_methods
69
+ end
70
70
 
71
- # cloning methods
72
- def initialize_copy(orig)
73
- super
74
- @delegated_to_object = @delegated_to_object.map do |data|
75
- data.clone
71
+ # cloning methods
72
+ def initialize_copy(orig)
73
+ super
74
+ @delegated_to_object = @delegated_to_object.map do |data|
75
+ data.clone
76
+ end
76
77
  end
77
- end
78
78
 
79
79
 
80
- private
80
+ private
81
81
 
82
- def delegated_to_object=(data)
83
- raise ArgumentError, 'FlickRaw::Response expected' unless data.class == FlickRaw::ResponseList
84
- @delegated_to_object = []
85
- data.each do |datum|
86
- @delegated_to_object.push PhotoSize.new datum
82
+ def delegated_to_object=(data)
83
+ raise ArgumentError, 'FlickRaw::Response expected' unless data.class == FlickRaw::ResponseList
84
+ @delegated_to_object = []
85
+ data.each do |datum|
86
+ @delegated_to_object.push PhotoSize.new datum
87
+ end
87
88
  end
88
- end
89
89
 
90
90
 
91
+ end
91
92
  end
92
- end
93
93
 
94
+ end
@@ -1,130 +1,135 @@
1
1
  module FlickrMocks
2
- class Photos
3
- attr_reader :current_page,:per_page,:total_entries,:total_pages,:photos
4
- alias :perpage :per_page
5
-
6
- @defaults = FlickrMocks::Models::Helpers.paging_defaults.clone
2
+ module Models
3
+ class Photos
4
+ attr_reader :current_page,:per_page,:total_entries,:total_pages,:photos
5
+ alias :perpage :per_page
7
6
 
7
+
8
8
 
9
- class << self
10
- attr_accessor :defaults
11
- end
9
+ class << self
10
+ attr_writer :defaults
11
+ def defaults
12
+ @defaults ||= FlickrMocks::Models::Helpers.paging_defaults().clone
13
+ @defaults
14
+ end
15
+ end
12
16
 
13
- def initialize(data)
14
- raise ArgumentError, 'Expecting class of FlickRaw::ResponseList' unless data.class == FlickRaw::ResponseList
15
- self.current_page= data.page
16
- self.per_page= data.perpage
17
- self.total_entries= data.total
18
- self.total_pages = data.pages
19
- self.photos = data.photo
20
- end
17
+ def initialize(data)
18
+ raise ArgumentError, 'Expecting class of FlickRaw::ResponseList' unless data.class == FlickRaw::ResponseList
19
+ self.current_page= data.page
20
+ self.per_page= data.perpage
21
+ self.total_entries= data.total
22
+ self.total_pages = data.pages
23
+ self.photos = data.photo
24
+ end
21
25
 
22
- def default(value)
23
- Photos.defaults[value.to_s.to_sym]
24
- end
26
+ def default(value)
27
+ Photos.defaults[value.to_s.to_sym]
28
+ end
25
29
 
26
- def capped_entries
27
- total_entries > max_entries ? max_entries : total_entries
28
- end
30
+ def capped_entries
31
+ total_entries > max_entries ? max_entries : total_entries
32
+ end
29
33
 
30
- def capped?
31
- max_entries < total_entries ? true : false
32
- end
34
+ def capped?
35
+ max_entries < total_entries ? true : false
36
+ end
33
37
 
34
- def max_entries
35
- default(:max_entries)
36
- end
38
+ def max_entries
39
+ default(:max_entries)
40
+ end
37
41
 
38
- def pages
39
- max_pages = default(:max_entries)/perpage
40
- total_pages > max_pages ? max_pages : total_pages
41
- end
42
+ def pages
43
+ max_pages = default(:max_entries)/perpage
44
+ total_pages > max_pages ? max_pages : total_pages
45
+ end
42
46
 
43
- def usable_photos
44
- photos.clone.keep_if(&:usable?)
45
- end
47
+ def usable_photos
48
+ photos.clone.keep_if(&:usable?)
49
+ end
46
50
 
47
- def collection(usable=nil)
48
- case usable
49
- when true
50
- usable_photos = photos.clone.keep_if(&:usable?)
51
- ::WillPaginate::Collection.create(1, per_page, usable_photos.length) do |obj|
52
- obj.replace(usable_photos)
53
- end
54
- else
55
- ::WillPaginate::Collection.create(current_page, per_page, capped_entries) do |obj|
56
- obj.replace(photos)
51
+ def collection(usable=nil)
52
+ case usable
53
+ when true
54
+ usable_photos = photos.clone.keep_if(&:usable?)
55
+ ::WillPaginate::Collection.create(1, per_page, usable_photos.length) do |obj|
56
+ obj.replace(usable_photos)
57
+ end
58
+ else
59
+ ::WillPaginate::Collection.create(current_page, per_page, capped_entries) do |obj|
60
+ obj.replace(photos)
61
+ end
57
62
  end
58
63
  end
59
- end
60
64
 
61
65
 
62
- def ==(other)
63
- return false unless other.class == Photos
64
- return false unless [:current_page,:per_page,:total_entries,:total_pages].inject(true) do |state,method|
65
- state && (self.send(method) == other.send(method))
66
+ def ==(other)
67
+ return false unless other.class == Photos
68
+ return false unless [:current_page,:per_page,:total_entries,:total_pages].inject(true) do |state,method|
69
+ state && (self.send(method) == other.send(method))
70
+ end
71
+ other.respond_to?(:photos) ? photos == other.photos : false
66
72
  end
67
- other.respond_to?(:photos) ? photos == other.photos : false
68
- end
69
73
 
70
74
 
71
- # metaprogramming methods
72
- def method_missing(id,*args,&block)
73
- return photos.send(id,*args,&block) if delegated_instance_methods.include?(id)
74
- super
75
- end
75
+ # metaprogramming methods
76
+ def method_missing(id,*args,&block)
77
+ return photos.send(id,*args,&block) if delegated_instance_methods.include?(id)
78
+ super
79
+ end
76
80
 
77
- alias :old_respond_to? :respond_to?
78
- def respond_to?(method)
79
- old_respond_to?(method) || delegated_instance_methods.include?(method)
80
- end
81
+ alias :old_respond_to? :respond_to?
82
+ def respond_to?(method)
83
+ old_respond_to?(method) || delegated_instance_methods.include?(method)
84
+ end
81
85
 
82
- alias :old_methods :methods
83
- def methods
84
- delegated_instance_methods + old_methods
85
- end
86
+ alias :old_methods :methods
87
+ def methods
88
+ delegated_instance_methods + old_methods
89
+ end
86
90
 
87
- def delegated_instance_methods
88
- FlickrMocks::Models::Helpers.array_accessor_methods
89
- end
91
+ def delegated_instance_methods
92
+ FlickrMocks::Models::Helpers.array_accessor_methods
93
+ end
90
94
 
91
- # custom cloning methods
92
- def initialize_copy(orig)
93
- super
94
- @photos = @photos.map do |photo|
95
- photo.clone
95
+ # custom cloning methods
96
+ def initialize_copy(orig)
97
+ super
98
+ @photos = @photos.map do |photo|
99
+ photo.clone
100
+ end
96
101
  end
97
- end
98
-
99
- private
100
- def current_page=(value)
101
- raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
102
- @current_page=value.to_i
103
- end
104
102
 
105
- def per_page=(value)
106
- raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
107
- @per_page=value.to_i
108
- end
103
+ private
104
+ def current_page=(value)
105
+ raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
106
+ @current_page=value.to_i
107
+ end
109
108
 
110
- def total_entries=(value)
111
- raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
112
- @total_entries=value.to_i
113
- end
109
+ def per_page=(value)
110
+ raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
111
+ @per_page=value.to_i
112
+ end
114
113
 
115
- def total_pages=(value)
116
- raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
117
- @total_pages=value.to_i
118
- end
114
+ def total_entries=(value)
115
+ raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
116
+ @total_entries=value.to_i
117
+ end
119
118
 
120
- def photos=(photos)
121
- raise ArgumentError,"Expected argument that responds to :each but got class #{photos.class}" unless photos.respond_to?(:each)
122
- results = []
123
- photos.each do |photo|
124
- raise ArgumentError,"Expected FlickRaw::Response but was #{value.class}" unless photo.is_a?(FlickRaw::Response)
125
- results.push(Photo.new(photo))
119
+ def total_pages=(value)
120
+ raise ArgumentError,"Expected Fixnum but was #{value.class}" unless value.is_a?(Fixnum) or value.is_a?(String)
121
+ @total_pages=value.to_i
122
+ end
123
+
124
+ def photos=(photos)
125
+ raise ArgumentError,"Expected argument that responds to :each but got class #{photos.class}" unless photos.respond_to?(:each)
126
+ results = []
127
+ photos.each do |photo|
128
+ raise ArgumentError,"Expected FlickRaw::Response but was #{value.class}" unless photo.is_a?(FlickRaw::Response)
129
+ results.push(Models::Photo.new(photo))
130
+ end
131
+ @photos=results
126
132
  end
127
- @photos=results
128
133
  end
129
134
  end
130
135
  end
@@ -1,50 +1,166 @@
1
1
  module FlickrMocks
2
+ # wrapper for methods that are used for Stubbing FlickRaw queries and Api calls that
3
+ # access the Flickr API. These methods are useful for stubbing the Flickr API for
4
+ # your Rspec 2.0 tests.
2
5
  module Stubs
3
6
  module Api
7
+ # Once this method is called all subsequent calls to the following calls are stubbed:
8
+ #
9
+ # Api.photos
10
+ # Api.photo_details
11
+ # Api.photo
12
+ # Api.photo_sizes
13
+ # Api.interesting_photos
14
+ # Api.commons_institutions
4
15
  def self.all
16
+ # [:VERSION, :Stubs, :Helpers, :Fixtures, :Models, :Api, :CustomClone, :CustomCompare, :CustomMarshal]
5
17
  [:photos,:photo_details,:photo,:photo_sizes,
6
18
  :interesting_photos,:commons_institutions].each do |method|
7
19
  self.send(method)
8
20
  end
9
21
  end
10
22
 
23
+
24
+ # Once this method is called, all subsequent calls to Api.photos are stubbed.
25
+ # The stub returns an object of class Flickr::PhotoSearch.
26
+ # The return value for Api.photos hash depends on the
27
+ # the options hash:
28
+ #
29
+ # :search_terms => 'garbage' (returns empy list of photos)
30
+ # :owner_id => 'garbage' (returns empty list of photos)
31
+ # :owner_id => '<valid_id>' (returns list of photos that contain same author photos; valid_id is any string other than garbage)
32
+ # :search_terms => '<valid_tag>' (returns list of photos with different author photos (if :owner_id must be nil); valid_tag is any string other than 'garbage')
33
+ # :search_terms => nil and :owner_id => nil (raises FlickRaw::FailedResponse error)
11
34
  def self.photos
12
35
  lambda {::FlickrMocks::Api.stub(:photos) do |params|
13
36
  ::FlickrMocks::Stubs::Flickr.search
14
37
  case params
15
38
  when Hash then
16
- PhotoSearch.new flickr.photos.search(::FlickrMocks::Api.search_options(params)),::FlickrMocks::Api.search_params(params)
39
+ Models::PhotoSearch.new flickr.photos.search(::FlickrMocks::Api::Options.search(params)),params
17
40
  else
18
41
  raise ArgumentError
19
42
  end
20
43
  end}.call
21
44
  end
22
45
 
46
+ # Once this method is called, subsequent calls to Api.photo_details are stubbed.
47
+ # The stub returns an object of class Models::PhotoDetails.
48
+ # The return value for Api.photo_details stub depends on the
49
+ # state of the supplied options hash:
50
+ #
51
+ # :photo_id or :id => 'garbage' (raises FlickRaw::FailedResponse error)
52
+ # :photo_id or :id => nil (raises FlickRaw::FailedResponse error)
53
+ # :photo_id or :id => <valid_id> (returns a photo fixture with detailed information; valid_id can be any string other than 'garbage' )
23
54
  def self.photo_details
24
55
  lambda {::FlickrMocks::Api.stub(:photo_details) do |params|
25
56
  ::FlickrMocks::Stubs::Flickr.getInfo
26
57
  ::FlickrMocks::Stubs::Flickr.getSizes
27
58
  case params
28
59
  when Hash then
29
- PhotoDetails.new(flickr.photos.getInfo(::FlickrMocks::Api.photo_options(params)),
30
- flickr.photos.getSizes(::FlickrMocks::Api.photo_options(params)))
60
+ Models::PhotoDetails.new(flickr.photos.getInfo(::FlickrMocks::Api::Options.photo(params)),
61
+ flickr.photos.getSizes(::FlickrMocks::Api::Options.photo(params)))
31
62
  else
32
63
  raise ArgumentError
33
64
  end
34
65
  end}.call
35
66
  end
36
67
 
37
- end
68
+ # Once this method is called, all subsequent calls to Api.photo are stubbed.
69
+ # The stub returns an object of class Models::Photo. The return value for the Api.photo
70
+ # stub depends on the supplied options:
71
+ #
72
+ # :photo_id or :id => 'garbage' (raises Invaid ID error)
73
+ # :photo_id or :id => nil (raises invalid ID error)
74
+ # :photo_id or :id => <valid_id> (returns a photo fixture with detailed information; valid_id is any string other than 'garbage')
75
+ def self.photo
76
+ lambda{::FlickrMocks::Api.stub(:photo) do |params|
77
+ ::FlickrMocks::Stubs::Flickr.getInfo
78
+ case params
79
+ when Hash then
80
+ Models::Photo.new(::FlickrMocks::Api::Flickr.photo(params))
81
+ else
82
+ raise ArgumentError
83
+ end
84
+ end}.call
85
+ end
38
86
 
87
+ # Once this method is called, all subsequent calls to Api.photo_sizes are stubbed.
88
+ # The stub returns an object of class Models::PhotoSizes.
89
+ # The return value of Api.photo_sizes stub depends on the supplied options:
90
+ #
91
+ # :photo_id or :id => 'garbage' (raises FlickRaw::FailedResponse error)
92
+ # :photo_id or :id => nil (raises FlickRaw::FailedResponse error)
93
+ # :photo_id or :id => <valid_id> (returns list of photo sizes; valid_id is any string other than 'garbage')
94
+ def self.photo_sizes
95
+ lambda {::FlickrMocks::Api.stub(:photo_sizes) do |params|
96
+ ::FlickrMocks::Stubs::Flickr.getSizes
97
+ case params
98
+ when Hash then
99
+ Models::PhotoSizes.new(flickr.photos.getSizes(::FlickrMocks::Api::Options.photo(params)))
100
+ else
101
+ raise ArgumentError
102
+ end
103
+ end}.call
104
+ end
39
105
 
106
+ # Once this method is called, all subsequent calls to Api.interesting_photos
107
+ # are stubbed. The stub returns an object of class Models::PhotoSearch.
108
+ # The return value for Api.interesting_photos stub depends on the supplied
109
+ # options hash:
110
+ #
111
+ # :date => '2000-01-01' (returns empy list of photos)
112
+ # :date => 'garbage' (raises an error)
113
+ # :date => <valid_id> (returns interesting list of photos; date is any string other than 'garbage' and '2001-01-01')
114
+ def self.interesting_photos
115
+ lambda {::FlickrMocks::Api.stub(:interesting_photos) do |params|
116
+ ::FlickrMocks::Stubs::Flickr.interestingness
117
+ case params
118
+ when Hash then
119
+ Models::PhotoSearch.new(flickr.interestingness.getList(params),params)
120
+ else
121
+ raise ArgumentError
122
+ end
123
+ end}.call
124
+ end
125
+
126
+ # Once method is called all subsequent calls to Api.commons_institutions
127
+ # are stubbed.
128
+ def self.commons_institutions
129
+ lambda {::FlickrMocks::Api.stub(:commons_institutions) do |params|
130
+ ::FlickrMocks::Stubs::Flickr.commons_institutions
131
+ case params
132
+ when Hash then
133
+ CommonsInstitutions.new(::FlickrMocks::Api.flickr_commons_institutions,params)
134
+ else
135
+ raise ArgumentError
136
+ end
137
+ end}.call
138
+ end
139
+
140
+ end
141
+
142
+ # stubs low level FlickRaw Api calls to Flickr
40
143
  module Flickr
144
+ # Once this method is called, the following calls are stubbed:
145
+ # flickr.photos.search
146
+ # flickr.photos.getInfo
147
+ # flickr.photos.getSizes
148
+ # flickr.interestingness.getList
149
+ # flickr.commons.getInstitutions
41
150
  def self.all
42
151
  [:search,:getInfo,:getSizes,:interestingness,:commons_institutions].each do |method|
43
152
  self.send(method)
44
153
  end
45
154
  end
46
155
 
47
-
156
+ # Once this method are called, all subsequent calls to flickr.photos.search
157
+ # are stubbed. The return value for the flickr.photos.search depends on
158
+ # the supplied options hash:
159
+ #
160
+ # :tags => 'garbage' (returns empy list of photos)
161
+ # :user_id => 'garbage' (returns empty list of photos)
162
+ # :user_id => '<valid_id>' (returns list of photos that contain same author photos)
163
+ # :tags => '<valid_tag>' (returns list of photos with different author photos; only if valid author id is not provided)
48
164
  def self.search
49
165
  fixtures = Fixtures.instance
50
166
  lambda { flickr.photos.stub(:search) do |params|
@@ -56,10 +172,10 @@ module FlickrMocks
56
172
  fixtures.empty_photos
57
173
  elsif(params[:tags] && params[:user_id])
58
174
  fixtures.author_photos
59
- elsif params.has_key?(:tags)
60
- fixtures.photos
61
- elsif params.has_key?(:user_id)
175
+ elsif !params[:user_id].nil?
62
176
  fixtures.author_photos
177
+ elsif !params[:tags].nil?
178
+ fixtures.photos
63
179
  else
64
180
  raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.',
65
181
  'code','flickr.photos.search'
@@ -69,19 +185,26 @@ module FlickrMocks
69
185
  }.call
70
186
  end
71
187
 
188
+ # Once this method is called, all subsequent calls to flickr.photos.getInfo
189
+ # are stubbed. The return value for the flickr.photos.getInfo stub depends on
190
+ # the supplied options hash:
191
+ #
192
+ # :photo_id => 'garbage' (raises Invaid ID error)
193
+ # :photo_id => nil (raises invalid ID error)
194
+ # :photo_id => <valid_id> (returns a photo fixture with detailed information)
72
195
  def self.getInfo
73
196
  lambda {
74
197
  flickr.photos.stub(:getInfo) do |params|
75
198
  if !params.is_a?(Hash)
76
199
  raise FlickRaw::FailedResponse.new('Photo not found',
77
200
  'code', 'flickr.photos.getInfo')
78
- elsif !params.has_key?(:photo_id)
201
+ elsif !params.has_key?(:photo_id)
79
202
  raise FlickRaw::FailedResponse.new('Photo not found',
80
203
  'code', 'flickr.photos.getInfo')
81
204
  elsif params[:photo_id] == 'garbage'
82
205
  raise FlickRaw::FailedResponse.new('Photo "%s" not found (invalid ID)' % params[:photo_id],
83
206
  'code','flickr.photos.getInfo')
84
- elsif params[:photo_id] == nil
207
+ elsif params[:photo_id].nil?
85
208
  raise FlickRaw::FailedResponse.new('Photo "nil" not found (invalid ID)',
86
209
  'code','flickr.photos.getInfo')
87
210
  else
@@ -91,6 +214,13 @@ module FlickrMocks
91
214
  }.call
92
215
  end
93
216
 
217
+ # Once this method is called all subsequent calls for flickr.photos.getSizes
218
+ # are stubbed. The return value for the flickr.photos.getSizes stub depends
219
+ # on the supplied options hash:
220
+ #
221
+ # :photo_id => nil (raises FlickRaw::FailedResponse error)
222
+ # :photo_id => 'garbage' (raises FlickRaw::FailedResponse error)
223
+ # :photo_id => '<valid_id>' (returns a list of photo sizes)
94
224
  def self.getSizes
95
225
  lambda {
96
226
  flickr.photos.stub(:getSizes) do |params|
@@ -113,19 +243,24 @@ module FlickrMocks
113
243
  }.call
114
244
  end
115
245
 
246
+ # Once this method is called, all subsequent calls to flickr.interestingness.getList
247
+ # are stubbed. The return value for the flickr.interesting.getList stub depends
248
+ # on the supplied options hash.
249
+ #
250
+ # :date => '2000-01-01' (returns empy list of photos)
251
+ # :date => 'garbage' (raises an error)
252
+ # :date => <valid_id> (returns interesting list of photos)
116
253
  def self.interestingness
117
254
  lambda {
118
255
  flickr.interestingness.stub(:getList) do |params|
119
256
  if !params.is_a?(Hash)
120
257
  Fixtures.instance.interesting_photos
121
- elsif !params.has_key?(:date)
122
- Fixtures.instance.interesting_photos
258
+ elsif params[:date] == '2000-01-01'
259
+ Fixtures.instance.empty_photos
123
260
  elsif params[:date] == 'garbage'
124
261
  raise FlickRaw::FailedResponse.new('Not a valid date string',
125
262
  'code','flickr.interestingness.getList'
126
263
  )
127
- elsif params[:date] == '2000-01-01'
128
- Fixtures.instance.empty_photos
129
264
  else
130
265
  Fixtures.instance.interesting_photos
131
266
  end
@@ -133,6 +268,8 @@ module FlickrMocks
133
268
  }.call
134
269
  end
135
270
 
271
+ # Once called, all subsequent calls to flickr.commons.getInstitutions are stubbed.
272
+ # The flickr.commons.getInstitutions stub simply returns a list of commons institutions.
136
273
  def self.commons_institutions
137
274
  lambda {
138
275
  flickr.commons.stub(:getInstitutions) do
@@ -1,4 +1,10 @@
1
1
 
2
2
  module FlickrMocks
3
- VERSION = '0.8.15'
3
+ # version for FlickrMocks gem
4
+ VERSION = '0.9.0'
5
+
6
+ # returns the version for FlickrMocks gem
7
+ def self.version
8
+ VERSION
9
+ end
4
10
  end