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.
- data/.gitignore +3 -0
- data/Gemfile.lock +123 -0
- data/README.rdoc +104 -30
- data/Rakefile +12 -0
- data/flickrmocks.gemspec +3 -1
- data/lib/flickr_mocks/api/api.rb +80 -27
- data/lib/flickr_mocks/api/flickr.rb +69 -23
- data/lib/flickr_mocks/api/helpers.rb +25 -12
- data/lib/flickr_mocks/api/options.rb +71 -53
- data/lib/flickr_mocks/api/sanitize.rb +129 -20
- data/lib/flickr_mocks/fixtures.rb +7 -1
- data/lib/flickr_mocks/flickraw/custom_clone.rb +3 -1
- data/lib/flickr_mocks/flickraw/custom_compare.rb +4 -0
- data/lib/flickr_mocks/flickraw/custom_marshal.rb +7 -2
- data/lib/flickr_mocks/flickraw/flickraw.rb +6 -0
- data/lib/flickr_mocks/helpers.rb +8 -1
- data/lib/flickr_mocks/models/commons_institution.rb +45 -34
- data/lib/flickr_mocks/models/commons_institutions.rb +85 -75
- data/lib/flickr_mocks/models/helpers.rb +13 -6
- data/lib/flickr_mocks/models/models.rb +7 -0
- data/lib/flickr_mocks/models/photo.rb +76 -75
- data/lib/flickr_mocks/models/photo_details.rb +71 -69
- data/lib/flickr_mocks/models/photo_dimensions.rb +80 -78
- data/lib/flickr_mocks/models/photo_search.rb +115 -88
- data/lib/flickr_mocks/models/photo_size.rb +57 -56
- data/lib/flickr_mocks/models/photo_sizes.rb +68 -67
- data/lib/flickr_mocks/models/photos.rb +104 -99
- data/lib/flickr_mocks/stubs.rb +151 -14
- data/lib/flickr_mocks/version.rb +7 -1
- data/spec/api/api_spec.rb +26 -8
- data/spec/api/flickr_spec.rb +19 -19
- data/spec/api/helper_spec.rb +20 -20
- data/spec/api/options_spec.rb +170 -124
- data/spec/api/sanitize_spec.rb +174 -59
- data/spec/base/stubs_spec.rb +37 -74
- data/spec/base/version_spec.rb +11 -4
- data/spec/models/commons_institution_spec.rb +3 -2
- data/spec/models/commons_institutions_spec.rb +34 -5
- data/spec/models/helpers_spec.rb +7 -6
- data/spec/models/photo_details_spec.rb +12 -11
- data/spec/models/photo_dimensions_spec.rb +5 -4
- data/spec/models/photo_search_spec.rb +50 -8
- data/spec/models/photo_size_spec.rb +4 -3
- data/spec/models/photo_sizes_spec.rb +6 -5
- data/spec/models/photo_spec.rb +6 -4
- data/spec/models/photos_spec.rb +9 -7
- data/spec/shared_examples/hash_options/date_hash_option.rb +42 -0
- data/spec/shared_examples/hash_options/page_hash_option.rb +23 -0
- data/spec/shared_examples/hash_options/perpage_hash_option.rb +43 -0
- data/spec/shared_examples/hash_options/tag_mode_hash_option.rb +31 -0
- data/spec/shared_examples/stub_helpers.rb +140 -0
- data/spec/spec_helper.rb +5 -5
- metadata +55 -16
@@ -1,103 +1,105 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module FlickrMocks
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Models
|
5
|
+
class PhotoDimensions
|
6
|
+
# sizes that are recognized by class. The sizes are in order from smallest to largest
|
7
|
+
@regexp_size = /^[a-z]+(_\d+)?:\d+x\d+(,[a-z]+(_\d+)?:\d+x\d+)*$/
|
7
8
|
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
class << self
|
11
|
+
attr_reader :regexp_size
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def initialize(data)
|
15
|
+
self.delegated_to_object = data
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def available_sizes
|
19
|
+
map do |dimension|
|
20
|
+
dimension.size
|
21
|
+
end
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def dimensions
|
25
|
+
@delegated_to_object
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def collection
|
29
|
+
@collection ||= ::WillPaginate::Collection.create(1, available_sizes.length, available_sizes.length) do |obj|
|
30
|
+
obj.replace(dimensions)
|
31
|
+
end
|
32
|
+
@collection
|
30
33
|
end
|
31
|
-
@collection
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def to_s
|
36
|
+
dimensions.map do |dimension|
|
37
|
+
[dimension.size,[dimension.width,dimension.height].join('x')].join(':')
|
38
|
+
end.join(',')
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def ==(other)
|
42
|
+
return false unless other.class.should == self.class
|
43
|
+
to_s == other.to_s
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
# metaprogramming methods
|
47
|
+
alias :old_respond_to? :respond_to?
|
48
|
+
def respond_to?(method)
|
49
|
+
valid_size?(method) || delegated_instance_methods.include?(method) || old_respond_to?(method)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def method_missing(id,*args,&block)
|
53
|
+
return get_size(id,*args,&block) if valid_size?(id)
|
54
|
+
return dimensions.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
55
|
+
super
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
alias :old_methods :methods
|
59
|
+
def methods
|
60
|
+
available_sizes + delegated_instance_methods + old_methods
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def delegated_instance_methods
|
64
|
+
Models::Helpers.array_accessor_methods
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
# custom cloning methods
|
68
|
+
def initialize_copy(other)
|
69
|
+
super
|
70
|
+
@delegated_to_object = @delegated_to_object.map do |object|
|
71
|
+
object.clone
|
72
|
+
end
|
71
73
|
end
|
72
|
-
end
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
75
|
+
def possible_sizes
|
76
|
+
FlickrMocks::Models::Helpers.possible_sizes
|
77
|
+
end
|
78
|
+
private
|
79
|
+
def delegated_to_object=(data)
|
80
|
+
raise(ArgumentError, "Invalid #{data} must respond to :to_s") unless data.respond_to?(:to_s)
|
81
|
+
# expecting strings of type: "square:1x1,thumbnail:2x2,small:3x3,medium:4x4,medium_640:4x4,large:5x5,original:6x6"
|
82
|
+
raise(ArgumentError, "Invalid string format") unless data =~ PhotoDimensions.regexp_size
|
83
|
+
|
84
|
+
@delegated_to_object= data.to_s.split(',').map do |fields|
|
85
|
+
size,dim = fields.split(':')
|
86
|
+
size= size.to_sym
|
87
|
+
raise(ArgumentError,"Invalid size provided #{size}") unless valid_size?(size)
|
88
|
+
width,height=dim.split(/x/)
|
89
|
+
OpenStruct.new :size => size,:width => width.to_i,:height => height.to_i
|
90
|
+
end
|
89
91
|
end
|
90
|
-
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
def valid_size?(data)
|
94
|
+
possible_sizes.include?(data.to_sym)
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def get_size(size)
|
98
|
+
dimensions.keep_if do |dimension|
|
99
|
+
dimension.size == size
|
100
|
+
end.first
|
101
|
+
end
|
101
102
|
|
103
|
+
end
|
102
104
|
end
|
103
105
|
end
|
@@ -1,115 +1,142 @@
|
|
1
1
|
module FlickrMocks
|
2
|
-
|
3
|
-
|
2
|
+
module Models
|
3
|
+
class PhotoSearch
|
4
|
+
attr_reader :search_terms,:page,:date
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
@defaults = {
|
7
|
+
:page => 1
|
8
|
+
}
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
@delegated_instance_methods = [:current_page, :per_page, :total_entries, :capped_entries,:perpage, :capped?,
|
11
|
+
:max_entries, :collection]
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
class << self
|
14
|
+
attr_accessor :defaults
|
15
|
+
attr_accessor :delegated_instance_methods
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def initialize(data,options={})
|
19
|
+
self.delegated_to_object = data
|
20
|
+
self.search_terms = extract_search_terms(options)
|
21
|
+
self.page = extract_page(options)
|
22
|
+
self.date = extract_date(options)
|
23
|
+
end
|
23
24
|
|
24
|
-
def default(value)
|
25
|
-
PhotoSearch.defaults[value.to_sym]
|
26
|
-
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
total_entries
|
34
|
-
end
|
26
|
+
# returns the string stored in the :search_terms tag. The string is stripped
|
27
|
+
# of spurious spaces and is made to be lower case.
|
28
|
+
def extract_search_terms(params)
|
29
|
+
Api::Sanitize.tags(params[:search_terms])
|
30
|
+
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
def extract_date(params)
|
33
|
+
date = params[:date]
|
34
|
+
case date
|
35
|
+
when NilClass
|
36
|
+
nil
|
37
|
+
when String
|
38
|
+
Api::Helpers.valid_date?(date) ? Api::Helpers.date(date) : raise(ArgumentError)
|
39
|
+
else
|
40
|
+
raise ArgumentError
|
41
|
+
end
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
(photos == other.photos) && [:search_terms,:page,:date].inject(true) do |state,method|
|
45
|
-
state && (self.send(method) == other.send(method))
|
44
|
+
def extract_page(params)
|
45
|
+
Api::Sanitize.page(params[:page])
|
46
46
|
end
|
47
|
-
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
super
|
54
|
-
end
|
48
|
+
# returns the default class instance value corresponding to the supplied key.
|
49
|
+
def default(value)
|
50
|
+
PhotoSearch.defaults[value.to_sym]
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
# returns the list of photo objects returned by search
|
54
|
+
def photos
|
55
|
+
@delegated_to_object
|
56
|
+
end
|
57
|
+
|
58
|
+
def total_results
|
59
|
+
total_entries
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def url_params
|
63
|
+
{ :search_terms => search_terms,
|
64
|
+
:date => (date.nil? && search_terms.empty?) ? Api::Helpers.date : date
|
65
|
+
}.keep_if do |k,v| !(v.nil? || v.to_s.empty?) end
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
def ==(other)
|
69
|
+
return false unless other.class == self.class
|
70
|
+
(photos == other.photos) && [:search_terms,:page,:date].inject(true) do |state,method|
|
71
|
+
state && (self.send(method) == other.send(method))
|
72
|
+
end
|
73
|
+
end
|
69
74
|
|
75
|
+
# metaprogramming methods
|
76
|
+
def method_missing(id,*args,&block)
|
77
|
+
return photos.photos.send(id,*args,&block) if delegated_array_accessor_methods.include?(id)
|
78
|
+
return photos.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
79
|
+
super
|
80
|
+
end
|
70
81
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
82
|
+
alias :old_respond_to? :respond_to?
|
83
|
+
def respond_to?(method)
|
84
|
+
delegated_instance_methods.include?(method) || old_respond_to?(method)
|
85
|
+
end
|
76
86
|
|
77
|
-
|
87
|
+
alias :old_methods :methods
|
88
|
+
def methods
|
89
|
+
delegated_instance_methods + old_methods
|
90
|
+
end
|
78
91
|
|
79
|
-
|
80
|
-
|
81
|
-
when FlickRaw::ResponseList then Photos.new(data)
|
82
|
-
when Photos then data
|
83
|
-
else raise ArgumentError, "expecting object of class Photos or FlickRaw::ResponseList"
|
92
|
+
def delegated_instance_methods
|
93
|
+
PhotoSearch.delegated_instance_methods + delegated_array_accessor_methods
|
84
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
# custom cloning methods
|
98
|
+
def initialize_copy(other)
|
99
|
+
super
|
100
|
+
@delegated_to_object = @delegated_to_object.clone
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def delegated_to_object=(data)
|
106
|
+
@delegated_to_object = case data
|
107
|
+
when FlickRaw::ResponseList then Photos.new(data)
|
108
|
+
when Photos then data
|
109
|
+
else raise ArgumentError, "expecting object of class Photos or FlickRaw::ResponseList"
|
110
|
+
end
|
85
111
|
|
86
|
-
|
112
|
+
end
|
87
113
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
114
|
+
def search_terms=(terms=nil)
|
115
|
+
terms ||= ''
|
116
|
+
raise ArgumentError, "Expecting String but got #{terms.class}" unless terms.is_a?(String)
|
117
|
+
@search_terms = terms
|
118
|
+
end
|
93
119
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
120
|
+
def page=(page=nil)
|
121
|
+
page ||= default(:page)
|
122
|
+
raise ArgumentError, "Expecting Fixnum but got #{page.class}" unless page.is_a?(Fixnum) or page.is_a?(String)
|
123
|
+
@page = page.to_i
|
124
|
+
end
|
99
125
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
126
|
+
def date=(date=nil)
|
127
|
+
raise ArgumentError, "Expecting String but got #{date.class}" unless date.is_a?(String) or date.nil?
|
128
|
+
begin
|
129
|
+
Chronic.parse(date) unless date.nil?
|
130
|
+
rescue
|
131
|
+
raise ArgumentError, "#{date} string can not be converted to Time object"
|
132
|
+
end
|
133
|
+
@date = date
|
134
|
+
end
|
109
135
|
|
110
|
-
|
111
|
-
|
112
|
-
|
136
|
+
def delegated_array_accessor_methods
|
137
|
+
FlickrMocks::Models::Helpers.array_accessor_methods
|
138
|
+
end
|
113
139
|
|
140
|
+
end
|
114
141
|
end
|
115
142
|
end
|
@@ -1,60 +1,61 @@
|
|
1
1
|
module FlickrMocks
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
2
|
+
module Models
|
3
|
+
class PhotoSize
|
4
|
+
def initialize(object)
|
5
|
+
self.delegated_to_object= object
|
6
|
+
end
|
7
|
+
|
8
|
+
def size
|
9
|
+
label.to_s.downcase.sub(/\s+/,'_')
|
10
|
+
end
|
11
|
+
|
12
|
+
def id
|
13
|
+
source.split('/')[-1].split('_')[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
def secret
|
17
|
+
source.split('/')[-1].split('_')[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
@delegated_to_object == other.instance_eval('@delegated_to_object')
|
22
|
+
end
|
23
|
+
|
24
|
+
# metaprogramming methods
|
25
|
+
def delegated_instance_methods
|
26
|
+
@delegated_to_object.methods(false).push(:flickr_type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(id,*args,&block)
|
30
|
+
return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
alias :old_respond_to? :respond_to?
|
35
|
+
def respond_to?(method,type=false)
|
36
|
+
return true if delegated_instance_methods.include?(method)
|
37
|
+
old_respond_to?(method,type)
|
38
|
+
end
|
39
|
+
|
40
|
+
alias :old_methods :methods
|
41
|
+
def methods
|
42
|
+
delegated_instance_methods + old_methods
|
43
|
+
end
|
44
|
+
|
45
|
+
# cloning and copying methods
|
46
|
+
def initialize_copy(orig)
|
47
|
+
super
|
48
|
+
@delegated_to_object = @delegated_to_object.clone
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def delegated_to_object=(data)
|
55
|
+
raise ArgumentError, 'FlickRaw::Response expected' if data.class == FlickRaw::ResponseList
|
56
|
+
raise ArgumentError, 'FlickRaw::Response expected' unless data.is_a? FlickRaw::Response
|
57
|
+
@delegated_to_object = data
|
58
|
+
end
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|